-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.ts
92 lines (83 loc) · 2.59 KB
/
extension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { ExtensionContext, window, workspace } from 'vscode';
import {
Executable,
LanguageClient,
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node';
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
let client: LanguageClient;
const getFromPath = (bin: string, def: string) => {
const paths = process.env.PATH?.split(path.delimiter) || [];
const binPaths = paths.map((x) => path.join(x, bin));
const found = binPaths.find((x) => {
return fs.existsSync(x);
});
return found || def;
};
const SOLIDITY_ANALYZER_SERVER_BIN_NAME = 'solidity-analyzer-ls';
export async function activate(context: ExtensionContext) {
// let disposable = commands.registerCommand("extension.helloworld", async uri => {
// vscode.window.showInformationMessage('Hello World!');
// });
//
// context.subscriptions.push(disposable);
const traceOutputChannel = window.createOutputChannel(
'Solidity Analyzer Language Server Trace'
);
traceOutputChannel.appendLine('Solidity Analyzer Language Server Trace');
const serverPathEnv = process.env.SOLIDITY_ANALYZER_SERVER_PATH;
const serverPathConfig = workspace
.getConfiguration('solidity-analyzer')
.get<string>('languageServerPath');
const defaultPath = getFromPath(
SOLIDITY_ANALYZER_SERVER_BIN_NAME,
path.join(os.homedir(), 'bin', SOLIDITY_ANALYZER_SERVER_BIN_NAME)
);
const serverPath = serverPathConfig || serverPathEnv || defaultPath;
if (!fs.existsSync(serverPath)) {
window.showErrorMessage(
`Solidity Analyzer Language Server not found at ${serverPath}`
);
process.exit(1);
return;
}
const run: Executable = {
command: serverPath,
options: {
env: {
...process.env,
RUST_LOG: 'debug',
},
},
};
const serverOptions: ServerOptions = {
run,
debug: run,
};
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'solidity' }],
outputChannel: traceOutputChannel,
traceOutputChannel,
};
// Create the language client and start the clien5t.
client = new LanguageClient(
'solidity-analyzer',
'Solidity language support for Visual Studio Code',
serverOptions,
clientOptions
);
client.start();
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}