Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a522ff6

Browse files
committedMay 20, 2025
Partially remove chokidar, setting up client file watching
1 parent 583c63a commit a522ff6

File tree

4 files changed

+76
-887
lines changed

4 files changed

+76
-887
lines changed
 

‎package-lock.json

Lines changed: 1 addition & 576 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎server/package-lock.json

Lines changed: 35 additions & 308 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
"url": "https://github.com/rescript-lang/rescript-vscode/issues"
3131
},
3232
"dependencies": {
33-
"chokidar": "^3.5.1",
3433
"semver": "^7.7.2",
3534
"vscode-jsonrpc": "^8.0.1",
36-
"vscode-languageserver": "^8.0.1",
35+
"vscode-languageserver": "^9.0.1",
3736
"vscode-languageserver-protocol": "^3.17.1"
3837
}
3938
}

‎server/src/server.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as lookup from "./lookup";
1919
import * as utils from "./utils";
2020
import * as codeActions from "./codeActions";
2121
import * as c from "./constants";
22-
import * as chokidar from "chokidar";
2322
import { assert } from "console";
2423
import { fileURLToPath } from "url";
2524
import { WorkspaceEdit } from "vscode-languageserver";
@@ -239,6 +238,7 @@ let compilerLogsWatcher = chokidar
239238
}
240239
}
241240
});
241+
242242
let stopWatchingCompilerLog = () => {
243243
// TODO: cleanup of compilerLogs?
244244
compilerLogsWatcher.close();
@@ -1051,6 +1051,44 @@ async function onMessage(msg: p.Message) {
10511051
} else {
10521052
process.exit(1);
10531053
}
1054+
} else if (msg.method === "initialized") {
1055+
/*
1056+
The initialized notification is sent from the client to the server after the client received the result of the initialize request
1057+
but before the client is sending any other request or notification to the server.
1058+
The server can use the initialized notification, for example, to dynamically register capabilities.
1059+
1060+
We use this to register the file watchers for the project.
1061+
The client can watch files for us and send us events via the `workspace/didChangeWatchedFiles`
1062+
*/
1063+
const watchers =
1064+
Array.from(projectsFiles.keys()).flatMap(projectRootPath => [
1065+
{
1066+
globPattern: path.join(projectRootPath, c.compilerLogPartialPath),
1067+
kind: p.WatchKind.Change | p.WatchKind.Create,
1068+
},
1069+
{
1070+
globPattern: path.join(projectRootPath, c.buildNinjaPartialPath),
1071+
kind: p.WatchKind.Change | p.WatchKind.Create,
1072+
},
1073+
])
1074+
const registrationParams : p.RegistrationParams = {
1075+
registrations:[
1076+
{
1077+
id: "rescript_file_watcher",
1078+
method: p.DidChangeWatchedFilesNotification.method,
1079+
registerOptions: {
1080+
watchers
1081+
}
1082+
}
1083+
]
1084+
};
1085+
const req: p.RequestMessage = {
1086+
jsonrpc: c.jsonrpcVersion,
1087+
id: serverSentRequestIdCounter++,
1088+
method: p.RegistrationRequest.method,
1089+
params: registrationParams,
1090+
};
1091+
send(req);
10541092
} else if (msg.method === DidOpenTextDocumentNotification.method) {
10551093
let params = msg.params as p.DidOpenTextDocumentParams;
10561094
await openedFile(params.textDocument.uri, params.textDocument.text);

0 commit comments

Comments
 (0)
Please sign in to comment.