Skip to content

Commit

Permalink
fixup! tweak diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Oct 18, 2024
1 parent 7347d15 commit d061f62
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/components/compilerloglib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<string, vscode.Diagnostic[]>()
const diagsCollection = new Map<string, DiagnosticEntry>()
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
Expand All @@ -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)
}
}

Expand Down

0 comments on commit d061f62

Please sign in to comment.