Skip to content

Commit 87ccdbc

Browse files
committed
Fix TS errors
1 parent 14c7144 commit 87ccdbc

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

client/src/extension.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import * as path from 'path';
2-
import { workspace, ExtensionContext, tasks, Task, TaskScope, ShellExecution } from 'vscode';
1+
import * as path from "path";
2+
import { workspace, ExtensionContext } from "vscode";
33

44
import {
55
LanguageClient,
66
LanguageClientOptions,
77
ServerOptions,
88
TransportKind,
9-
DefinitionRequest
10-
} from 'vscode-languageclient';
9+
} from "vscode-languageclient/node";
1110

1211
let client: LanguageClient;
1312

@@ -62,11 +61,11 @@ let client: LanguageClient;
6261
export function activate(context: ExtensionContext) {
6362
// The server is implemented in node
6463
let serverModule = context.asAbsolutePath(
65-
path.join('server', 'out', 'server.js')
64+
path.join("server", "out", "server.js")
6665
);
6766
// The debug options for the server
6867
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
69-
let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
68+
let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };
7069

7170
// If the extension is launched in debug mode then the debug server options are used
7271
// Otherwise the run options are used
@@ -75,26 +74,24 @@ export function activate(context: ExtensionContext) {
7574
debug: {
7675
module: serverModule,
7776
transport: TransportKind.ipc,
78-
options: debugOptions
79-
}
77+
options: debugOptions,
78+
},
8079
};
8180

8281
// Options to control the language client
8382
let clientOptions: LanguageClientOptions = {
8483
// Register the server for plain text documents
85-
documentSelector: [
86-
{ scheme: 'file', language: 'rescript' },
87-
],
84+
documentSelector: [{ scheme: "file", language: "rescript" }],
8885
synchronize: {
8986
// Notify the server about file changes to '.clientrc files contained in the workspace
90-
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
91-
}
87+
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
88+
},
9289
};
9390

9491
// Create the language client and start the client.
9592
client = new LanguageClient(
96-
'ReScriptLSP',
97-
'ReScript Language Server',
93+
"ReScriptLSP",
94+
"ReScript Language Server",
9895
serverOptions,
9996
clientOptions
10097
);

server/src/server.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from "process";
22
import * as p from "vscode-languageserver-protocol";
3-
import * as m from "vscode-jsonrpc/lib/messages";
3+
import * as m from "vscode-jsonrpc/lib/common/messages";
44
import * as v from "vscode-languageserver";
55
import * as rpc from "vscode-jsonrpc";
66
import * as path from "path";
@@ -40,7 +40,7 @@ let projectsFiles: Map<
4040
// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
4141

4242
// will be properly defined later depending on the mode (stdio/node-rpc)
43-
let send: (msg: m.Message) => void = (_) => {};
43+
let send: (msg: m.Message) => void = (_) => { };
4444

