( filepath: string, fileContents: string, )
| 6 | export type AstPath = Parser.SyntaxNode[]; |
| 7 | |
| 8 | export async function getAst( |
| 9 | filepath: string, |
| 10 | fileContents: string, |
| 11 | ): Promise<Parser.Tree | undefined> { |
| 12 | const parser = await getParserForFile(filepath); |
| 13 | |
| 14 | if (!parser) { |
| 15 | return undefined; |
| 16 | } |
| 17 | |
| 18 | try { |
| 19 | const ast = parser.parse(fileContents); |
| 20 | return ast; |
| 21 | } catch (e) { |
| 22 | return undefined; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | export async function getTreePathAtCursor( |
| 27 | ast: Parser.Tree, |
no test coverage detected