Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
"cel"
]
},
{
"id": "spicedb-yaml",
"aliases": [
"SpiceDB YAML"
],
"extensions": [
".zed.yaml"
],
"filenamePatterns": [
"*.zed.yaml"
]
},
{
"id": "spicedb",
"aliases": [
Expand All @@ -52,6 +64,24 @@
"scopeName": "source.cel",
"path": "./syntaxes/cel.tmGrammar.json"
},
{
"language": "spicedb-yaml",
"scopeName": "source.spicedb-yaml",
"path": "./syntaxes/spicedb-yaml.tmGrammar.json",
"embeddedLanguages": {
"meta.embedded.block.spicedb": "spicedb"
}
},
{
"scopeName": "spicedb-yaml.injection",
"path": "./syntaxes/spicedb-yaml-injection.tmGrammar.json",
"injectTo": [
"source.spicedb-yaml"
],
"embeddedLanguages": {
"meta.embedded.block.spicedb": "spicedb"
}
},
{
"language": "spicedb",
"scopeName": "source.spicedb",
Expand Down Expand Up @@ -104,9 +134,16 @@
"when": "view == spicedb.checkWatchView"
}
]
},
"configurationDefaults": {
"files.associations": {
"*.zed.yaml": "spicedb-yaml"
}
}
},
"activationEvents": [],
"activationEvents": [
"onStartupFinished"
],
"main": "./out/extension.js",
"scripts": {
"vscode:build": "vsce package -o spicedb.vsix --no-yarn",
Expand Down
2 changes: 1 addition & 1 deletion src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { promisify } from 'util';

const execFileAsync = promisify(execFile);

export const MIN_SPICEDB_VERSION = '1.51.1';
export const MIN_SPICEDB_VERSION = '1.52.0';

export async function languageServerBinaryPath(_context: vscode.ExtensionContext): Promise<string | undefined> {
const config = vscode.workspace.getConfiguration('spicedb');
Expand Down
17 changes: 15 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import { type ResolvedReference, Resolver, parse } from '@authzed/spicedb-parser
import { checkSpicedbVersion, getInstallCommand, languageServerBinaryPath } from './binary';
import { CheckWatchProvider } from './checkwatchprovider';

function reassignZedYamlLanguage(doc: vscode.TextDocument) {
if (doc.fileName.endsWith('.zed.yaml') && doc.languageId !== 'spicedb-yaml') {
vscode.languages.setTextDocumentLanguage(doc, 'spicedb-yaml');
}
}

export function activate(context: vscode.ExtensionContext) {
console.log('spicedb-vscode is now active');

// Reassign language for any already-open .zed.yaml files detected as plain yaml
vscode.workspace.textDocuments.forEach(reassignZedYamlLanguage);
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(reassignZedYamlLanguage));

const checkWatchProvider = new CheckWatchProvider(context.extensionUri);

context.subscriptions.push(vscode.window.registerWebviewViewProvider(CheckWatchProvider.viewType, checkWatchProvider));
Expand Down Expand Up @@ -199,9 +209,12 @@ async function startLanguageServer(context: vscode.ExtensionContext) {
};

const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'spicedb' }],
documentSelector: [
{ scheme: 'file', language: 'spicedb' },
{ scheme: 'file', language: 'spicedb-yaml' },
],
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/.zed'),
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.zed{,.yaml}'),
},
};

Expand Down
19 changes: 19 additions & 0 deletions syntaxes/spicedb-yaml-injection.tmGrammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"scopeName": "spicedb-yaml.injection",
"injectionSelector": "L:source.spicedb-yaml",
"patterns": [{ "include": "#schema-block" }],
"repository": {
"schema-block": {
"begin": "(['\"]?schema['\"]?)(:\\s*)([|>][-+0-9]*)\\s*$",
"beginCaptures": {
"1": { "name": "entity.name.tag.yaml" },
"2": { "name": "punctuation.separator.key-value.mapping.yaml" },
"3": { "name": "keyword.control.flow.block-scalar.literal.yaml" }
},
"while": "^(\\s|$)",
"contentName": "meta.embedded.block.spicedb",
"patterns": [{ "include": "source.spicedb" }]
}
}
}
6 changes: 6 additions & 0 deletions syntaxes/spicedb-yaml.tmGrammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "SpiceDB YAML",
"scopeName": "source.spicedb-yaml",
"patterns": [{ "include": "source.yaml" }]
}
14 changes: 14 additions & 0 deletions syntaxes/test/full-standard.zed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
schema: |-
definition user {}
definition doc {
relation vieww: user
relation blah: user
}

assertions:
assertTrue:
- 'doc:1#admin@user:maria'

relationships: |-
doc:1#vieww@user:maria
2 changes: 2 additions & 0 deletions syntaxes/test/withSchemaFile.zed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
schemaFile: 'imported.zed'
Loading