Skip to content

Commit 0bd2212

Browse files
committed
Parse in rootNode instead of searching for it
1 parent 53085f6 commit 0bd2212

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

server/src/analyser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ export default class Analyzer {
578578

579579
const localDeclarations = getLocalDeclarations({
580580
node,
581+
rootNode: analyzedDocument.tree.rootNode,
581582
uri,
582583
})
583584

server/src/util/declarations.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ export function getAllDeclarationsInTree({
9494
*/
9595
export function getLocalDeclarations({
9696
node,
97+
rootNode,
9798
uri,
9899
}: {
99100
node: Parser.SyntaxNode | null
101+
rootNode: Parser.SyntaxNode
100102
uri: string
101103
}): Declarations {
102104
const declarations: Declarations = {}
@@ -149,26 +151,16 @@ export function getLocalDeclarations({
149151
walk(node)
150152

151153
// Top down traversal to add missing global variables from within functions
152-
if (node) {
153-
const rootNode =
154-
node.type === 'program'
155-
? node
156-
: TreeSitterUtil.findParent(node, (p) => p.type === 'program')
157-
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-
})
154+
Object.entries(
155+
getAllGlobalVariableDeclarations({
156+
rootNode,
157+
uri,
158+
}),
159+
).map(([name, symbols]) => {
160+
if (!declarations[name]) {
161+
declarations[name] = symbols
170162
}
171-
}
163+
})
172164

173165
return declarations
174166
}

0 commit comments

Comments
 (0)