1
+ import * as vscode from 'vscode'
1
2
import * as path from 'path'
2
3
import * as workerpool from 'workerpool'
3
4
import type * as Ast from '@unified-latex/unified-latex-types'
@@ -12,6 +13,7 @@ import { latexLogParser } from './parser/latexlog'
12
13
import { toString } from '../../../resources/unified.js'
13
14
14
15
const logger = lw . log ( 'Parser' )
16
+ const bibDiagnostics = vscode . languages . createDiagnosticCollection ( 'BibTeX' )
15
17
16
18
export const parser = {
17
19
bib,
@@ -42,12 +44,22 @@ async function reset() {
42
44
return ( await proxy ) . reset ( getMacroDefs ( ) , getEnvDefs ( ) )
43
45
}
44
46
45
- async function bib ( s : string , options ?: bibtexParser . ParserOptions ) : Promise < bibtexParser . BibtexAst | undefined > {
46
- const ast = await ( await proxy ) . parseBibTeX ( s , options )
47
- if ( ast instanceof Error ) {
48
- logger . logError ( 'Error when parsing bib file.' , ast )
47
+ async function bib ( uri : vscode . Uri , s : string ) : Promise < bibtexParser . BibtexAst | undefined > {
48
+ const ast = await ( await proxy ) . parseBibTeX ( s )
49
+ if ( typeof ast === 'string' ) {
50
+ const err = JSON . parse ( ast ) as bibtexParser . SyntaxError
51
+ logger . log ( `Error when parsing bib file: found ${ err . found } from ${ err . location . start . line } :${ err . location . start . column } to ${ err . location . end . line } :${ err . location . end . column } .` )
52
+ bibDiagnostics . set ( uri , [ new vscode . Diagnostic (
53
+ new vscode . Range (
54
+ new vscode . Position ( err . location . start . line - 1 , err . location . start . column - 1 ) ,
55
+ new vscode . Position ( err . location . end . line - 1 , err . location . end . column - 1 )
56
+ ) ,
57
+ `A BibTeX parsing error occurred. "${ err . found } " is unexpected here. No BibTeX entries will be available.` ,
58
+ vscode . DiagnosticSeverity . Warning
59
+ ) ] )
49
60
return undefined
50
61
} else {
62
+ bibDiagnostics . set ( uri , [ ] )
51
63
return ast
52
64
}
53
65
}
0 commit comments