/
LanguageServices.ts
103 lines (88 loc) · 3.19 KB
/
LanguageServices.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
93
94
95
96
97
98
99
100
101
102
103
/*!
* Copyright 2018-2019 VMware, Inc.
* SPDX-License-Identifier: MIT
*/
import * as path from "path"
import { AutoWire, Logger } from "vrealize-common"
import * as vscode from "vscode"
import * as client from "vscode-languageclient"
import { OutputChannels } from "../constants"
import { ClientWindow } from "../ui"
import { Registrable } from "../Registrable"
class ErrorHandler {
closed(): client.CloseAction {
return client.CloseAction.DoNotRestart
}
error(): client.ErrorAction {
return client.ErrorAction.Shutdown
}
}
@AutoWire
export class LanguageServices implements Registrable, vscode.Disposable {
private logger = Logger.get("LanguageServices")
private languageClient: client.LanguageClient | undefined
private outputChannel: vscode.OutputChannel
private extensionContext: vscode.ExtensionContext
constructor() {
// empty
}
get client(): client.LanguageClient | undefined {
return this.languageClient
}
dispose() {
if (this.languageClient) {
return this.languageClient.stop()
}
return Promise.resolve()
}
register(context: vscode.ExtensionContext, clientWindow: ClientWindow): void {
this.extensionContext = context
}
initialize(): Promise<void> {
this.outputChannel = vscode.window.createOutputChannel(OutputChannels.LanguageServerLogs)
this.languageClient = this.newLanguageClient()
this.languageClient.start()
return this.languageClient.onReady()
}
private newLanguageClient(): client.LanguageClient {
const config = vscode.workspace.getConfiguration("vrdev")
const module = this.extensionContext.asAbsolutePath(path.join("language-server"))
const executable = path.join(module, "out", "server", "langserver.js")
this.logger.info(`Starting vRO language server on port 6014`)
const serverOptions = {
run: {
module: executable,
transport: client.TransportKind.ipc,
args: ["--node-ipc"],
options: { cwd: module }
},
debug: {
module: executable,
transport: client.TransportKind.ipc,
args: ["--node-ipc"],
options: { cwd: module, execArgv: ["--nolazy", "--inspect=6014"] }
}
}
const clientOptions: client.LanguageClientOptions = {
documentSelector: [
{
language: "javascript",
scheme: "file"
}
],
errorHandler: new ErrorHandler(),
initializationOptions: config,
outputChannel: this.outputChannel,
revealOutputChannelOn: client.RevealOutputChannelOn.Never,
stdioEncoding: "utf8",
synchronize: {
configurationSection: "vrdev",
fileEvents: [
vscode.workspace.createFileSystemWatcher("**/src/**/*.js"),
vscode.workspace.createFileSystemWatcher("**/pom.xml")
]
}
}
return new client.LanguageClient("vRO LS", serverOptions, clientOptions)
}
}