|
1 | | -import { DiagnosticSeverity, DocumentDiagnosticReportKind, FullDocumentDiagnosticReport } from './diagnosticTypes.js'; |
| 1 | +import { Diagnostic, DiagnosticSeverity, DocumentDiagnosticReportKind, FullDocumentDiagnosticReport } from './diagnosticTypes.js'; |
2 | 2 | import { sysparser, syxparser } from './ast.js'; |
3 | 3 | import { tokenizeSys, tokenizeSyx } from './lexer.js'; |
4 | | -import { CompilerError } from './types.js'; |
| 4 | +import { isCompilerError } from './types.js'; |
5 | 5 | import { readFileSync } from 'fs'; |
6 | 6 |
|
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * Creates a diagnostic report from the file path given. |
10 | 10 | * @param {string} filePath Path of the file to create a report. |
| 11 | + * @param {string} fileContent Content of the file if it is already fetched. |
11 | 12 | * @returns A diagnostic report language servers can use. |
12 | 13 | */ |
13 | | -export function createSyntaxScriptDiagnosticReport(filePath: string): FullDocumentDiagnosticReport { |
| 14 | +export function createSyntaxScriptDiagnosticReport(filePath: string,fileContent?:string): FullDocumentDiagnosticReport { |
14 | 15 | const isSyx: boolean = filePath.endsWith('.syx'); |
15 | 16 |
|
| 17 | + const items:Diagnostic[] = [{message:'Base',range:{end:{character:0,line:1},start:{character:0,line:0}},severity:DiagnosticSeverity.Warning,source:'syntax-script'}]; |
| 18 | + |
16 | 19 | try { |
17 | 20 |
|
18 | | - const content = readFileSync(filePath).toString(); |
| 21 | + const content = fileContent??readFileSync(filePath).toString(); |
19 | 22 | const tokens = (isSyx ? tokenizeSyx : tokenizeSys)(content); |
20 | 23 | (isSyx ? syxparser : sysparser).parseTokens(tokens); |
21 | 24 |
|
22 | | - return { kind: DocumentDiagnosticReportKind.Full, items: [] }; |
23 | 25 | } catch (error) { |
24 | | - if (error instanceof CompilerError) { |
25 | | - const compilerError = error as CompilerError; |
26 | | - return { |
27 | | - kind: DocumentDiagnosticReportKind.Full, items: [ |
28 | | - { message: compilerError.message, range: compilerError.range, severity: DiagnosticSeverity.Error, source: 'syntax-script' } |
29 | | - ] |
30 | | - }; |
| 26 | + if (isCompilerError(error)) { |
| 27 | + items.push({ message: error.message, range: error.range, severity: DiagnosticSeverity.Error, source: 'syntax-script' }); |
31 | 28 | } |
| 29 | + } finally { |
| 30 | + return {items,kind:DocumentDiagnosticReportKind.Full}; |
32 | 31 | } |
33 | 32 |
|
34 | 33 | } |
0 commit comments