File tree Expand file tree Collapse file tree 2 files changed +29
-15
lines changed Expand file tree Collapse file tree 2 files changed +29
-15
lines changed Original file line number Diff line number Diff line change @@ -1046,8 +1046,22 @@ describe('server', () => {
1046
1046
line : 2 ,
1047
1047
character : 3 ,
1048
1048
} )
1049
- expect ( result2 ) . toBeDefined ( )
1050
- expect ( ( result2 as any ) ?. contents . value ) . toBeUndefined ( )
1049
+ expect ( result2 ) . toEqual ( null )
1050
+ } )
1051
+
1052
+ it ( 'responds with documentation even if parsing fails' , async ( ) => {
1053
+ const result = await getHoverResult ( FIXTURE_URI . MISSING_NODE2 , {
1054
+ // sleep
1055
+ line : 12 ,
1056
+ character : 4 ,
1057
+ } )
1058
+
1059
+ expect ( result ) . toEqual ( {
1060
+ contents : {
1061
+ kind : 'markdown' ,
1062
+ value : expect . stringContaining ( 'suspends execution' ) ,
1063
+ } ,
1064
+ } )
1051
1065
} )
1052
1066
1053
1067
it . skip ( 'returns documentation from explainshell' , async ( ) => {
Original file line number Diff line number Diff line change @@ -154,20 +154,20 @@ export function getLocalDeclarations({
154
154
node . type === 'program'
155
155
? node
156
156
: TreeSitterUtil . findParent ( node , ( p ) => p . type === 'program' )
157
- if ( ! rootNode ) {
158
- throw new Error ( 'did not find root node' )
159
- }
160
157
161
- Object . entries (
162
- getAllGlobalVariableDeclarations ( {
163
- rootNode,
164
- uri,
165
- } ) ,
166
- ) . map ( ( [ name , symbols ] ) => {
167
- if ( ! declarations [ name ] ) {
168
- declarations [ name ] = symbols
169
- }
170
- } )
158
+ if ( rootNode ) {
159
+ // In case of parsing errors, the root node might not be found
160
+ Object . entries (
161
+ getAllGlobalVariableDeclarations ( {
162
+ rootNode,
163
+ uri,
164
+ } ) ,
165
+ ) . map ( ( [ name , symbols ] ) => {
166
+ if ( ! declarations [ name ] ) {
167
+ declarations [ name ] = symbols
168
+ }
169
+ } )
170
+ }
171
171
}
172
172
173
173
return declarations
You can’t perform that action at this time.
0 commit comments