File tree Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -46,12 +46,30 @@ describe('analyze', () => {
46
46
expect ( loggerWarn ) . not . toHaveBeenCalled ( )
47
47
} )
48
48
49
- it ( 'parses files with a missing node ' , ( ) => {
49
+ it ( 'parses files with a missing nodes and return relevant diagnostics ' , ( ) => {
50
50
const diagnostics = analyzer . analyze ( {
51
51
uri : CURRENT_URI ,
52
52
document : FIXTURE_DOCUMENT . MISSING_NODE ,
53
53
} )
54
- expect ( diagnostics ) . toEqual ( [ ] )
54
+ expect ( diagnostics ) . toMatchInlineSnapshot ( `
55
+ Array [
56
+ Object {
57
+ "message": "Syntax error: \\"fi\\" missing",
58
+ "range": Object {
59
+ "end": Object {
60
+ "character": 0,
61
+ "line": 12,
62
+ },
63
+ "start": Object {
64
+ "character": 0,
65
+ "line": 12,
66
+ },
67
+ },
68
+ "severity": 2,
69
+ "source": "bash-language-server",
70
+ },
71
+ ]
72
+ ` )
55
73
expect ( loggerWarn ) . toHaveBeenCalledWith (
56
74
'Error while parsing dummy-uri.sh: syntax error' ,
57
75
)
Original file line number Diff line number Diff line change @@ -116,7 +116,11 @@ export default class Analyzer {
116
116
logger . warn ( `Error while parsing ${ uri } : syntax error` )
117
117
}
118
118
119
- return diagnostics
119
+ const missingNodesDiagnostics = TreeSitterUtil . getDiagnosticsForMissingNodes (
120
+ tree . rootNode ,
121
+ )
122
+
123
+ return diagnostics . concat ( missingNodesDiagnostics )
120
124
}
121
125
122
126
/**
Original file line number Diff line number Diff line change 1
- import { Range } from 'vscode-languageserver/node'
1
+ import { Diagnostic , DiagnosticSeverity , Range } from 'vscode-languageserver/node'
2
2
import { SyntaxNode } from 'web-tree-sitter'
3
3
4
4
/**
@@ -56,3 +56,24 @@ export function findParent(
56
56
}
57
57
return null
58
58
}
59
+
60
+ export function getDiagnosticsForMissingNodes ( node : SyntaxNode ) {
61
+ const diagnostics : Diagnostic [ ] = [ ]
62
+
63
+ forEach ( node , ( node ) => {
64
+ if ( node . isMissing ( ) ) {
65
+ diagnostics . push (
66
+ Diagnostic . create (
67
+ range ( node ) ,
68
+ `Syntax error: "${ node . type } " missing` ,
69
+ DiagnosticSeverity . Warning ,
70
+ undefined ,
71
+ 'bash-language-server' ,
72
+ ) ,
73
+ )
74
+ }
75
+ return node . hasError ( )
76
+ } )
77
+
78
+ return diagnostics
79
+ }
You can’t perform that action at this time.
0 commit comments