Skip to content

Commit

Permalink
Update server.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
vrognas committed Oct 6, 2023
1 parent 87f98bf commit 248c9ea
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import {
CodeActionKind,
Diagnostic,
DiagnosticSeverity,
DocumentSymbolParams,
Hover,
InitializeParams,
InitializeResult,
MarkupContent,
MarkupKind,
ProposedFeatures,
SymbolInformation,
SymbolKind,
TextDocuments,
TextDocumentSyncKind
} from 'vscode-languageserver/node';
Expand Down Expand Up @@ -40,7 +43,8 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
capabilities: {
textDocumentSync: TextDocumentSyncKind.Full,
hoverProvider: true,
codeActionProvider: true
codeActionProvider: true,
documentSymbolProvider: true
}
};
});
Expand Down Expand Up @@ -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<void> {
const text = textDocument.getText();
const controlRecords = findControlRecordsInText(text);
Expand Down

0 comments on commit 248c9ea

Please sign in to comment.