1
- import { Diagnostic , DiagnosticSeverity , DocumentDiagnosticReportKind , FullDocumentDiagnosticReport } from 'lsp-types' ;
1
+ import { CodeAction , CodeActionKind , Diagnostic , DiagnosticSeverity , DocumentDiagnosticReportKind , FullDocumentDiagnosticReport } from 'lsp-types' ;
2
2
import { sysparser , syxparser } from './ast.js' ;
3
3
import { tokenizeSys , tokenizeSyx } from './lexer.js' ;
4
4
import { isCompilerError } from './types.js' ;
@@ -12,23 +12,45 @@ import { readFileSync } from 'fs';
12
12
* @param {string } fileContent Content of the file if it is already fetched.
13
13
* @returns A diagnostic report language servers can use.
14
14
*/
15
- export function createSyntaxScriptDiagnosticReport ( filePath : string , fileContent ?:string ) : FullDocumentDiagnosticReport {
15
+ export function createSyntaxScriptDiagnosticReport ( filePath : string , fileContent ?: string ) : FullDocumentDiagnosticReport {
16
16
const isSyx : boolean = filePath . endsWith ( '.syx' ) ;
17
17
18
- const items :Diagnostic [ ] = [ ] ;
18
+ const items : Diagnostic [ ] = [ ] ;
19
19
20
20
try {
21
21
22
- const content = fileContent ?? readFileSync ( filePath ) . toString ( ) ;
22
+ const content = fileContent ?? readFileSync ( filePath ) . toString ( ) ;
23
23
const tokens = ( isSyx ? tokenizeSyx : tokenizeSys ) ( content ) ;
24
24
( isSyx ? syxparser : sysparser ) . parseTokens ( tokens ) ;
25
25
26
26
} catch ( error ) {
27
27
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
+ } ) ;
29
51
}
30
52
} finally {
31
- return { items, kind :DocumentDiagnosticReportKind . Full } ;
53
+ return { items, kind : DocumentDiagnosticReportKind . Full } ;
32
54
}
33
55
34
56
}
0 commit comments