From a25966932f14c0a7452484ebbeb71d081fc6497e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Rogn=C3=A5s?= Date: Mon, 2 Sep 2024 19:02:49 +0200 Subject: [PATCH] Update server.ts --- server/src/server.ts | 66 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 012a108..90153dd 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -97,7 +97,7 @@ function findControlRecordsInText(text: string): RegExpExecArray[] { .filter(line => !line.trim().startsWith(';')) .join('\n'); - while ((match = controlRecordPattern.exec(text)) !== null) { + while ((match = controlRecordPattern.exec(filteredText)) !== null) { matches.push(match); } @@ -143,38 +143,42 @@ function createDiagnosticForControlRecord(match: RegExpExecArray, textDocument: // Implement Hover logic connection.onHover(({ textDocument, position }) => { - const uri = textDocument.uri; - const document = documents.get(uri); - if (!document) { - return null; - } - - const text = document.getText(); - const offset = document.offsetAt(position); - const controlRecordPattern = /\$[A-Z]+\b/g; - let match: RegExpExecArray | null; - - while ((match = controlRecordPattern.exec(text)) !== null) { - const start = match.index; - const end = match.index + match[0].length; - if (start <= offset && offset <= end) { - const fullControlRecord = getFullControlRecord(match[0]); // Assuming you have this function - const hoverInfo: MarkupContent = { - kind: MarkupKind.Markdown, - value: getHoverInfoForControlRecord(match[0], fullControlRecord) - }; - - return { - contents: hoverInfo, - range: { - start: document.positionAt(start), - end: document.positionAt(end) - } - } as Hover; + try { + const uri = textDocument.uri; + const document = documents.get(uri); + if (!document) { + connection.console.error(`Document not found: ${uri}`); + return null; } + + const text = document.getText(); + const offset = document.offsetAt(position); + const controlRecordPattern = /\$[A-Z]+\b/g; + let match: RegExpExecArray | null; + + while ((match = controlRecordPattern.exec(text)) !== null) { + const start = match.index; + const end = match.index + match[0].length; + if (start <= offset && offset <= end) { + const fullControlRecord = getFullControlRecord(match[0]); // Assuming you have this function + const hoverInfo: MarkupContent = { + kind: MarkupKind.Markdown, + value: getHoverInfoForControlRecord(match[0], fullControlRecord) + }; + + return { + contents: hoverInfo, + range: { + start: document.positionAt(start), + end: document.positionAt(end) + } + } as Hover; + } + } + } catch (error) { + connection.console.error(`Error during onHover: ${(error as Error).message}`); + return null; } - - return null; }); // Implement CodeAction logic