|
1 | | -// The module 'vscode' contains the VS Code extensibility API |
2 | | -// Import the module and reference it with the alias vscode in your code below |
3 | 1 | import * as vscode from "vscode"; |
4 | | -// import { workspace } from "vscode"; |
5 | 2 |
|
6 | 3 | import { |
7 | 4 | Executable, |
8 | 5 | LanguageClient, |
9 | 6 | LanguageClientOptions, |
10 | 7 | } from "vscode-languageclient/node"; |
11 | 8 |
|
12 | | -let client: LanguageClient; |
13 | | - |
14 | | -// This method is called when your extension is activated |
15 | | -// Your extension is activated the very first time the command is executed |
16 | | -export function activate(_context: vscode.ExtensionContext) { |
17 | | - // Options to control the language client |
18 | | - // |
19 | | - const serverOptions: Executable = { |
20 | | - command: "mix", |
21 | | - args: ["credo.lsp", "--stdio"], |
22 | | - }; |
23 | | - const clientOptions: LanguageClientOptions = { |
24 | | - // Register the server for plain text documents |
25 | | - documentSelector: [{ scheme: "file", language: "elixir" }], |
26 | | - }; |
27 | | - |
28 | | - // Create the language client and start the client. |
29 | | - client = new LanguageClient( |
30 | | - "elixir-tools.credo", |
31 | | - "Credo", |
32 | | - serverOptions, |
33 | | - clientOptions |
34 | | - ); |
35 | | - |
36 | | - // Start the client. This will also launch the server |
37 | | - client.start(); |
| 9 | +let credoClient: LanguageClient; |
| 10 | + |
| 11 | +export async function activate(_context: vscode.ExtensionContext) { |
| 12 | + let files = await vscode.workspace.findFiles("mix.exs"); |
| 13 | + |
| 14 | + let config = vscode.workspace.getConfiguration("elixir-tools.credo"); |
| 15 | + |
| 16 | + if (files[0]) { |
| 17 | + let text = await vscode.workspace.fs.readFile(files[0]); |
| 18 | + |
| 19 | + if (text.toString().includes("{:credo")) { |
| 20 | + if (config.get("enabled")) { |
| 21 | + const serverOptions: Executable = { |
| 22 | + command: "mix", |
| 23 | + args: ["credo.lsp", "--stdio"], |
| 24 | + }; |
| 25 | + const clientOptions: LanguageClientOptions = { |
| 26 | + documentSelector: [{ scheme: "file", language: "elixir" }], |
| 27 | + }; |
| 28 | + |
| 29 | + credoClient = new LanguageClient( |
| 30 | + "elixir-tools.credo", |
| 31 | + "Credo", |
| 32 | + serverOptions, |
| 33 | + clientOptions |
| 34 | + ); |
| 35 | + |
| 36 | + // Start the credoClient. This will also launch the server |
| 37 | + credoClient.start(); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
38 | 41 | } |
39 | 42 |
|
40 | | -// This method is called when your extension is deactivated |
41 | 43 | export function deactivate() { |
42 | | - if (!client) { |
| 44 | + if (!credoClient) { |
43 | 45 | return undefined; |
44 | 46 | } |
45 | | - return client.stop(); |
| 47 | + return credoClient.stop(); |
46 | 48 | } |
0 commit comments