Skip to content

Commit 47c36e7

Browse files
committed
feat: add yaml support
1 parent 9295f11 commit 47c36e7

6 files changed

Lines changed: 94 additions & 3 deletions

File tree

package.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
"cel"
2929
]
3030
},
31+
{
32+
"id": "spicedb-yaml",
33+
"aliases": [
34+
"SpiceDB YAML"
35+
],
36+
"extensions": [
37+
".zed.yaml"
38+
],
39+
"filenamePatterns": [
40+
"*.zed.yaml"
41+
]
42+
},
3143
{
3244
"id": "spicedb",
3345
"aliases": [
@@ -52,6 +64,24 @@
5264
"scopeName": "source.cel",
5365
"path": "./syntaxes/cel.tmGrammar.json"
5466
},
67+
{
68+
"language": "spicedb-yaml",
69+
"scopeName": "source.spicedb-yaml",
70+
"path": "./syntaxes/spicedb-yaml.tmGrammar.json",
71+
"embeddedLanguages": {
72+
"meta.embedded.block.spicedb": "spicedb"
73+
}
74+
},
75+
{
76+
"scopeName": "spicedb-yaml.injection",
77+
"path": "./syntaxes/spicedb-yaml-injection.tmGrammar.json",
78+
"injectTo": [
79+
"source.spicedb-yaml"
80+
],
81+
"embeddedLanguages": {
82+
"meta.embedded.block.spicedb": "spicedb"
83+
}
84+
},
5585
{
5686
"language": "spicedb",
5787
"scopeName": "source.spicedb",
@@ -104,9 +134,16 @@
104134
"when": "view == spicedb.checkWatchView"
105135
}
106136
]
137+
},
138+
"configurationDefaults": {
139+
"files.associations": {
140+
"*.zed.yaml": "spicedb-yaml"
141+
}
107142
}
108143
},
109-
"activationEvents": [],
144+
"activationEvents": [
145+
"onStartupFinished"
146+
],
110147
"main": "./out/extension.js",
111148
"scripts": {
112149
"vscode:build": "vsce package -o spicedb.vsix --no-yarn",

src/extension.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ import { type ResolvedReference, Resolver, parse } from '@authzed/spicedb-parser
66
import { getInstallCommand, languageServerBinaryPath } from './binary';
77
import { CheckWatchProvider } from './checkwatchprovider';
88

9+
function reassignZedYamlLanguage(doc: vscode.TextDocument) {
10+
if (doc.fileName.endsWith('.zed.yaml') && doc.languageId !== 'spicedb-yaml') {
11+
vscode.languages.setTextDocumentLanguage(doc, 'spicedb-yaml');
12+
}
13+
}
14+
915
export function activate(context: vscode.ExtensionContext) {
1016
console.log('spicedb-vscode is now active');
1117

18+
// Reassign language for any already-open .zed.yaml files detected as plain yaml
19+
vscode.workspace.textDocuments.forEach(reassignZedYamlLanguage);
20+
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(reassignZedYamlLanguage));
21+
1222
const checkWatchProvider = new CheckWatchProvider(context.extensionUri);
1323

1424
context.subscriptions.push(vscode.window.registerWebviewViewProvider(CheckWatchProvider.viewType, checkWatchProvider));
@@ -197,9 +207,12 @@ async function startLanguageServer(context: vscode.ExtensionContext) {
197207
};
198208

199209
const clientOptions: LanguageClientOptions = {
200-
documentSelector: [{ scheme: 'file', language: 'spicedb' }],
210+
documentSelector: [
211+
{ scheme: 'file', language: 'spicedb' },
212+
{ scheme: 'file', language: 'spicedb-yaml' },
213+
],
201214
synchronize: {
202-
fileEvents: vscode.workspace.createFileSystemWatcher('**/.zed'),
215+
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.zed{,.yaml}'),
203216
},
204217
};
205218

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"scopeName": "spicedb-yaml.injection",
4+
"injectionSelector": "L:source.spicedb-yaml",
5+
"patterns": [{ "include": "#schema-block" }],
6+
"repository": {
7+
"schema-block": {
8+
"begin": "(['\"]?schema['\"]?)(:\\s*)([|>][-+0-9]*)\\s*$",
9+
"beginCaptures": {
10+
"1": { "name": "entity.name.tag.yaml" },
11+
"2": { "name": "punctuation.separator.key-value.mapping.yaml" },
12+
"3": { "name": "keyword.control.flow.block-scalar.literal.yaml" }
13+
},
14+
"while": "^(\\s|$)",
15+
"contentName": "meta.embedded.block.spicedb",
16+
"patterns": [{ "include": "source.spicedb" }]
17+
}
18+
}
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "SpiceDB YAML",
4+
"scopeName": "source.spicedb-yaml",
5+
"patterns": [{ "include": "source.yaml" }]
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
schema: |-
3+
definition user {}
4+
definition doc {
5+
relation vieww: user
6+
relation blah: user
7+
}
8+
9+
assertions:
10+
assertTrue:
11+
- 'doc:1#admin@user:maria'
12+
13+
relationships: |-
14+
doc:1#vieww@user:maria
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
schemaFile: 'imported.zed'

0 commit comments

Comments
 (0)