| 10 | let client: LanguageClient; |
| 11 | |
| 12 | export async function activate(context: vscode.ExtensionContext) { |
| 13 | const serverModule = context.asAbsolutePath("server.js"); |
| 14 | const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] }; |
| 15 | |
| 16 | const serverOptions: ServerOptions = { |
| 17 | run: { module: serverModule, transport: TransportKind.ipc }, |
| 18 | debug: { |
| 19 | module: serverModule, |
| 20 | transport: TransportKind.ipc, |
| 21 | options: debugOptions |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | const clientOptions: LanguageClientOptions = { |
| 26 | // register server for sqlx files |
| 27 | documentSelector: [{ scheme: "file", language: "sqlx" }], |
| 28 | synchronize: { |
| 29 | fileEvents: workspace.createFileSystemWatcher("**/.clientrc") |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | client = new LanguageClient( |
| 34 | "dataformLanguageServer", |
| 35 | "Dataform Language Server", |
| 36 | serverOptions, |
| 37 | clientOptions |
| 38 | ); |
| 39 | |
| 40 | const compile = vscode.commands.registerCommand("dataform.compile", () => { |
| 41 | const _ = client.sendRequest("compile"); |
| 42 | }); |
| 43 | |
| 44 | context.subscriptions.push(compile); |
| 45 | |
| 46 | client.start(); |
| 47 | |
| 48 | // wait for client to be ready before setting up notification handlers |
| 49 | await client.onReady(); |
| 50 | client.onNotification("error", (errorMessage: string) => { |
| 51 | vscode.window.showErrorMessage(errorMessage); |
| 52 | }); |
| 53 | client.onNotification("info", (message: string) => { |
| 54 | vscode.window.showInformationMessage(message); |
| 55 | }); |
| 56 | client.onNotification("success", (message: string) => { |
| 57 | vscode.window.showInformationMessage(message); |
| 58 | }); |
| 59 | |
| 60 | // Recommend YAML extension if not installed |
| 61 | // We also can add the extension to "extensionDependencies" in package.json, |
| 62 | // but this way we can avoid forcing users to install the extension. |
| 63 | // You can control this recommendation behavior through the setting. |
| 64 | if (workspace.getConfiguration("dataform").get("recommendYamlExtension")) { |
| 65 | const yamlExtension = vscode.extensions.getExtension("redhat.vscode-yaml"); |
| 66 | if (!yamlExtension) { |
| 67 | await vscode.window |
| 68 | .showInformationMessage( |
| 69 | "The Dataform extension recommends installing the YAML extension for workflow_settings.yaml support.", |