diff --git a/src/lang/queryAst.ts b/src/lang/queryAst.ts index 70a5553d1e..2c20682e26 100644 --- a/src/lang/queryAst.ts +++ b/src/lang/queryAst.ts @@ -905,6 +905,7 @@ export function isCursorInFunctionDefinition( ast: Node, selectionRanges: Selection ): boolean { + if (ast.body.length === 0) return false if (!selectionRanges?.codeRef?.pathToNode) return false const node = getNodeFromPath( ast, diff --git a/src/lib/operations.ts b/src/lib/operations.ts index a1f9c067c1..0b0829d27a 100644 --- a/src/lib/operations.ts +++ b/src/lib/operations.ts @@ -1349,6 +1349,11 @@ export function getOperationVariableName( ) { return undefined } + if (program.body.length === 0) { + // No program body, no variable name + return undefined + } + // Find the AST node. const pathToNode = pathToNodeFromRustNodePath(op.nodePath) if (pathToNode.length === 0) {