From d061f62f319859e7e608bf24faeaa47c32528231 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Sat, 19 Oct 2024 07:49:50 +0900 Subject: [PATCH] fixup! tweak diagnostics --- src/components/compilerloglib/core.ts | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/components/compilerloglib/core.ts b/src/components/compilerloglib/core.ts index 7220944d..50f6825e 100644 --- a/src/components/compilerloglib/core.ts +++ b/src/components/compilerloglib/core.ts @@ -9,6 +9,7 @@ import type { Completer } from '../../providers/completion.js' import type { Logger } from '../logger.js' import type { Manager } from '../manager.js' import { exists } from '../../lib/lwfs/lwfs.js' +import { toKey } from '../../utils/tokey.js' // Notice that 'Output written on filename.pdf' isn't output in draft mode. @@ -41,6 +42,11 @@ export interface LogEntry { errorPosText?: string } +interface DiagnosticEntry { + uri: vscode.Uri, + diags: vscode.Diagnostic[] +} + export class CompilerLogParser { private readonly latexLogParser: LatexLogParser private readonly bibLogParser: BibLogParser @@ -165,8 +171,13 @@ export class CompilerLogParser { async showCompilerDiagnostics(compilerDiagnostics: vscode.DiagnosticCollection, buildLog: LogEntry[], source: string) { compilerDiagnostics.clear() const newBuildLog = this.tweakLogEntries(buildLog) - const diagsCollection = new Map() + const diagsCollection = new Map() for (const item of newBuildLog) { + const itemUri = await this.findFile(item.file) + if (!itemUri) { + continue + } + const itemKey = toKey(itemUri) let startChar = 0 let endChar = 65535 // Try to compute a more precise position @@ -179,20 +190,14 @@ export class CompilerLogParser { const range = new vscode.Range(new vscode.Position(item.line - 1, startChar), new vscode.Position(item.line - 1, endChar)) const diag = new vscode.Diagnostic(range, item.text, DIAGNOSTIC_SEVERITY[item.type]) diag.source = source - if (diagsCollection.get(item.file) === undefined) { - diagsCollection.set(item.file, []) + if (!diagsCollection.get(itemKey)) { + diagsCollection.set(itemKey, {uri: itemUri, diags: []}) } - diagsCollection.get(item.file)?.push(diag) + diagsCollection.get(itemKey)?.diags.push(diag) } - for (const [file, diags] of diagsCollection) { - const uri = await this.findFile(file) - if (uri) { - compilerDiagnostics.set(uri, diags) - } - -// const uri = vscode.Uri.file(file) -// compilerDiagnostics.set(uri, diagsCollection[file]) + for (const [_, diagsEntry] of diagsCollection) { + compilerDiagnostics.set(diagsEntry.uri, diagsEntry.diags) } }