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
2 changes: 1 addition & 1 deletion build-panels.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set -e

WASM_FILE="src/check-watch-panel/public/main.wasm"
WASM_URL="https://github.com/authzed/spicedb/releases/download/v1.49.2/development.wasm"
WASM_URL="https://github.com/authzed/spicedb/releases/download/v1.51.0/development.wasm"

WASM_EXEC_FILE="src/check-watch-panel/public/wasm_exec.js"
WASM_EXEC_URL="https://raw.githubusercontent.com/golang/go/c61e5e72447b568dd25367f592962c7ebf28b1c7/lib/wasm/wasm_exec.js"
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@
"icon": "$(watch-expressions-add)"
}
],
"configuration": {
"title": "SpiceDB",
"properties": {
"spicedb.binaryPath": {
"type": "string",
"default": "/Users/user/Documents/GitHub/spicedb/dist/main",
"description": "Absolute path to a custom SpiceDB binary. If empty, the extension will look for 'spicedb' on your PATH."
}
}
},
"menus": {
"view/title": [
{
Expand Down
15 changes: 13 additions & 2 deletions src/binary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import * as vscode from 'vscode';

import commandExists from 'command-exists';
import * as fs from 'fs';

export async function languageServerBinaryPath(_context: vscode.ExtensionContext): Promise<string | undefined> {
const config = vscode.workspace.getConfiguration('spicedb');
const customPath = config.get<string>('binaryPath');
if (customPath) {
if (fs.existsSync(customPath)) {
vscode.window.showInformationMessage(`Using custom SpiceDB binary found at configured path: ${customPath}`);
return customPath;
}
vscode.window.showInformationMessage(`Custom SpiceDB binary specified but not found: ${customPath}`);
}

try {
return await commandExists('spicedb');
} catch (_e) {
Expand All @@ -13,7 +24,7 @@ export async function languageServerBinaryPath(_context: vscode.ExtensionContext
const INSTALL_COMMANDS = {
darwin: 'brew install spicedb',
linux: '',
win32: '',
win32: 'choco install spicedb',
aix: '',
android: '',
freebsd: '',
Expand All @@ -26,5 +37,5 @@ const INSTALL_COMMANDS = {

export function getInstallCommand() {
const platform = process.platform;
return INSTALL_COMMANDS[platform] || 'https://authzed.com/docs/spicedb/getting-started/installing-spicedb';
return INSTALL_COMMANDS[platform] || 'https://authzed.com/docs/spicedb/getting-started/install/macos';
}
75 changes: 1 addition & 74 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';

import { type ResolvedReference, Resolver, findReferenceNode, parse } from '@authzed/spicedb-parser-js';
import { type ResolvedReference, Resolver, parse } from '@authzed/spicedb-parser-js';

import { getInstallCommand, languageServerBinaryPath } from './binary';
import { CheckWatchProvider } from './checkwatchprovider';
Expand Down Expand Up @@ -43,79 +43,6 @@ export function activate(context: vscode.ExtensionContext) {
}),
);

// TODO: Move this into the language server.
vscode.languages.registerDefinitionProvider('spicedb', {
provideDefinition: function (
document: vscode.TextDocument,
position: vscode.Position,
_token: vscode.CancellationToken,
): vscode.ProviderResult<vscode.Definition> {
const text = document.getText();
const parserResult = parse(text);
if (parserResult.error) {
return;
}

// NOTE: the indexes from VSCode are 0-based, but the parser is 1-based.
const found = findReferenceNode(parserResult.schema!, position.line + 1, position.character + 1);
if (!found) {
return;
}

const resolution = new Resolver(parserResult.schema!);
switch (found.node?.kind) {
case 'typeref': {
const def = resolution.lookupDefinition(found.node.path);
if (def) {
if (found.node.relationName) {
const relation = def.lookupRelationOrPermission(found.node.relationName);
if (relation) {
return {
uri: document.uri,
range: new vscode.Range(
relation.range.startIndex.line - 1,
relation.range.startIndex.column - 1,
relation.range.startIndex.line - 1,
relation.range.startIndex.column - 1,
),
};
}
} else {
return {
uri: document.uri,
range: new vscode.Range(
def.definition.range.startIndex.line - 1,
def.definition.range.startIndex.column - 1,
def.definition.range.startIndex.line - 1,
def.definition.range.startIndex.column - 1,
),
};
}
}
break;
}

case 'relationref': {
const relation = resolution.resolveRelationOrPermission(found.node, found.def);
if (relation) {
return {
uri: document.uri,
range: new vscode.Range(
relation.range.startIndex.line - 1,
relation.range.startIndex.column - 1,
relation.range.startIndex.line - 1,
relation.range.startIndex.column - 1,
),
};
}
break;
}
}

return undefined;
},
});

// TODO: Move this into the language server.
vscode.languages.registerDocumentSemanticTokensProvider(
'spicedb',
Expand Down
26 changes: 26 additions & 0 deletions syntaxes/spicedb.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"patterns": [
{ "include": "#comment" },
{ "include": "#use" },
{ "include": "#import" },
{ "include": "#partial" },
{ "include": "#definition" },
{ "include": "#caveat" },
{ "include": "#relation" },
Expand Down Expand Up @@ -288,6 +290,30 @@
}
}
},
"import": {
"comment": "import",
"match": "\\s*(import)\\s*([\"a-zA-Z_]\\w*)\\s*",
"captures": {
"1": {
"name": "keyword.class.definition"
},
"2": {
"name": "entity.name.function"
}
}
},
"partial": {
"comment": "partial",
"match": "\\s*(partial)\\s*([\"a-zA-Z_]\\w*)\\s*",
"captures": {
"1": {
"name": "keyword.class.definition"
},
"2": {
"name": "entity.name.function"
}
}
},
"with_caveat": {
"comment": "with_caveat",
"match": "\\s*(with)\\s*(([a-z][\\w]{1,62}[a-z0-9]\\/)*[a-z][\\w]{1,62}[a-z0-9])\\s*",
Expand Down
14 changes: 11 additions & 3 deletions syntaxes/test/full-standard.zed
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// this is a standard schema that should have every available feature (wildcards, caveats, etc)
use expiration
use partial
use import

definition user {}
import "imported.zed"

definition group {
relation member: user with non_expired_grant | user with expiration
relation member: user with is_raining | user with expiration
relation member2: user:* with non_expired_grant
...secret
permission supersecret = secretview // defined in the partial
}

definition document {
Expand All @@ -15,7 +19,7 @@ definition document {
relation bbb: user:*
relation ccc: user:*
relation ddd: user:*

...view_secret

// a comment
permission view = aaa
Expand All @@ -34,3 +38,7 @@ definition document {
caveat non_expired_grant(name string, description string) {
name.matches("-$test") || size(description) >= 100
}

partial view_secret {
relation secret: user
}
13 changes: 13 additions & 0 deletions syntaxes/test/imported.zed
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use partial

definition mycustomtype {}

definition user {}

partial secret {
relation secretview: user | mycustomtype
}

caveat is_raining(day string) {
day == "tues" || day == "mon"
}
Loading