Skip to content

Commit 1a485e4

Browse files
committed
Hooks up documentSymbol to the server.
1 parent a9882c0 commit 1a485e4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

server/src/server.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { assert } from "console";
2020
import { fileURLToPath } from "url";
2121
import { ChildProcess } from "child_process";
2222
import { Location } from "vscode-languageserver";
23+
import { SymbolInformation } from "vscode-languageserver";
2324

2425
// https://microsoft.github.io/language-server-protocol/specification#initialize
2526
// According to the spec, there could be requests before the 'initialize' request. Link in comment tells how to handle them.
@@ -297,6 +298,7 @@ function onMessage(msg: m.Message) {
297298
hoverProvider: true,
298299
definitionProvider: true,
299300
referencesProvider: true,
301+
documentSymbolProvider: true,
300302
completionProvider: { triggerCharacters: [".", ">", "@", "~"] },
301303
},
302304
};
@@ -394,6 +396,20 @@ function onMessage(msg: m.Message) {
394396
// error: code and message set in case an exception happens during the definition request.
395397
};
396398
send(definitionResponse);
399+
} else if (msg.method === p.DocumentSymbolRequest.method) {
400+
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
401+
let result:
402+
| SymbolInformation[]
403+
| null = utils.runAnalysisAfterSanityCheck(msg, (filePath) => [
404+
"documentSymbol",
405+
filePath,
406+
]);
407+
let definitionResponse: m.ResponseMessage = {
408+
jsonrpc: c.jsonrpcVersion,
409+
id: msg.id,
410+
result,
411+
};
412+
send(definitionResponse);
397413
} else if (msg.method === p.CompletionRequest.method) {
398414
let code = getOpenedFileContent(msg.params.textDocument.uri);
399415
let tmpname = utils.createFileInTempDir();

0 commit comments

Comments
 (0)