Skip to content

Parse additioanal error/warning info from lobster #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions dev/lsp/src/lobster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exec } from 'child_process';
import { Diagnostic, DiagnosticSeverity, integer, uinteger } from 'vscode-languageserver';
import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, integer, uinteger } from 'vscode-languageserver';
import { LobsterSettings } from './lsp';
import { Location } from 'vscode';

export interface LobsterLocation {
file: string,
Expand Down Expand Up @@ -72,17 +73,46 @@ export async function parseLobster(
return []; // TODO make "can't open file" a normal error instead of an unformatted error
}

const regex = /^(.*)\((\d+)\): (warning|error): (.*)/g;
let match;
const regex = /^(.*?)\((\d+)\): (warning|error): (.*)((\s+ .*)*)/gm;
const regexInner = /^\s*?in (.*)\((\d+)\):.*/gm;
let match, innerMatch;
const output: Diagnostic[] = [];

function scanLine(at: string, thisLine: integer, relInfo: DiagnosticRelatedInformation[]): integer | undefined {
var result: integer | undefined = undefined;
if (file.endsWith(at)) {
result = thisLine;
} else {
//Push link to related source from another file
relInfo.push({
message: "source",
location: {
uri: settings.imports[0] + "/" + at,
range: {
start: { line: thisLine, character: 0 },
end: { line: thisLine, character: uinteger.MAX_VALUE }
}
}
});
}
return result;
}


while ((match = regex.exec(input))) {
const at = match[1];
if (!file.endsWith(at)) return [];
const relInfo: DiagnosticRelatedInformation[] = [];
var line = scanLine(match[1], parseInt(match[2]) - 1, relInfo);
let innerMsg = match[5];
if (innerMsg && !line) {
while ((innerMatch = regexInner.exec(innerMsg))) {
line ||= scanLine(innerMatch[1], parseInt(innerMatch[2]) - 1, relInfo);
}
}

line = line || uinteger.MAX_VALUE;

const line = parseInt(match[2]) - 1; // Its zero based
const messageType = match[3].trim();
const message = match[4].trim();
const message = match[4].trim() + (innerMsg ? innerMsg.replace(regexInner, "") : "");

const severity = messageType == "warning" ?
DiagnosticSeverity.Warning :
Expand All @@ -93,6 +123,7 @@ export async function parseLobster(
start: { line, character: 0 },
end: { line, character: uinteger.MAX_VALUE }
},
relatedInformation: relInfo.length ? relInfo : undefined,
message,
severity
});
Expand Down
Loading