Skip to content

Commit ac78c6c

Browse files
authored
Merge pull request #139 from rescript-lang/go-to-ref-command
Hook up command to go to references.
2 parents b8143cb + d8a6619 commit ac78c6c

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features:
99
- `->` autocomplete for built-in list, array, string, option types. And for string and array literals.
1010
- Hover on labels in component functions with compiler version 9.1, and labels with type annotation.
1111
- Don't show file path on hover (cleaner).
12+
- Show References.
1213

1314
## 1.0.8
1415

server/src/server.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let projectsFiles: Map<
3939
// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
4040

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

4444
let sendUpdatedDiagnostics = () => {
4545
projectsFiles.forEach(({ filesWithDiagnostics }, projectRootPath) => {
@@ -296,6 +296,7 @@ function onMessage(msg: m.Message) {
296296
documentFormattingProvider: true,
297297
hoverProvider: true,
298298
definitionProvider: true,
299+
referencesProvider: true,
299300
completionProvider: { triggerCharacters: [".", ">", "@", "~"] },
300301
},
301302
};
@@ -359,7 +360,7 @@ function onMessage(msg: m.Message) {
359360
send(hoverResponse);
360361
} else if (msg.method === p.DefinitionRequest.method) {
361362
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
362-
let result: Location | null = utils.runAnalysisAfterSanityCheck(
363+
let result: Location[] | null = utils.runAnalysisAfterSanityCheck(
363364
msg,
364365
(filePath) => [
365366
"definition",
@@ -375,19 +376,37 @@ function onMessage(msg: m.Message) {
375376
// error: code and message set in case an exception happens during the definition request.
376377
};
377378
send(definitionResponse);
379+
} else if (msg.method === p.ReferencesRequest.method) {
380+
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
381+
let result: Location | null = utils.runAnalysisAfterSanityCheck(
382+
msg,
383+
(filePath) => [
384+
"references",
385+
filePath,
386+
msg.params.position.line,
387+
msg.params.position.character,
388+
]
389+
);
390+
let definitionResponse: m.ResponseMessage = {
391+
jsonrpc: c.jsonrpcVersion,
392+
id: msg.id,
393+
result,
394+
// error: code and message set in case an exception happens during the definition request.
395+
};
396+
send(definitionResponse);
378397
} else if (msg.method === p.CompletionRequest.method) {
379398
let code = getOpenedFileContent(msg.params.textDocument.uri);
380399
let tmpname = utils.createFileInTempDir();
381400
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
382401
let result:
383402
| CompletionItem[]
384403
| null = utils.runAnalysisAfterSanityCheck(msg, (filePath) => [
385-
"complete",
386-
filePath,
387-
msg.params.position.line,
388-
msg.params.position.character,
389-
tmpname,
390-
]);
404+
"complete",
405+
filePath,
406+
msg.params.position.line,
407+
msg.params.position.character,
408+
tmpname,
409+
]);
391410
fs.unlink(tmpname, () => null);
392411
let completionResponse: m.ResponseMessage = {
393412
jsonrpc: c.jsonrpcVersion,

0 commit comments

Comments
 (0)