4545
let sendUpdatedDiagnostics = () => {
4646
projectsFiles.forEach(({ filesWithDiagnostics }, projectRootPath) => {
@@ -343,15 +343,14 @@ function onMessage(msg: m.Message) {
343343
send(response);
344344
}
345345
} else if (msg.method === p.HoverRequest.method) {
346-
let result: Hover | null = utils.runAnalysisAfterSanityCheck(
347-
msg,
348-
(filePath) => [
349-
"hover",
350-
filePath,
351-
msg.params.position.line,
352-
msg.params.position.character,
353-
]
354-
);
346+
let params = msg.params as p.HoverParams;
347+
let filePath = fileURLToPath(params.textDocument.uri);
348+
let result: Hover | null = utils.runAnalysisAfterSanityCheck(filePath, [
349+
"hover",
350+
filePath,
351+
params.position.line,
352+
params.position.character,
353+
]);
355354
let hoverResponse: m.ResponseMessage = {
356355
jsonrpc: c.jsonrpcVersion,
357356
id: msg.id,
@@ -362,15 +361,16 @@ function onMessage(msg: m.Message) {
362361
send(hoverResponse);
363362
} else if (msg.method === p.DefinitionRequest.method) {
364363
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
365-
let result: Location[] | null = utils.runAnalysisAfterSanityCheck(
366-
msg,
367-
(filePath) => [
364+
let params = msg.params as p.DefinitionParams;
365+
let filePath = fileURLToPath(params.textDocument.uri);
366+
let result:
367+
| Location[]
368+
| null = utils.runAnalysisAfterSanityCheck(filePath, [
368369
"definition",
369370
filePath,
370-
msg.params.position.line,
371-
msg.params.position.character,
372-
]
373-
);
371+
params.position.line,
372+
params.position.character,
373+
]);
374374
let definitionResponse: m.ResponseMessage = {
375375
jsonrpc: c.jsonrpcVersion,
376376
id: msg.id,
@@ -380,13 +380,15 @@ function onMessage(msg: m.Message) {
380380
send(definitionResponse);
381381
} else if (msg.method === p.ReferencesRequest.method) {
382382
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
383+
let params = msg.params as p.ReferenceParams;
384+
let filePath = fileURLToPath(params.textDocument.uri);
383385
let result: Location | null = utils.runAnalysisAfterSanityCheck(
384-
msg,
385-
(filePath) => [
386+
filePath,
387+
[
386388
"references",
387389
filePath,
388-
msg.params.position.line,
389-
msg.params.position.character,
390+
params.position.line,
391+
params.position.character,
390392
]
391393
);
392394
let definitionResponse: m.ResponseMessage = {
@@ -398,31 +400,35 @@ function onMessage(msg: m.Message) {
398400
send(definitionResponse);
399401
} else if (msg.method === p.DocumentSymbolRequest.method) {
400402
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
403+
let params = msg.params as p.DocumentSymbolParams;
404+
let filePath = fileURLToPath(params.textDocument.uri);
401405
let result:
402406
| SymbolInformation[]
403-
| null = utils.runAnalysisAfterSanityCheck(msg, (filePath) => [
404-
"documentSymbol",
405-
filePath,
406-
]);
407+
| null = utils.runAnalysisAfterSanityCheck(filePath, [
408+
"documentSymbol",
409+
filePath,
410+
]);
407411
let definitionResponse: m.ResponseMessage = {
408412
jsonrpc: c.jsonrpcVersion,
409413
id: msg.id,
410414
result,
411415
};
412416
send(definitionResponse);
413417
} else if (msg.method === p.CompletionRequest.method) {
414-
let code = getOpenedFileContent(msg.params.textDocument.uri);
418+
let params = msg.params as p.ReferenceParams;
419+
let filePath = fileURLToPath(params.textDocument.uri);
420+
let code = getOpenedFileContent(params.textDocument.uri);
415421
let tmpname = utils.createFileInTempDir();
416422
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
417423
let result:
418424
| CompletionItem[]
419-
| null = utils.runAnalysisAfterSanityCheck(msg, (filePath) => [
420-
"complete",
421-
filePath,
422-
msg.params.position.line,
423-
msg.params.position.character,
424-
tmpname,
425-
]);
425+
| null = utils.runAnalysisAfterSanityCheck(filePath, [
426+
"complete",
427+
filePath,
428+
params.position.line,
429+
params.position.character,
430+
tmpname,
431+
]);
426432
fs.unlink(tmpname, () => null);
427433
let completionResponse: m.ResponseMessage = {
428434
jsonrpc: c.jsonrpcVersion,

server/src/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as t from "vscode-languageserver-types";
66
import fs from "fs";
77
import * as os from "os";
88
import { fileURLToPath } from "url";
9-
import { RequestMessage } from "vscode-languageserver";
9+
import { RequestMessage } from "vscode-languageserver-protocol";
1010

1111
let tempFilePrefix = "rescript_format_file_" + process.pid + "_";
1212
let tempFileId = 0;
@@ -105,8 +105,8 @@ export let formatUsingValidBscExePath = (
105105
};
106106

107107
export let runAnalysisAfterSanityCheck = (
108-
msg: RequestMessage,
109-
getArgs: (filePath: string) => Array<string>
108+
filePath: p.DocumentUri,
109+
args: Array<any>
110110
) => {
111111
let binaryPath;
112112
if (fs.existsSync(c.analysisDevPath)) {
@@ -117,12 +117,11 @@ export let runAnalysisAfterSanityCheck = (
117117
return null;
118118
}
119119

120-
let filePath = fileURLToPath(msg.params.textDocument.uri);
121120
let projectRootPath = findProjectRootOfFile(filePath);
122121
if (projectRootPath == null) {
123122
return null;
124123
}
125-
let stdout = childProcess.execFileSync(binaryPath, getArgs(filePath), {
124+
let stdout = childProcess.execFileSync(binaryPath, args, {
126125
cwd: projectRootPath,
127126
});
128127
return JSON.parse(stdout.toString());

0 commit comments

Comments
 (0)