( ast: Parser.Tree, cursorIndex: number, )
| 24 | } |
| 25 | |
| 26 | export 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 | |
| 49 | export async function getScopeAroundRange( |
| 50 | range: RangeInFileWithContents, |
no test coverage detected