@rescript/language-server 1.42.0 → 1.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analysis_binaries/darwin/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/darwinarm64/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/linux/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/win32/rescript-editor-analysis.exe +0 -0
- package/out/cli.js +93 -32
- package/out/cli.js.map +7 -1
- package/package.json +1 -1
- package/out/buildSchema.js +0 -21
- package/out/buildSchema.js.map +0 -1
- package/out/codeActions.js +0 -573
- package/out/codeActions.js.map +0 -1
- package/out/constants.js +0 -58
- package/out/constants.js.map +0 -1
- package/out/errorReporter.js +0 -22
- package/out/errorReporter.js.map +0 -1
- package/out/lookup.js +0 -147
- package/out/lookup.js.map +0 -1
- package/out/server.js +0 -1108
- package/out/server.js.map +0 -1
- package/out/utils.js +0 -582
- package/out/utils.js.map +0 -1
package/out/server.js
DELETED
|
@@ -1,1108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const process_1 = __importDefault(require("process"));
|
|
30
|
-
const p = __importStar(require("vscode-languageserver-protocol"));
|
|
31
|
-
const v = __importStar(require("vscode-languageserver"));
|
|
32
|
-
const rpc = __importStar(require("vscode-jsonrpc/node"));
|
|
33
|
-
const path = __importStar(require("path"));
|
|
34
|
-
const fs_1 = __importDefault(require("fs"));
|
|
35
|
-
// TODO: check DidChangeWatchedFilesNotification.
|
|
36
|
-
const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol");
|
|
37
|
-
const lookup = __importStar(require("./lookup"));
|
|
38
|
-
const utils = __importStar(require("./utils"));
|
|
39
|
-
const c = __importStar(require("./constants"));
|
|
40
|
-
const chokidar = __importStar(require("chokidar"));
|
|
41
|
-
const console_1 = require("console");
|
|
42
|
-
const url_1 = require("url");
|
|
43
|
-
const errorReporter_1 = require("./errorReporter");
|
|
44
|
-
let extensionClientCapabilities = {};
|
|
45
|
-
// All values here are temporary, and will be overridden as the server is
|
|
46
|
-
// initialized, and the current config is received from the client.
|
|
47
|
-
let extensionConfiguration = {
|
|
48
|
-
allowBuiltInFormatter: false,
|
|
49
|
-
askToStartBuild: true,
|
|
50
|
-
inlayHints: {
|
|
51
|
-
enable: false,
|
|
52
|
-
maxLength: 25,
|
|
53
|
-
},
|
|
54
|
-
codeLens: false,
|
|
55
|
-
binaryPath: null,
|
|
56
|
-
platformPath: null,
|
|
57
|
-
signatureHelp: {
|
|
58
|
-
enabled: true,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
// Below here is some state that's not important exactly how long it lives.
|
|
62
|
-
let hasPromptedAboutBuiltInFormatter = false;
|
|
63
|
-
let pullConfigurationPeriodically = null;
|
|
64
|
-
// https://microsoft.github.io/language-server-protocol/specification#initialize
|
|
65
|
-
// According to the spec, there could be requests before the 'initialize' request. Link in comment tells how to handle them.
|
|
66
|
-
let initialized = false;
|
|
67
|
-
let serverSentRequestIdCounter = 0;
|
|
68
|
-
// https://microsoft.github.io/language-server-protocol/specification#exit
|
|
69
|
-
let shutdownRequestAlreadyReceived = false;
|
|
70
|
-
let stupidFileContentCache = new Map();
|
|
71
|
-
let projectsFiles = new Map();
|
|
72
|
-
// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
|
|
73
|
-
// This keeps track of code actions extracted from diagnostics.
|
|
74
|
-
let codeActionsFromDiagnostics = {};
|
|
75
|
-
// will be properly defined later depending on the mode (stdio/node-rpc)
|
|
76
|
-
let send = (_) => { };
|
|
77
|
-
let findRescriptBinary = (projectRootPath) => extensionConfiguration.binaryPath == null
|
|
78
|
-
? lookup.findFilePathFromProjectRoot(projectRootPath, path.join(c.nodeModulesBinDir, c.rescriptBinName))
|
|
79
|
-
: utils.findBinary(extensionConfiguration.binaryPath, c.rescriptBinName);
|
|
80
|
-
let findPlatformPath = (projectRootPath) => {
|
|
81
|
-
if (extensionConfiguration.platformPath != null) {
|
|
82
|
-
return extensionConfiguration.platformPath;
|
|
83
|
-
}
|
|
84
|
-
let rescriptDir = lookup.findFilePathFromProjectRoot(projectRootPath, path.join("node_modules", "rescript"));
|
|
85
|
-
if (rescriptDir == null) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
let platformPath = path.join(rescriptDir, c.platformDir);
|
|
89
|
-
// Workaround for darwinarm64 which has no folder yet in ReScript <= 9.1.4
|
|
90
|
-
if (process_1.default.platform == "darwin" &&
|
|
91
|
-
process_1.default.arch == "arm64" &&
|
|
92
|
-
!fs_1.default.existsSync(platformPath)) {
|
|
93
|
-
platformPath = path.join(rescriptDir, process_1.default.platform);
|
|
94
|
-
}
|
|
95
|
-
return platformPath;
|
|
96
|
-
};
|
|
97
|
-
let findBscExeBinary = (projectRootPath) => utils.findBinary(findPlatformPath(projectRootPath), c.bscExeName);
|
|
98
|
-
let createInterfaceRequest = new v.RequestType("textDocument/createInterface");
|
|
99
|
-
let openCompiledFileRequest = new v.RequestType("textDocument/openCompiled");
|
|
100
|
-
let getCurrentCompilerDiagnosticsForFile = (fileUri) => {
|
|
101
|
-
let diagnostics = null;
|
|
102
|
-
projectsFiles.forEach((projectFile, _projectRootPath) => {
|
|
103
|
-
if (diagnostics == null && projectFile.filesDiagnostics[fileUri] != null) {
|
|
104
|
-
diagnostics = projectFile.filesDiagnostics[fileUri].slice();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
return diagnostics !== null && diagnostics !== void 0 ? diagnostics : [];
|
|
108
|
-
};
|
|
109
|
-
let sendUpdatedDiagnostics = () => {
|
|
110
|
-
projectsFiles.forEach((projectFile, projectRootPath) => {
|
|
111
|
-
let { filesWithDiagnostics } = projectFile;
|
|
112
|
-
let compilerLogPath = path.join(projectRootPath, c.compilerLogPartialPath);
|
|
113
|
-
let content = fs_1.default.readFileSync(compilerLogPath, { encoding: "utf-8" });
|
|
114
|
-
let { done, result: filesAndErrors, codeActions, linesWithParseErrors, } = utils.parseCompilerLogOutput(content);
|
|
115
|
-
if (linesWithParseErrors.length > 0) {
|
|
116
|
-
let params = {
|
|
117
|
-
type: p.MessageType.Warning,
|
|
118
|
-
message: `There are more compiler warning/errors that we could not parse. You can help us fix this by opening an [issue on the repository](https://github.com/rescript-lang/rescript-vscode/issues/new?title=Compiler%20log%20parse%20error), pasting the contents of the file [lib/bs/.compiler.log](file://${compilerLogPath}).`,
|
|
119
|
-
};
|
|
120
|
-
let message = {
|
|
121
|
-
jsonrpc: c.jsonrpcVersion,
|
|
122
|
-
method: "window/showMessage",
|
|
123
|
-
params: params,
|
|
124
|
-
};
|
|
125
|
-
send(message);
|
|
126
|
-
}
|
|
127
|
-
projectFile.filesDiagnostics = filesAndErrors;
|
|
128
|
-
codeActionsFromDiagnostics = codeActions;
|
|
129
|
-
// diff
|
|
130
|
-
Object.keys(filesAndErrors).forEach((file) => {
|
|
131
|
-
let params = {
|
|
132
|
-
uri: file,
|
|
133
|
-
diagnostics: filesAndErrors[file],
|
|
134
|
-
};
|
|
135
|
-
let notification = {
|
|
136
|
-
jsonrpc: c.jsonrpcVersion,
|
|
137
|
-
method: "textDocument/publishDiagnostics",
|
|
138
|
-
params: params,
|
|
139
|
-
};
|
|
140
|
-
send(notification);
|
|
141
|
-
filesWithDiagnostics.add(file);
|
|
142
|
-
});
|
|
143
|
-
if (done) {
|
|
144
|
-
// clear old files
|
|
145
|
-
filesWithDiagnostics.forEach((file) => {
|
|
146
|
-
if (filesAndErrors[file] == null) {
|
|
147
|
-
// Doesn't exist in the new diagnostics. Clear this diagnostic
|
|
148
|
-
let params = {
|
|
149
|
-
uri: file,
|
|
150
|
-
diagnostics: [],
|
|
151
|
-
};
|
|
152
|
-
let notification = {
|
|
153
|
-
jsonrpc: c.jsonrpcVersion,
|
|
154
|
-
method: "textDocument/publishDiagnostics",
|
|
155
|
-
params: params,
|
|
156
|
-
};
|
|
157
|
-
send(notification);
|
|
158
|
-
filesWithDiagnostics.delete(file);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
let deleteProjectDiagnostics = (projectRootPath) => {
|
|
165
|
-
let root = projectsFiles.get(projectRootPath);
|
|
166
|
-
if (root != null) {
|
|
167
|
-
root.filesWithDiagnostics.forEach((file) => {
|
|
168
|
-
let params = {
|
|
169
|
-
uri: file,
|
|
170
|
-
diagnostics: [],
|
|
171
|
-
};
|
|
172
|
-
let notification = {
|
|
173
|
-
jsonrpc: c.jsonrpcVersion,
|
|
174
|
-
method: "textDocument/publishDiagnostics",
|
|
175
|
-
params: params,
|
|
176
|
-
};
|
|
177
|
-
send(notification);
|
|
178
|
-
});
|
|
179
|
-
projectsFiles.delete(projectRootPath);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
let sendCompilationFinishedMessage = () => {
|
|
183
|
-
let notification = {
|
|
184
|
-
jsonrpc: c.jsonrpcVersion,
|
|
185
|
-
method: "rescript/compilationFinished",
|
|
186
|
-
};
|
|
187
|
-
send(notification);
|
|
188
|
-
};
|
|
189
|
-
let compilerLogsWatcher = chokidar
|
|
190
|
-
.watch([], {
|
|
191
|
-
awaitWriteFinish: {
|
|
192
|
-
stabilityThreshold: 1,
|
|
193
|
-
},
|
|
194
|
-
})
|
|
195
|
-
.on("all", (_e, changedPath) => {
|
|
196
|
-
var _a;
|
|
197
|
-
sendUpdatedDiagnostics();
|
|
198
|
-
sendCompilationFinishedMessage();
|
|
199
|
-
if (((_a = extensionConfiguration.inlayHints) === null || _a === void 0 ? void 0 : _a.enable) === true) {
|
|
200
|
-
sendInlayHintsRefresh();
|
|
201
|
-
}
|
|
202
|
-
if (extensionConfiguration.codeLens === true) {
|
|
203
|
-
sendCodeLensRefresh();
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
let stopWatchingCompilerLog = () => {
|
|
207
|
-
// TODO: cleanup of compilerLogs?
|
|
208
|
-
compilerLogsWatcher.close();
|
|
209
|
-
};
|
|
210
|
-
let openedFile = (fileUri, fileContent) => {
|
|
211
|
-
let filePath = (0, url_1.fileURLToPath)(fileUri);
|
|
212
|
-
stupidFileContentCache.set(filePath, fileContent);
|
|
213
|
-
let projectRootPath = utils.findProjectRootOfFile(filePath);
|
|
214
|
-
if (projectRootPath != null) {
|
|
215
|
-
let projectRootState = projectsFiles.get(projectRootPath);
|
|
216
|
-
if (projectRootState == null) {
|
|
217
|
-
projectRootState = {
|
|
218
|
-
openFiles: new Set(),
|
|
219
|
-
filesWithDiagnostics: new Set(),
|
|
220
|
-
filesDiagnostics: {},
|
|
221
|
-
bsbWatcherByEditor: null,
|
|
222
|
-
hasPromptedToStartBuild: /(\/|\\)node_modules(\/|\\)/.test(projectRootPath)
|
|
223
|
-
? "never"
|
|
224
|
-
: false,
|
|
225
|
-
};
|
|
226
|
-
projectsFiles.set(projectRootPath, projectRootState);
|
|
227
|
-
compilerLogsWatcher.add(path.join(projectRootPath, c.compilerLogPartialPath));
|
|
228
|
-
}
|
|
229
|
-
let root = projectsFiles.get(projectRootPath);
|
|
230
|
-
root.openFiles.add(filePath);
|
|
231
|
-
// check if .bsb.lock is still there. If not, start a bsb -w ourselves
|
|
232
|
-
// because otherwise the diagnostics info we'll display might be stale
|
|
233
|
-
let bsbLockPath = path.join(projectRootPath, c.bsbLock);
|
|
234
|
-
if (projectRootState.hasPromptedToStartBuild === false &&
|
|
235
|
-
extensionConfiguration.askToStartBuild === true &&
|
|
236
|
-
!fs_1.default.existsSync(bsbLockPath)) {
|
|
237
|
-
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
|
|
238
|
-
// stale. Use that logic
|
|
239
|
-
// TODO: close watcher when lang-server shuts down
|
|
240
|
-
if (findRescriptBinary(projectRootPath) != null) {
|
|
241
|
-
let payload = {
|
|
242
|
-
title: c.startBuildAction,
|
|
243
|
-
projectRootPath: projectRootPath,
|
|
244
|
-
};
|
|
245
|
-
let params = {
|
|
246
|
-
type: p.MessageType.Info,
|
|
247
|
-
message: `Start a build for this project to get the freshest data?`,
|
|
248
|
-
actions: [payload],
|
|
249
|
-
};
|
|
250
|
-
let request = {
|
|
251
|
-
jsonrpc: c.jsonrpcVersion,
|
|
252
|
-
id: serverSentRequestIdCounter++,
|
|
253
|
-
method: "window/showMessageRequest",
|
|
254
|
-
params: params,
|
|
255
|
-
};
|
|
256
|
-
send(request);
|
|
257
|
-
projectRootState.hasPromptedToStartBuild = true;
|
|
258
|
-
// the client might send us back the "start build" action, which we'll
|
|
259
|
-
// handle in the isResponseMessage check in the message handling way
|
|
260
|
-
// below
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
let request = {
|
|
264
|
-
jsonrpc: c.jsonrpcVersion,
|
|
265
|
-
method: "window/showMessage",
|
|
266
|
-
params: {
|
|
267
|
-
type: p.MessageType.Error,
|
|
268
|
-
message: extensionConfiguration.binaryPath == null
|
|
269
|
-
? `Can't find ReScript binary in ${path.join(projectRootPath, c.nodeModulesBinDir)} or parent directories. Did you install it? It's required to use "rescript" > 9.1`
|
|
270
|
-
: `Can't find ReScript binary in the directory ${extensionConfiguration.binaryPath}`,
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
send(request);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
// no need to call sendUpdatedDiagnostics() here; the watcher add will
|
|
277
|
-
// call the listener which calls it
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
let closedFile = (fileUri) => {
|
|
281
|
-
let filePath = (0, url_1.fileURLToPath)(fileUri);
|
|
282
|
-
stupidFileContentCache.delete(filePath);
|
|
283
|
-
let projectRootPath = utils.findProjectRootOfFile(filePath);
|
|
284
|
-
if (projectRootPath != null) {
|
|
285
|
-
let root = projectsFiles.get(projectRootPath);
|
|
286
|
-
if (root != null) {
|
|
287
|
-
root.openFiles.delete(filePath);
|
|
288
|
-
// clear diagnostics too if no open files open in said project
|
|
289
|
-
if (root.openFiles.size === 0) {
|
|
290
|
-
compilerLogsWatcher.unwatch(path.join(projectRootPath, c.compilerLogPartialPath));
|
|
291
|
-
deleteProjectDiagnostics(projectRootPath);
|
|
292
|
-
if (root.bsbWatcherByEditor !== null) {
|
|
293
|
-
root.bsbWatcherByEditor.kill();
|
|
294
|
-
root.bsbWatcherByEditor = null;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
let updateOpenedFile = (fileUri, fileContent) => {
|
|
301
|
-
let filePath = (0, url_1.fileURLToPath)(fileUri);
|
|
302
|
-
(0, console_1.assert)(stupidFileContentCache.has(filePath));
|
|
303
|
-
stupidFileContentCache.set(filePath, fileContent);
|
|
304
|
-
};
|
|
305
|
-
let getOpenedFileContent = (fileUri) => {
|
|
306
|
-
let filePath = (0, url_1.fileURLToPath)(fileUri);
|
|
307
|
-
let content = stupidFileContentCache.get(filePath);
|
|
308
|
-
(0, console_1.assert)(content != null);
|
|
309
|
-
return content;
|
|
310
|
-
};
|
|
311
|
-
function listen(useStdio = false) {
|
|
312
|
-
// Start listening now!
|
|
313
|
-
// We support two modes: the regular node RPC mode for VSCode, and the --stdio
|
|
314
|
-
// mode for other editors The latter is _technically unsupported_. It's an
|
|
315
|
-
// implementation detail that might change at any time
|
|
316
|
-
if (useStdio) {
|
|
317
|
-
let writer = new rpc.StreamMessageWriter(process_1.default.stdout);
|
|
318
|
-
let reader = new rpc.StreamMessageReader(process_1.default.stdin);
|
|
319
|
-
// proper `this` scope for writer
|
|
320
|
-
send = (msg) => writer.write(msg);
|
|
321
|
-
reader.listen(onMessage);
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
// proper `this` scope for process
|
|
325
|
-
send = (msg) => process_1.default.send(msg);
|
|
326
|
-
process_1.default.on("message", onMessage);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
exports.default = listen;
|
|
330
|
-
function hover(msg) {
|
|
331
|
-
let params = msg.params;
|
|
332
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
333
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
334
|
-
let tmpname = utils.createFileInTempDir();
|
|
335
|
-
fs_1.default.writeFileSync(tmpname, code, { encoding: "utf-8" });
|
|
336
|
-
let response = utils.runAnalysisCommand(filePath, [
|
|
337
|
-
"hover",
|
|
338
|
-
filePath,
|
|
339
|
-
params.position.line,
|
|
340
|
-
params.position.character,
|
|
341
|
-
tmpname,
|
|
342
|
-
Boolean(extensionClientCapabilities.supportsMarkdownLinks),
|
|
343
|
-
], msg);
|
|
344
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
345
|
-
return response;
|
|
346
|
-
}
|
|
347
|
-
function inlayHint(msg) {
|
|
348
|
-
const params = msg.params;
|
|
349
|
-
const filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
350
|
-
const response = utils.runAnalysisCommand(filePath, [
|
|
351
|
-
"inlayHint",
|
|
352
|
-
filePath,
|
|
353
|
-
params.range.start.line,
|
|
354
|
-
params.range.end.line,
|
|
355
|
-
extensionConfiguration.inlayHints.maxLength,
|
|
356
|
-
], msg);
|
|
357
|
-
return response;
|
|
358
|
-
}
|
|
359
|
-
function sendInlayHintsRefresh() {
|
|
360
|
-
let request = {
|
|
361
|
-
jsonrpc: c.jsonrpcVersion,
|
|
362
|
-
method: p.InlayHintRefreshRequest.method,
|
|
363
|
-
id: serverSentRequestIdCounter++,
|
|
364
|
-
};
|
|
365
|
-
send(request);
|
|
366
|
-
}
|
|
367
|
-
function codeLens(msg) {
|
|
368
|
-
const params = msg.params;
|
|
369
|
-
const filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
370
|
-
const response = utils.runAnalysisCommand(filePath, ["codeLens", filePath], msg);
|
|
371
|
-
return response;
|
|
372
|
-
}
|
|
373
|
-
function sendCodeLensRefresh() {
|
|
374
|
-
let request = {
|
|
375
|
-
jsonrpc: c.jsonrpcVersion,
|
|
376
|
-
method: p.CodeLensRefreshRequest.method,
|
|
377
|
-
id: serverSentRequestIdCounter++,
|
|
378
|
-
};
|
|
379
|
-
send(request);
|
|
380
|
-
}
|
|
381
|
-
function signatureHelp(msg) {
|
|
382
|
-
let params = msg.params;
|
|
383
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
384
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
385
|
-
let tmpname = utils.createFileInTempDir();
|
|
386
|
-
fs_1.default.writeFileSync(tmpname, code, { encoding: "utf-8" });
|
|
387
|
-
let response = utils.runAnalysisCommand(filePath, [
|
|
388
|
-
"signatureHelp",
|
|
389
|
-
filePath,
|
|
390
|
-
params.position.line,
|
|
391
|
-
params.position.character,
|
|
392
|
-
tmpname,
|
|
393
|
-
], msg);
|
|
394
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
395
|
-
return response;
|
|
396
|
-
}
|
|
397
|
-
function definition(msg) {
|
|
398
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
|
|
399
|
-
let params = msg.params;
|
|
400
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
401
|
-
let response = utils.runAnalysisCommand(filePath, ["definition", filePath, params.position.line, params.position.character], msg);
|
|
402
|
-
return response;
|
|
403
|
-
}
|
|
404
|
-
function typeDefinition(msg) {
|
|
405
|
-
// https://microsoft.github.io/language-server-protocol/specification/specification-current/#textDocument_typeDefinition
|
|
406
|
-
let params = msg.params;
|
|
407
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
408
|
-
let response = utils.runAnalysisCommand(filePath, [
|
|
409
|
-
"typeDefinition",
|
|
410
|
-
filePath,
|
|
411
|
-
params.position.line,
|
|
412
|
-
params.position.character,
|
|
413
|
-
], msg);
|
|
414
|
-
return response;
|
|
415
|
-
}
|
|
416
|
-
function references(msg) {
|
|
417
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
|
418
|
-
let params = msg.params;
|
|
419
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
420
|
-
let result = utils.getReferencesForPosition(filePath, params.position);
|
|
421
|
-
let response = {
|
|
422
|
-
jsonrpc: c.jsonrpcVersion,
|
|
423
|
-
id: msg.id,
|
|
424
|
-
result,
|
|
425
|
-
// error: code and message set in case an exception happens during the definition request.
|
|
426
|
-
};
|
|
427
|
-
return response;
|
|
428
|
-
}
|
|
429
|
-
function prepareRename(msg) {
|
|
430
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
|
|
431
|
-
let params = msg.params;
|
|
432
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
433
|
-
let locations = utils.getReferencesForPosition(filePath, params.position);
|
|
434
|
-
let result = null;
|
|
435
|
-
if (locations !== null) {
|
|
436
|
-
locations.forEach((loc) => {
|
|
437
|
-
if (path.normalize((0, url_1.fileURLToPath)(loc.uri)) ===
|
|
438
|
-
path.normalize((0, url_1.fileURLToPath)(params.textDocument.uri))) {
|
|
439
|
-
let { start, end } = loc.range;
|
|
440
|
-
let pos = params.position;
|
|
441
|
-
if (start.character <= pos.character &&
|
|
442
|
-
start.line <= pos.line &&
|
|
443
|
-
end.character >= pos.character &&
|
|
444
|
-
end.line >= pos.line) {
|
|
445
|
-
result = loc.range;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
return {
|
|
451
|
-
jsonrpc: c.jsonrpcVersion,
|
|
452
|
-
id: msg.id,
|
|
453
|
-
result,
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
function rename(msg) {
|
|
457
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
|
|
458
|
-
let params = msg.params;
|
|
459
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
460
|
-
let documentChanges = utils.runAnalysisAfterSanityCheck(filePath, [
|
|
461
|
-
"rename",
|
|
462
|
-
filePath,
|
|
463
|
-
params.position.line,
|
|
464
|
-
params.position.character,
|
|
465
|
-
params.newName,
|
|
466
|
-
]);
|
|
467
|
-
let result = null;
|
|
468
|
-
if (documentChanges !== null) {
|
|
469
|
-
result = { documentChanges };
|
|
470
|
-
}
|
|
471
|
-
let response = {
|
|
472
|
-
jsonrpc: c.jsonrpcVersion,
|
|
473
|
-
id: msg.id,
|
|
474
|
-
result,
|
|
475
|
-
};
|
|
476
|
-
return response;
|
|
477
|
-
}
|
|
478
|
-
function documentSymbol(msg) {
|
|
479
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
|
|
480
|
-
let params = msg.params;
|
|
481
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
482
|
-
let extension = path.extname(params.textDocument.uri);
|
|
483
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
484
|
-
let tmpname = utils.createFileInTempDir(extension);
|
|
485
|
-
fs_1.default.writeFileSync(tmpname, code, { encoding: "utf-8" });
|
|
486
|
-
let response = utils.runAnalysisCommand(filePath, ["documentSymbol", tmpname], msg,
|
|
487
|
-
/* projectRequired */ false);
|
|
488
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
489
|
-
return response;
|
|
490
|
-
}
|
|
491
|
-
function askForAllCurrentConfiguration() {
|
|
492
|
-
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration
|
|
493
|
-
let params = {
|
|
494
|
-
items: [
|
|
495
|
-
{
|
|
496
|
-
section: "rescript.settings",
|
|
497
|
-
},
|
|
498
|
-
],
|
|
499
|
-
};
|
|
500
|
-
let req = {
|
|
501
|
-
jsonrpc: c.jsonrpcVersion,
|
|
502
|
-
id: c.configurationRequestId,
|
|
503
|
-
method: p.ConfigurationRequest.type.method,
|
|
504
|
-
params,
|
|
505
|
-
};
|
|
506
|
-
send(req);
|
|
507
|
-
}
|
|
508
|
-
function semanticTokens(msg) {
|
|
509
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens
|
|
510
|
-
let params = msg.params;
|
|
511
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
512
|
-
let extension = path.extname(params.textDocument.uri);
|
|
513
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
514
|
-
let tmpname = utils.createFileInTempDir(extension);
|
|
515
|
-
fs_1.default.writeFileSync(tmpname, code, { encoding: "utf-8" });
|
|
516
|
-
let response = utils.runAnalysisCommand(filePath, ["semanticTokens", tmpname], msg,
|
|
517
|
-
/* projectRequired */ false);
|
|
518
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
519
|
-
return response;
|
|
520
|
-
}
|
|
521
|
-
function completion(msg) {
|
|
522
|
-
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
|
|
523
|
-
let params = msg.params;
|
|
524
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
525
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
526
|
-
let tmpname = utils.createFileInTempDir();
|
|
527
|
-
fs_1.default.writeFileSync(tmpname, code, { encoding: "utf-8" });
|
|
528
|
-
let response = utils.runAnalysisCommand(filePath, [
|
|
529
|
-
"completion",
|
|
530
|
-
filePath,
|
|
531
|
-
params.position.line,
|
|
532
|
-
params.position.character,
|
|
533
|
-
tmpname,
|
|
534
|
-
Boolean(extensionClientCapabilities.supportsSnippetSyntax),
|
|
535
|
-
], msg);
|
|
536
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
537
|
-
return response;
|
|
538
|
-
}
|
|
539
|
-
function codeAction(msg) {
|
|
540
|
-
var _a;
|
|
541
|
-
let params = msg.params;
|
|
542
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
543
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
544
|
-
let extension = path.extname(params.textDocument.uri);
|
|
545
|
-
let tmpname = utils.createFileInTempDir(extension);
|
|
546
|
-
// Check local code actions coming from the diagnostics.
|
|
547
|
-
let localResults = [];
|
|
548
|
-
(_a = codeActionsFromDiagnostics[params.textDocument.uri]) === null || _a === void 0 ? void 0 : _a.forEach(({ range, codeAction }) => {
|
|
549
|
-
if (utils.rangeContainsRange(range, params.range)) {
|
|
550
|
-
localResults.push(codeAction);
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
fs_1.default.writeFileSync(tmpname, code, { encoding: "utf-8" });
|
|
554
|
-
let response = utils.runAnalysisCommand(filePath, [
|
|
555
|
-
"codeAction",
|
|
556
|
-
filePath,
|
|
557
|
-
params.range.start.line,
|
|
558
|
-
params.range.start.character,
|
|
559
|
-
params.range.end.line,
|
|
560
|
-
params.range.end.character,
|
|
561
|
-
tmpname,
|
|
562
|
-
], msg);
|
|
563
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
564
|
-
let { result } = response;
|
|
565
|
-
// We must send `null` when there are no results, empty array isn't enough.
|
|
566
|
-
let codeActions = result != null && Array.isArray(result)
|
|
567
|
-
? [...localResults, ...result]
|
|
568
|
-
: localResults;
|
|
569
|
-
let res = {
|
|
570
|
-
jsonrpc: c.jsonrpcVersion,
|
|
571
|
-
id: msg.id,
|
|
572
|
-
result: codeActions.length > 0 ? codeActions : null,
|
|
573
|
-
};
|
|
574
|
-
return res;
|
|
575
|
-
}
|
|
576
|
-
function format(msg) {
|
|
577
|
-
// technically, a formatting failure should reply with the error. Sadly
|
|
578
|
-
// the LSP alert box for these error replies sucks (e.g. doesn't actually
|
|
579
|
-
// display the message). In order to signal the client to display a proper
|
|
580
|
-
// alert box (sometime with actionable buttons), we need to first send
|
|
581
|
-
// back a fake success message (because each request mandates a
|
|
582
|
-
// response), then right away send a server notification to display a
|
|
583
|
-
// nicer alert. Ugh.
|
|
584
|
-
let fakeSuccessResponse = {
|
|
585
|
-
jsonrpc: c.jsonrpcVersion,
|
|
586
|
-
id: msg.id,
|
|
587
|
-
result: [],
|
|
588
|
-
};
|
|
589
|
-
let params = msg.params;
|
|
590
|
-
let filePath = (0, url_1.fileURLToPath)(params.textDocument.uri);
|
|
591
|
-
let extension = path.extname(params.textDocument.uri);
|
|
592
|
-
if (extension !== c.resExt && extension !== c.resiExt) {
|
|
593
|
-
let params = {
|
|
594
|
-
type: p.MessageType.Error,
|
|
595
|
-
message: `Not a ${c.resExt} or ${c.resiExt} file. Cannot format it.`,
|
|
596
|
-
};
|
|
597
|
-
let response = {
|
|
598
|
-
jsonrpc: c.jsonrpcVersion,
|
|
599
|
-
method: "window/showMessage",
|
|
600
|
-
params: params,
|
|
601
|
-
};
|
|
602
|
-
return [fakeSuccessResponse, response];
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
// code will always be defined here, even though technically it can be undefined
|
|
606
|
-
let code = getOpenedFileContent(params.textDocument.uri);
|
|
607
|
-
let projectRootPath = utils.findProjectRootOfFile(filePath);
|
|
608
|
-
let bscExeBinaryPath = findBscExeBinary(projectRootPath);
|
|
609
|
-
let formattedResult = utils.formatCode(bscExeBinaryPath, filePath, code, extensionConfiguration.allowBuiltInFormatter);
|
|
610
|
-
if (formattedResult.kind === "success") {
|
|
611
|
-
let max = code.length;
|
|
612
|
-
let result = [
|
|
613
|
-
{
|
|
614
|
-
range: {
|
|
615
|
-
start: { line: 0, character: 0 },
|
|
616
|
-
end: { line: max, character: max },
|
|
617
|
-
},
|
|
618
|
-
newText: formattedResult.result,
|
|
619
|
-
},
|
|
620
|
-
];
|
|
621
|
-
let response = {
|
|
622
|
-
jsonrpc: c.jsonrpcVersion,
|
|
623
|
-
id: msg.id,
|
|
624
|
-
result: result,
|
|
625
|
-
};
|
|
626
|
-
return [response];
|
|
627
|
-
}
|
|
628
|
-
else if (formattedResult.kind === "blocked-using-built-in-formatter") {
|
|
629
|
-
// Let's only prompt the user once about this, or things might become annoying.
|
|
630
|
-
if (hasPromptedAboutBuiltInFormatter) {
|
|
631
|
-
return [fakeSuccessResponse];
|
|
632
|
-
}
|
|
633
|
-
hasPromptedAboutBuiltInFormatter = true;
|
|
634
|
-
let params = {
|
|
635
|
-
type: p.MessageType.Warning,
|
|
636
|
-
message: `Formatting not applied! Could not find the ReScript compiler in the current project, and you haven't configured the extension to allow formatting using the built in formatter. To allow formatting files not strictly part of a ReScript project using the built in formatter, [please configure the extension to allow that.](command:workbench.action.openSettings?${encodeURIComponent(JSON.stringify(["rescript.settings.allowBuiltInFormatter"]))})`,
|
|
637
|
-
};
|
|
638
|
-
let response = {
|
|
639
|
-
jsonrpc: c.jsonrpcVersion,
|
|
640
|
-
method: "window/showMessage",
|
|
641
|
-
params: params,
|
|
642
|
-
};
|
|
643
|
-
return [fakeSuccessResponse, response];
|
|
644
|
-
}
|
|
645
|
-
else {
|
|
646
|
-
// let the diagnostics logic display the updated syntax errors,
|
|
647
|
-
// from the build.
|
|
648
|
-
// Again, not sending the actual errors. See fakeSuccessResponse
|
|
649
|
-
// above for explanation
|
|
650
|
-
return [fakeSuccessResponse];
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
let updateDiagnosticSyntax = (fileUri, fileContent) => {
|
|
655
|
-
let filePath = (0, url_1.fileURLToPath)(fileUri);
|
|
656
|
-
let extension = path.extname(filePath);
|
|
657
|
-
let tmpname = utils.createFileInTempDir(extension);
|
|
658
|
-
fs_1.default.writeFileSync(tmpname, fileContent, { encoding: "utf-8" });
|
|
659
|
-
// We need to account for any existing diagnostics from the compiler for this
|
|
660
|
-
// file. If we don't we might accidentally clear the current file's compiler
|
|
661
|
-
// diagnostics if there's no syntax diagostics to send. This is because
|
|
662
|
-
// publishing an empty diagnostics array is equivalent to saying "clear all
|
|
663
|
-
// errors".
|
|
664
|
-
let compilerDiagnosticsForFile = getCurrentCompilerDiagnosticsForFile(fileUri);
|
|
665
|
-
let syntaxDiagnosticsForFile = utils.runAnalysisAfterSanityCheck(filePath, ["diagnosticSyntax", tmpname]);
|
|
666
|
-
let notification = {
|
|
667
|
-
jsonrpc: c.jsonrpcVersion,
|
|
668
|
-
method: "textDocument/publishDiagnostics",
|
|
669
|
-
params: {
|
|
670
|
-
uri: fileUri,
|
|
671
|
-
diagnostics: [...syntaxDiagnosticsForFile, ...compilerDiagnosticsForFile],
|
|
672
|
-
},
|
|
673
|
-
};
|
|
674
|
-
fs_1.default.unlink(tmpname, () => null);
|
|
675
|
-
send(notification);
|
|
676
|
-
};
|
|
677
|
-
function createInterface(msg) {
|
|
678
|
-
let params = msg.params;
|
|
679
|
-
let extension = path.extname(params.uri);
|
|
680
|
-
let filePath = (0, url_1.fileURLToPath)(params.uri);
|
|
681
|
-
let projDir = utils.findProjectRootOfFile(filePath);
|
|
682
|
-
if (projDir === null) {
|
|
683
|
-
let params = {
|
|
684
|
-
type: p.MessageType.Error,
|
|
685
|
-
message: `Cannot locate project directory to generate the interface file.`,
|
|
686
|
-
};
|
|
687
|
-
let response = {
|
|
688
|
-
jsonrpc: c.jsonrpcVersion,
|
|
689
|
-
method: "window/showMessage",
|
|
690
|
-
params: params,
|
|
691
|
-
};
|
|
692
|
-
return response;
|
|
693
|
-
}
|
|
694
|
-
if (extension !== c.resExt) {
|
|
695
|
-
let params = {
|
|
696
|
-
type: p.MessageType.Error,
|
|
697
|
-
message: `Not a ${c.resExt} file. Cannot create an interface for it.`,
|
|
698
|
-
};
|
|
699
|
-
let response = {
|
|
700
|
-
jsonrpc: c.jsonrpcVersion,
|
|
701
|
-
method: "window/showMessage",
|
|
702
|
-
params: params,
|
|
703
|
-
};
|
|
704
|
-
return response;
|
|
705
|
-
}
|
|
706
|
-
let resPartialPath = filePath.split(projDir)[1];
|
|
707
|
-
// The .cmi filename may have a namespace suffix appended.
|
|
708
|
-
let namespaceResult = utils.getNamespaceNameFromConfigFile(projDir);
|
|
709
|
-
if (namespaceResult.kind === "error") {
|
|
710
|
-
let params = {
|
|
711
|
-
type: p.MessageType.Error,
|
|
712
|
-
message: `Error reading ReScript config file.`,
|
|
713
|
-
};
|
|
714
|
-
let response = {
|
|
715
|
-
jsonrpc: c.jsonrpcVersion,
|
|
716
|
-
method: "window/showMessage",
|
|
717
|
-
params,
|
|
718
|
-
};
|
|
719
|
-
return response;
|
|
720
|
-
}
|
|
721
|
-
let namespace = namespaceResult.result;
|
|
722
|
-
let suffixToAppend = namespace.length > 0 ? "-" + namespace : "";
|
|
723
|
-
let cmiPartialPath = path.join(path.dirname(resPartialPath), path.basename(resPartialPath, c.resExt) + suffixToAppend + c.cmiExt);
|
|
724
|
-
let cmiPath = path.join(projDir, c.compilerDirPartialPath, cmiPartialPath);
|
|
725
|
-
let cmiAvailable = fs_1.default.existsSync(cmiPath);
|
|
726
|
-
if (!cmiAvailable) {
|
|
727
|
-
let params = {
|
|
728
|
-
type: p.MessageType.Error,
|
|
729
|
-
message: `No compiled interface file found. Please compile your project first.`,
|
|
730
|
-
};
|
|
731
|
-
let response = {
|
|
732
|
-
jsonrpc: c.jsonrpcVersion,
|
|
733
|
-
method: "window/showMessage",
|
|
734
|
-
params,
|
|
735
|
-
};
|
|
736
|
-
return response;
|
|
737
|
-
}
|
|
738
|
-
let response = utils.runAnalysisCommand(filePath, ["createInterface", filePath, cmiPath], msg);
|
|
739
|
-
let result = typeof response.result === "string" ? response.result : "";
|
|
740
|
-
try {
|
|
741
|
-
let resiPath = lookup.replaceFileExtension(filePath, c.resiExt);
|
|
742
|
-
fs_1.default.writeFileSync(resiPath, result, { encoding: "utf-8" });
|
|
743
|
-
let response = {
|
|
744
|
-
jsonrpc: c.jsonrpcVersion,
|
|
745
|
-
id: msg.id,
|
|
746
|
-
result: {
|
|
747
|
-
uri: utils.pathToURI(resiPath),
|
|
748
|
-
},
|
|
749
|
-
};
|
|
750
|
-
return response;
|
|
751
|
-
}
|
|
752
|
-
catch (e) {
|
|
753
|
-
let response = {
|
|
754
|
-
jsonrpc: c.jsonrpcVersion,
|
|
755
|
-
id: msg.id,
|
|
756
|
-
error: {
|
|
757
|
-
code: p.ErrorCodes.InternalError,
|
|
758
|
-
message: "Unable to create interface file.",
|
|
759
|
-
},
|
|
760
|
-
};
|
|
761
|
-
return response;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
function openCompiledFile(msg) {
|
|
765
|
-
let params = msg.params;
|
|
766
|
-
let filePath = (0, url_1.fileURLToPath)(params.uri);
|
|
767
|
-
let projDir = utils.findProjectRootOfFile(filePath);
|
|
768
|
-
if (projDir === null) {
|
|
769
|
-
let params = {
|
|
770
|
-
type: p.MessageType.Error,
|
|
771
|
-
message: `Cannot locate project directory.`,
|
|
772
|
-
};
|
|
773
|
-
let response = {
|
|
774
|
-
jsonrpc: c.jsonrpcVersion,
|
|
775
|
-
method: "window/showMessage",
|
|
776
|
-
params: params,
|
|
777
|
-
};
|
|
778
|
-
return response;
|
|
779
|
-
}
|
|
780
|
-
let compiledFilePath = utils.getCompiledFilePath(filePath, projDir);
|
|
781
|
-
if (compiledFilePath.kind === "error" ||
|
|
782
|
-
!fs_1.default.existsSync(compiledFilePath.result)) {
|
|
783
|
-
let message = compiledFilePath.kind === "success"
|
|
784
|
-
? `No compiled file found. Expected it at: ${compiledFilePath.result}`
|
|
785
|
-
: `No compiled file found. Please compile your project first.`;
|
|
786
|
-
let params = {
|
|
787
|
-
type: p.MessageType.Error,
|
|
788
|
-
message,
|
|
789
|
-
};
|
|
790
|
-
let response = {
|
|
791
|
-
jsonrpc: c.jsonrpcVersion,
|
|
792
|
-
method: "window/showMessage",
|
|
793
|
-
params,
|
|
794
|
-
};
|
|
795
|
-
return response;
|
|
796
|
-
}
|
|
797
|
-
let response = {
|
|
798
|
-
jsonrpc: c.jsonrpcVersion,
|
|
799
|
-
id: msg.id,
|
|
800
|
-
result: {
|
|
801
|
-
uri: utils.pathToURI(compiledFilePath.result),
|
|
802
|
-
},
|
|
803
|
-
};
|
|
804
|
-
return response;
|
|
805
|
-
}
|
|
806
|
-
function onMessage(msg) {
|
|
807
|
-
var _a, _b, _c, _d, _f, _g, _h;
|
|
808
|
-
if (p.Message.isNotification(msg)) {
|
|
809
|
-
// notification message, aka the client ends it and doesn't want a reply
|
|
810
|
-
if (!initialized && msg.method !== "exit") {
|
|
811
|
-
// From spec: "Notifications should be dropped, except for the exit notification. This will allow the exit of a server without an initialize request"
|
|
812
|
-
// For us: do nothing. We don't have anything we need to clean up right now
|
|
813
|
-
// TODO: we might have things we need to clean up now... like some watcher stuff
|
|
814
|
-
}
|
|
815
|
-
else if (msg.method === "exit") {
|
|
816
|
-
// The server should exit with success code 0 if the shutdown request has been received before; otherwise with error code 1
|
|
817
|
-
if (shutdownRequestAlreadyReceived) {
|
|
818
|
-
process_1.default.exit(0);
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
821
|
-
process_1.default.exit(1);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
else if (msg.method === vscode_languageserver_protocol_1.DidOpenTextDocumentNotification.method) {
|
|
825
|
-
let params = msg.params;
|
|
826
|
-
openedFile(params.textDocument.uri, params.textDocument.text);
|
|
827
|
-
updateDiagnosticSyntax(params.textDocument.uri, params.textDocument.text);
|
|
828
|
-
}
|
|
829
|
-
else if (msg.method === vscode_languageserver_protocol_1.DidChangeTextDocumentNotification.method) {
|
|
830
|
-
let params = msg.params;
|
|
831
|
-
let extName = path.extname(params.textDocument.uri);
|
|
832
|
-
if (extName === c.resExt || extName === c.resiExt) {
|
|
833
|
-
let changes = params.contentChanges;
|
|
834
|
-
if (changes.length === 0) {
|
|
835
|
-
// no change?
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
// we currently only support full changes
|
|
839
|
-
updateOpenedFile(params.textDocument.uri, changes[changes.length - 1].text);
|
|
840
|
-
updateDiagnosticSyntax(params.textDocument.uri, changes[changes.length - 1].text);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
else if (msg.method === vscode_languageserver_protocol_1.DidCloseTextDocumentNotification.method) {
|
|
845
|
-
let params = msg.params;
|
|
846
|
-
closedFile(params.textDocument.uri);
|
|
847
|
-
}
|
|
848
|
-
else if (msg.method === vscode_languageserver_protocol_1.DidChangeConfigurationNotification.type.method) {
|
|
849
|
-
// Can't seem to get this notification to trigger, but if it does this will be here and ensure we're synced up at the server.
|
|
850
|
-
askForAllCurrentConfiguration();
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
else if (p.Message.isRequest(msg)) {
|
|
854
|
-
// request message, aka client sent request and waits for our mandatory reply
|
|
855
|
-
if (!initialized && msg.method !== "initialize") {
|
|
856
|
-
let response = {
|
|
857
|
-
jsonrpc: c.jsonrpcVersion,
|
|
858
|
-
id: msg.id,
|
|
859
|
-
error: {
|
|
860
|
-
code: p.ErrorCodes.ServerNotInitialized,
|
|
861
|
-
message: "Server not initialized.",
|
|
862
|
-
},
|
|
863
|
-
};
|
|
864
|
-
send(response);
|
|
865
|
-
}
|
|
866
|
-
else if (msg.method === "initialize") {
|
|
867
|
-
// Save initial configuration, if present
|
|
868
|
-
let initParams = msg.params;
|
|
869
|
-
let initialConfiguration = (_a = initParams.initializationOptions) === null || _a === void 0 ? void 0 : _a.extensionConfiguration;
|
|
870
|
-
if (initialConfiguration != null) {
|
|
871
|
-
extensionConfiguration = initialConfiguration;
|
|
872
|
-
}
|
|
873
|
-
// These are static configuration options the client can set to enable certain
|
|
874
|
-
let extensionClientCapabilitiesFromClient = (_b = initParams
|
|
875
|
-
.initializationOptions) === null || _b === void 0 ? void 0 : _b.extensionClientCapabilities;
|
|
876
|
-
if (extensionClientCapabilitiesFromClient != null) {
|
|
877
|
-
extensionClientCapabilities = extensionClientCapabilitiesFromClient;
|
|
878
|
-
}
|
|
879
|
-
extensionClientCapabilities.supportsSnippetSyntax = Boolean((_f = (_d = (_c = initParams.capabilities.textDocument) === null || _c === void 0 ? void 0 : _c.completion) === null || _d === void 0 ? void 0 : _d.completionItem) === null || _f === void 0 ? void 0 : _f.snippetSupport);
|
|
880
|
-
// send the list of features we support
|
|
881
|
-
let result = {
|
|
882
|
-
// This tells the client: "hey, we support the following operations".
|
|
883
|
-
// Example: we want to expose "jump-to-definition".
|
|
884
|
-
// By adding `definitionProvider: true`, the client will now send "jump-to-definition" requests.
|
|
885
|
-
capabilities: {
|
|
886
|
-
// TODO: incremental sync?
|
|
887
|
-
textDocumentSync: v.TextDocumentSyncKind.Full,
|
|
888
|
-
documentFormattingProvider: true,
|
|
889
|
-
hoverProvider: true,
|
|
890
|
-
definitionProvider: true,
|
|
891
|
-
typeDefinitionProvider: true,
|
|
892
|
-
referencesProvider: true,
|
|
893
|
-
codeActionProvider: true,
|
|
894
|
-
renameProvider: { prepareProvider: true },
|
|
895
|
-
documentSymbolProvider: true,
|
|
896
|
-
completionProvider: {
|
|
897
|
-
triggerCharacters: [".", ">", "@", "~", '"', "=", "("],
|
|
898
|
-
},
|
|
899
|
-
semanticTokensProvider: {
|
|
900
|
-
legend: {
|
|
901
|
-
tokenTypes: [
|
|
902
|
-
"operator",
|
|
903
|
-
"variable",
|
|
904
|
-
"type",
|
|
905
|
-
"modifier",
|
|
906
|
-
"namespace",
|
|
907
|
-
"enumMember",
|
|
908
|
-
"property",
|
|
909
|
-
"interface", // emit jsxlowercase, div in <div> as interface
|
|
910
|
-
],
|
|
911
|
-
tokenModifiers: [],
|
|
912
|
-
},
|
|
913
|
-
documentSelector: [{ scheme: "file", language: "rescript" }],
|
|
914
|
-
// TODO: Support range for full, and add delta support
|
|
915
|
-
full: true,
|
|
916
|
-
},
|
|
917
|
-
inlayHintProvider: (_g = extensionConfiguration.inlayHints) === null || _g === void 0 ? void 0 : _g.enable,
|
|
918
|
-
codeLensProvider: extensionConfiguration.codeLens
|
|
919
|
-
? {
|
|
920
|
-
workDoneProgress: false,
|
|
921
|
-
}
|
|
922
|
-
: undefined,
|
|
923
|
-
signatureHelpProvider: ((_h = extensionConfiguration.signatureHelp) === null || _h === void 0 ? void 0 : _h.enabled)
|
|
924
|
-
? {
|
|
925
|
-
triggerCharacters: ["("],
|
|
926
|
-
retriggerCharacters: ["=", ","],
|
|
927
|
-
}
|
|
928
|
-
: undefined,
|
|
929
|
-
},
|
|
930
|
-
};
|
|
931
|
-
let response = {
|
|
932
|
-
jsonrpc: c.jsonrpcVersion,
|
|
933
|
-
id: msg.id,
|
|
934
|
-
result: result,
|
|
935
|
-
};
|
|
936
|
-
initialized = true;
|
|
937
|
-
// Periodically pull configuration from the client.
|
|
938
|
-
pullConfigurationPeriodically = setInterval(() => {
|
|
939
|
-
askForAllCurrentConfiguration();
|
|
940
|
-
}, c.pullConfigurationInterval);
|
|
941
|
-
send(response);
|
|
942
|
-
}
|
|
943
|
-
else if (msg.method === "initialized") {
|
|
944
|
-
// sent from client after initialize. Nothing to do for now
|
|
945
|
-
let response = {
|
|
946
|
-
jsonrpc: c.jsonrpcVersion,
|
|
947
|
-
id: msg.id,
|
|
948
|
-
result: null,
|
|
949
|
-
};
|
|
950
|
-
send(response);
|
|
951
|
-
}
|
|
952
|
-
else if (msg.method === "shutdown") {
|
|
953
|
-
// https://microsoft.github.io/language-server-protocol/specification#shutdown
|
|
954
|
-
if (shutdownRequestAlreadyReceived) {
|
|
955
|
-
let response = {
|
|
956
|
-
jsonrpc: c.jsonrpcVersion,
|
|
957
|
-
id: msg.id,
|
|
958
|
-
error: {
|
|
959
|
-
code: p.ErrorCodes.InvalidRequest,
|
|
960
|
-
message: `Language server already received the shutdown request`,
|
|
961
|
-
},
|
|
962
|
-
};
|
|
963
|
-
send(response);
|
|
964
|
-
}
|
|
965
|
-
else {
|
|
966
|
-
shutdownRequestAlreadyReceived = true;
|
|
967
|
-
// TODO: recheck logic around init/shutdown...
|
|
968
|
-
stopWatchingCompilerLog();
|
|
969
|
-
// TODO: delete bsb watchers
|
|
970
|
-
if (pullConfigurationPeriodically != null) {
|
|
971
|
-
clearInterval(pullConfigurationPeriodically);
|
|
972
|
-
}
|
|
973
|
-
let response = {
|
|
974
|
-
jsonrpc: c.jsonrpcVersion,
|
|
975
|
-
id: msg.id,
|
|
976
|
-
result: null,
|
|
977
|
-
};
|
|
978
|
-
send(response);
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
else if (msg.method === p.HoverRequest.method) {
|
|
982
|
-
send(hover(msg));
|
|
983
|
-
}
|
|
984
|
-
else if (msg.method === p.DefinitionRequest.method) {
|
|
985
|
-
send(definition(msg));
|
|
986
|
-
}
|
|
987
|
-
else if (msg.method === p.TypeDefinitionRequest.method) {
|
|
988
|
-
send(typeDefinition(msg));
|
|
989
|
-
}
|
|
990
|
-
else if (msg.method === p.ReferencesRequest.method) {
|
|
991
|
-
send(references(msg));
|
|
992
|
-
}
|
|
993
|
-
else if (msg.method === p.PrepareRenameRequest.method) {
|
|
994
|
-
send(prepareRename(msg));
|
|
995
|
-
}
|
|
996
|
-
else if (msg.method === p.RenameRequest.method) {
|
|
997
|
-
send(rename(msg));
|
|
998
|
-
}
|
|
999
|
-
else if (msg.method === p.DocumentSymbolRequest.method) {
|
|
1000
|
-
send(documentSymbol(msg));
|
|
1001
|
-
}
|
|
1002
|
-
else if (msg.method === p.CompletionRequest.method) {
|
|
1003
|
-
send(completion(msg));
|
|
1004
|
-
}
|
|
1005
|
-
else if (msg.method === p.SemanticTokensRequest.method) {
|
|
1006
|
-
send(semanticTokens(msg));
|
|
1007
|
-
}
|
|
1008
|
-
else if (msg.method === p.CodeActionRequest.method) {
|
|
1009
|
-
send(codeAction(msg));
|
|
1010
|
-
}
|
|
1011
|
-
else if (msg.method === p.DocumentFormattingRequest.method) {
|
|
1012
|
-
let responses = format(msg);
|
|
1013
|
-
responses.forEach((response) => send(response));
|
|
1014
|
-
}
|
|
1015
|
-
else if (msg.method === createInterfaceRequest.method) {
|
|
1016
|
-
send(createInterface(msg));
|
|
1017
|
-
}
|
|
1018
|
-
else if (msg.method === openCompiledFileRequest.method) {
|
|
1019
|
-
send(openCompiledFile(msg));
|
|
1020
|
-
}
|
|
1021
|
-
else if (msg.method === p.InlayHintRequest.method) {
|
|
1022
|
-
let params = msg.params;
|
|
1023
|
-
let extName = path.extname(params.textDocument.uri);
|
|
1024
|
-
if (extName === c.resExt) {
|
|
1025
|
-
send(inlayHint(msg));
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
else if (msg.method === p.CodeLensRequest.method) {
|
|
1029
|
-
let params = msg.params;
|
|
1030
|
-
let extName = path.extname(params.textDocument.uri);
|
|
1031
|
-
if (extName === c.resExt) {
|
|
1032
|
-
send(codeLens(msg));
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
else if (msg.method === p.SignatureHelpRequest.method) {
|
|
1036
|
-
let params = msg.params;
|
|
1037
|
-
let extName = path.extname(params.textDocument.uri);
|
|
1038
|
-
if (extName === c.resExt) {
|
|
1039
|
-
send(signatureHelp(msg));
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
else {
|
|
1043
|
-
let response = {
|
|
1044
|
-
jsonrpc: c.jsonrpcVersion,
|
|
1045
|
-
id: msg.id,
|
|
1046
|
-
error: {
|
|
1047
|
-
code: p.ErrorCodes.InvalidRequest,
|
|
1048
|
-
message: "Unrecognized editor request.",
|
|
1049
|
-
},
|
|
1050
|
-
};
|
|
1051
|
-
send(response);
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
else if (p.Message.isResponse(msg)) {
|
|
1055
|
-
if (msg.id === c.configurationRequestId) {
|
|
1056
|
-
if (msg.result != null) {
|
|
1057
|
-
// This is a response from a request to get updated configuration. Note
|
|
1058
|
-
// that it seems to return the configuration in a way that lets the
|
|
1059
|
-
// current workspace settings override the user settings. This is good
|
|
1060
|
-
// as we get started, but _might_ be problematic further down the line
|
|
1061
|
-
// if we want to support having several projects open at the same time
|
|
1062
|
-
// without their settings overriding eachother. Not a problem now though
|
|
1063
|
-
// as we'll likely only have "global" settings starting out.
|
|
1064
|
-
let [configuration] = msg.result;
|
|
1065
|
-
if (configuration != null) {
|
|
1066
|
-
extensionConfiguration = configuration;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
else if (msg.result != null &&
|
|
1071
|
-
// @ts-ignore
|
|
1072
|
-
msg.result.title != null &&
|
|
1073
|
-
// @ts-ignore
|
|
1074
|
-
msg.result.title === c.startBuildAction) {
|
|
1075
|
-
let msg_ = msg.result;
|
|
1076
|
-
let projectRootPath = msg_.projectRootPath;
|
|
1077
|
-
// TODO: sometime stale .bsb.lock dangling
|
|
1078
|
-
// TODO: close watcher when lang-server shuts down. However, by Node's
|
|
1079
|
-
// default, these subprocesses are automatically killed when this
|
|
1080
|
-
// language-server process exits
|
|
1081
|
-
let rescriptBinaryPath = findRescriptBinary(projectRootPath);
|
|
1082
|
-
if (rescriptBinaryPath != null) {
|
|
1083
|
-
let bsbProcess = utils.runBuildWatcherUsingValidBuildPath(rescriptBinaryPath, projectRootPath);
|
|
1084
|
-
let root = projectsFiles.get(projectRootPath);
|
|
1085
|
-
root.bsbWatcherByEditor = bsbProcess;
|
|
1086
|
-
// bsbProcess.on("message", (a) => console.log(a));
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
// Gate behind a debug setting potentially?
|
|
1092
|
-
(0, errorReporter_1.onErrorReported)((msg) => {
|
|
1093
|
-
let params = {
|
|
1094
|
-
type: p.MessageType.Warning,
|
|
1095
|
-
message: `ReScript tooling: Internal error. Something broke. Here's the error message that you can report if you want:
|
|
1096
|
-
|
|
1097
|
-
${msg}
|
|
1098
|
-
|
|
1099
|
-
(this message will only be reported once every 15 minutes)`,
|
|
1100
|
-
};
|
|
1101
|
-
let message = {
|
|
1102
|
-
jsonrpc: c.jsonrpcVersion,
|
|
1103
|
-
method: "window/showMessage",
|
|
1104
|
-
params: params,
|
|
1105
|
-
};
|
|
1106
|
-
send(message);
|
|
1107
|
-
});
|
|
1108
|
-
//# sourceMappingURL=server.js.map
|