-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.ts
63 lines (54 loc) · 1.75 KB
/
client.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
import * as vscode from 'vscode'
import * as lsp from 'vscode-languageclient/node'
import { LanguageConfig, alloglot } from './config'
import { IHierarchicalOutputChannel } from './utils'
/**
* A full-featured generic LSP client.
* The client launches its own server in a child process and cleans up after itself.
*/
export function makeClient(output: IHierarchicalOutputChannel, config: LanguageConfig): vscode.Disposable {
const { languageId, serverCommand, serverArgs } = config
if (!languageId || !serverCommand) return vscode.Disposable.from()
const serverExecutable = {
command: serverCommand,
options: {
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
env: process.env
},
args: serverArgs || [],
transport: lsp.TransportKind.stdio
}
const serverOptions = {
run: serverExecutable,
debug: serverExecutable
}
const clientChannel = output.split()
const clientOptions = {
documentSelector: [{ scheme: 'file', language: languageId }],
synchronize: { configurationSection: alloglot.root },
revealOutputChannelOn: lsp.RevealOutputChannelOn.Never,
outputChannel: clientChannel,
outputChannelName: clientChannel.name,
workspaceFolder: vscode.workspace.workspaceFolders?.[0]
}
let client = new lsp.LanguageClient(
clientChannel.name,
clientChannel.name,
serverOptions,
clientOptions,
false
)
output.appendLine(alloglot.ui.startingLanguageClient)
client.start()
output.appendLine(alloglot.ui.languageClientStarted)
return vscode.Disposable.from(
clientChannel,
{
dispose: () => {
output.appendLine(alloglot.ui.stoppingLanguageClient)
client.stop()
output.appendLine(alloglot.ui.languageClientStopped)
}
}
)
}