Skip to content

Commit fca68b5

Browse files
committed
Hook up command to go to references.
1 parent dd06da7 commit fca68b5

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
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

package-lock.json

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

server/src/server.ts

Lines changed: 26 additions & 7 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
};
@@ -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)