-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,782 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,51 @@ | ||
/**@type {import('eslint').Linter.Config} */ | ||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
rules: { | ||
'semi': [2, "always"], | ||
'@typescript-eslint/no-unused-vars': 0, | ||
'@typescript-eslint/no-explicit-any': 0, | ||
'@typescript-eslint/explicit-module-boundary-types': 0, | ||
'@typescript-eslint/no-non-null-assertion': 0, | ||
'no-trailing-spaces': ["error", { "skipBlankLines": false }] | ||
} | ||
}; | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"prettier", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:import/recommended", | ||
"plugin:import/typescript" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2021, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"ignorePatterns": ["src/parser/grammar.ts"], | ||
"rules": { | ||
"no-case-declarations": "off", | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/no-explicit-any": "warn", | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"max-len": [ | ||
"warn", | ||
{ | ||
"code": 120 | ||
} | ||
], | ||
"object-curly-spacing": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tests/__snapshots__/* | ||
src/parser/grammar.ts | ||
*.ne |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,70 @@ | ||
import * as path from 'path'; | ||
import { window, workspace, ExtensionContext, commands, Range } from 'vscode'; | ||
import { transformer } from '@openfga/syntax-transformer'; | ||
|
||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind | ||
} from 'vscode-languageclient/node'; | ||
|
||
let client: LanguageClient; | ||
|
||
export function activate(context: ExtensionContext) { | ||
|
||
const module = path.join(__dirname, '..', '..', 'server', 'out', 'server.node.js'); | ||
const debugOptions = { execArgv: ['--nolazy', '--inspect=6012'] }; | ||
const serverOptions: ServerOptions = { | ||
run: { module, transport: TransportKind.ipc }, | ||
debug: { module, transport: TransportKind.ipc, options: debugOptions} | ||
}; | ||
|
||
// Options to control the language client | ||
const clientOptions: LanguageClientOptions = { | ||
// Register the server for all document types | ||
documentSelector: [{ language: 'openfga' }], | ||
synchronize: { | ||
// Notify the server about file changes to '.clientrc files contained in the workspace | ||
fileEvents: workspace.createFileSystemWatcher('**/.clientrc') | ||
} | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
'openfgaLanguageServer', | ||
'OpenFGA Language Server', | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
// Start the client. This will also launch the server | ||
client.start(); | ||
|
||
const transformCommand = commands.registerCommand('openfga.commands.transformToJson', async () => { | ||
const activeEditor = window.activeTextEditor; | ||
if (!activeEditor) { | ||
return; | ||
} | ||
const text = activeEditor.document.getText(); | ||
|
||
const modelInApiFormat = transformer.transformDSLToJSON(text); | ||
|
||
const doc = await workspace.openTextDocument({ | ||
content: JSON.stringify(modelInApiFormat, null, " "), | ||
language: "json" | ||
}); | ||
|
||
return (await window.showTextDocument(doc)).document; | ||
}); | ||
|
||
context.subscriptions.push(transformCommand); | ||
} | ||
|
||
export function deactivate(): Thenable<void> | undefined { | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
import * as path from "path"; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { window, workspace, ExtensionContext, commands } from "vscode"; | ||
import { transformer } from "@openfga/syntax-transformer"; | ||
|
||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind | ||
} from "vscode-languageclient/node"; | ||
|
||
let client: LanguageClient; | ||
|
||
export function activate(context: ExtensionContext) { | ||
|
||
const module = path.join(__dirname, "..", "..", "server", "out", "server.node.js"); | ||
const debugOptions = { execArgv: ["--nolazy", "--inspect=6012"] }; | ||
const serverOptions: ServerOptions = { | ||
run: { module, transport: TransportKind.ipc }, | ||
debug: { module, transport: TransportKind.ipc, options: debugOptions } | ||
}; | ||
|
||
// Options to control the language client | ||
const clientOptions: LanguageClientOptions = { | ||
// Register the server for all document types | ||
documentSelector: [{ language: "openfga" }], | ||
synchronize: { | ||
// Notify the server about file changes to '.clientrc files contained in the workspace | ||
fileEvents: workspace.createFileSystemWatcher("**/.clientrc") | ||
} | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
"openfgaLanguageServer", | ||
"OpenFGA Language Server", | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
// Start the client. This will also launch the server | ||
client.start(); | ||
|
||
const transformCommand = commands.registerCommand("openfga.commands.transformToJson", async () => { | ||
const activeEditor = window.activeTextEditor; | ||
if (!activeEditor) { | ||
return; | ||
} | ||
const text = activeEditor.document.getText(); | ||
|
||
const modelInApiFormat = transformer.transformDSLToJSON(text); | ||
|
||
const doc = await workspace.openTextDocument({ | ||
content: JSON.stringify(modelInApiFormat, null, " "), | ||
language: "json" | ||
}); | ||
|
||
return (await window.showTextDocument(doc)).document; | ||
}); | ||
|
||
context.subscriptions.push(transformCommand); | ||
} | ||
|
||
export function deactivate(): Thenable<void> | undefined { | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.