From 248c9ea686b0e06fbd1a7f0a49141e5a58bb8f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Rogn=C3=A5s?= Date: Fri, 6 Oct 2023 23:39:41 +0200 Subject: [PATCH] Update server.ts --- server/src/server.ts | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/server/src/server.ts b/server/src/server.ts index ce6719e..012a108 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -4,12 +4,15 @@ import { CodeActionKind, Diagnostic, DiagnosticSeverity, + DocumentSymbolParams, Hover, InitializeParams, InitializeResult, MarkupContent, MarkupKind, ProposedFeatures, + SymbolInformation, + SymbolKind, TextDocuments, TextDocumentSyncKind } from 'vscode-languageserver/node'; @@ -40,7 +43,8 @@ connection.onInitialize((params: InitializeParams): InitializeResult => { capabilities: { textDocumentSync: TextDocumentSyncKind.Full, hoverProvider: true, - codeActionProvider: true + codeActionProvider: true, + documentSymbolProvider: true } }; }); @@ -211,6 +215,38 @@ connection.onCodeAction(({ textDocument, range, context }) => { return codeActions; }); +// Implement Document Symbol logic +connection.onDocumentSymbol((params: DocumentSymbolParams) => { + const uri = params.textDocument.uri; + const document = documents.get(uri); + if (!document) { + return null; + } + + const text = document.getText(); + const controlRecords = findControlRecordsInText(text); + const symbols: SymbolInformation[] = []; + + for (const match of controlRecords) { + const fullControlRecord = getFullControlRecord(match[0]); + const symbolInfo: SymbolInformation = { + name: fullControlRecord, + kind: SymbolKind.Module, + location: { + uri: uri, + range: { + start: document.positionAt(match.index), + end: document.positionAt(match.index + match[0].length) + } + } + }; + + symbols.push(symbolInfo); + } + + return symbols; +}); + async function validateNMTRANDocument(textDocument: TextDocument): Promise { const text = textDocument.getText(); const controlRecords = findControlRecordsInText(text);