-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.ts
52 lines (45 loc) · 1.33 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
import { workspace, window, ExtensionContext } from 'vscode';
import * as child_process from 'child_process';
import {
LanguageClient,
LanguageClientOptions,
} from 'vscode-languageclient';
let client: LanguageClient;
export function activate(context: ExtensionContext) {
// Options to control the language client
let clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'yaml' }],
outputChannelName: 'xpls',
};
// Create the language client and start the client.
client = new LanguageClient(
'xpls',
'Crossplane Language Server',
spawnServer,
clientOptions
);
// Start the client. This will also launch the server
client.start();
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}
async function spawnServer(): Promise<child_process.ChildProcess> {
let settings = getSettings()
let serverProcess = child_process.spawn(settings.upPath, ['xpls', 'serve', '--verbose'])
serverProcess.on('error', (err: { code?: string; message: string }) => {
window.showWarningMessage(
`Failed to spawn xpls: \`${err.message}\``
)
})
return serverProcess
}
function getSettings(): {upPath: any} {
const configUpPath = workspace.getConfiguration().get('xpls.up.path');
return {
upPath: configUpPath ? configUpPath : "up"
}
}