MCPcopy Create free account
hub / github.com/continuedev/continue / getTreePathAtCursor

Function getTreePathAtCursor

core/autocomplete/util/ast.ts:26–47  ·  view source on GitHub ↗
(
  ast: Parser.Tree,
  cursorIndex: number,
)

Source from the content-addressed store, hash-verified

24}
25
26export async function getTreePathAtCursor(
27 ast: Parser.Tree,
28 cursorIndex: number,
29): Promise<AstPath> {
30 const path = [ast.rootNode];
31 while (path[path.length - 1].childCount > 0) {
32 let foundChild = false;
33 for (const child of path[path.length - 1].children) {
34 if (child.startIndex <= cursorIndex && child.endIndex >= cursorIndex) {
35 path.push(child);
36 foundChild = true;
37 break;
38 }
39 }
40
41 if (!foundChild) {
42 break;
43 }
44 }
45
46 return path;
47}
48
49export async function getScopeAroundRange(
50 range: RangeInFileWithContents,

Callers 3

testRootPathContextFunction · 0.90
initMethod · 0.90
getDefinitionsFromLspFunction · 0.90

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected