fix path to query
This commit is contained in:
parent
4e97c922d5
commit
97788f2b9d
1 changed files with 57 additions and 12 deletions
|
|
@ -66,12 +66,7 @@ export async function extractTopLevelDecls(currentFile: string, givenParser?: Pa
|
|||
|
||||
const query = await getQueryForFile(
|
||||
currentFile,
|
||||
path.join(
|
||||
__dirname,
|
||||
"queries",
|
||||
"relevant-headers-queries",
|
||||
`${language}-get-toplevel-headers.scm`
|
||||
)
|
||||
`static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm`
|
||||
);
|
||||
if (!query) {
|
||||
throw new Error(
|
||||
|
|
@ -95,12 +90,7 @@ export async function extractTopLevelDeclsWithFormatting(currentFile: string, gi
|
|||
|
||||
const query = await getQueryForFile(
|
||||
currentFile,
|
||||
path.join(
|
||||
__dirname,
|
||||
"queries",
|
||||
"relevant-headers-queries",
|
||||
`${language}-get-toplevel-headers.scm`
|
||||
)
|
||||
`static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm`
|
||||
);
|
||||
if (!query) {
|
||||
throw new Error(
|
||||
|
|
@ -162,3 +152,58 @@ export async function extractTopLevelDeclsWithFormatting(currentFile: string, gi
|
|||
|
||||
return results;
|
||||
}
|
||||
|
||||
export function extractFunctionTypeFromDecl(match: Parser.QueryMatch): string {
|
||||
let paramsNode: Parser.SyntaxNode | undefined = undefined;
|
||||
let returnNode: Parser.SyntaxNode | undefined = undefined;
|
||||
|
||||
for (const capture of match.captures) {
|
||||
if (capture.name === "top.fn.param.type") {
|
||||
paramsNode = capture.node;
|
||||
} else if (capture.name === "top.fn.type") {
|
||||
returnNode = capture.node;
|
||||
}
|
||||
}
|
||||
|
||||
if (!paramsNode) {
|
||||
console.error(`extractFunctionTypeFromDecl: ${paramsNode} not found`);
|
||||
throw new Error(`extractFunctionTypeFromDecl: ${paramsNode} not found`);
|
||||
}
|
||||
|
||||
if (!returnNode) {
|
||||
console.error(`extractFunctionTypeFromDecl: ${returnNode} not found`);
|
||||
throw new Error(`extractFunctionTypeFromDecl: ${returnNode} not found`);
|
||||
}
|
||||
|
||||
return `(${paramsNode!.text}) => ${returnNode!.text}`;
|
||||
}
|
||||
|
||||
export function unwrapToBaseType(node: Parser.SyntaxNode): Parser.SyntaxNode {
|
||||
if (
|
||||
[
|
||||
"function_type",
|
||||
"tuple_type",
|
||||
"type_identifier",
|
||||
"predefined_type",
|
||||
].includes(node.type)
|
||||
) {
|
||||
return node;
|
||||
}
|
||||
|
||||
for (const child of node.namedChildren) {
|
||||
const unwrapped = unwrapToBaseType(child!);
|
||||
if (
|
||||
unwrapped !== child ||
|
||||
[
|
||||
"function_type",
|
||||
"tuple_type",
|
||||
"type_identifier",
|
||||
"predefined_type",
|
||||
].includes(unwrapped.type)
|
||||
) {
|
||||
return unwrapped;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue