Skip to content

Commit a489934

Browse files
committed
add a test action to data
1 parent 2b276a7 commit a489934

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/diagnostic.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Diagnostic,DiagnosticSeverity,DocumentDiagnosticReportKind,FullDocumentDiagnosticReport} from 'lsp-types';
1+
import { CodeAction, CodeActionKind, Diagnostic, DiagnosticSeverity, DocumentDiagnosticReportKind, FullDocumentDiagnosticReport } from 'lsp-types';
22
import { sysparser, syxparser } from './ast.js';
33
import { tokenizeSys, tokenizeSyx } from './lexer.js';
44
import { isCompilerError } from './types.js';
@@ -12,23 +12,45 @@ import { readFileSync } from 'fs';
1212
* @param {string} fileContent Content of the file if it is already fetched.
1313
* @returns A diagnostic report language servers can use.
1414
*/
15-
export function createSyntaxScriptDiagnosticReport(filePath: string,fileContent?:string): FullDocumentDiagnosticReport {
15+
export function createSyntaxScriptDiagnosticReport(filePath: string, fileContent?: string): FullDocumentDiagnosticReport {
1616
const isSyx: boolean = filePath.endsWith('.syx');
1717

18-
const items:Diagnostic[] = [];
18+
const items: Diagnostic[] = [];
1919

2020
try {
2121

22-
const content = fileContent??readFileSync(filePath).toString();
22+
const content = fileContent ?? readFileSync(filePath).toString();
2323
const tokens = (isSyx ? tokenizeSyx : tokenizeSys)(content);
2424
(isSyx ? syxparser : sysparser).parseTokens(tokens);
2525

2626
} catch (error) {
2727
if (isCompilerError(error)) {
28-
items.push({ message: error.message, range: error.range, severity: DiagnosticSeverity.Error, source: 'syntax-script' });
28+
items.push({
29+
message: error.message,
30+
range: error.range,
31+
severity: DiagnosticSeverity.Error,
32+
source: 'syntax-script',
33+
data: [
34+
{
35+
title: 'Test Action',
36+
kind: CodeActionKind.QuickFix,
37+
edit: {
38+
changes: {
39+
[filePath]: [
40+
{
41+
range:error.range,
42+
newText:'test'
43+
}
44+
]
45+
}
46+
}
47+
48+
}
49+
] as CodeAction[]
50+
});
2951
}
3052
} finally {
31-
return {items,kind:DocumentDiagnosticReportKind.Full};
53+
return { items, kind: DocumentDiagnosticReportKind.Full };
3254
}
3355

3456
}

0 commit comments

Comments
 (0)