hierarchical context support for more languages

This commit is contained in:
Nate Sesti 2024-06-29 20:40:01 -07:00
parent 196992c6bd
commit 0d70cd7420
9 changed files with 82 additions and 1 deletions

View file

@ -61,6 +61,12 @@ export class HierarchicalContextService {
case "method_definition":
query = await getQueryForFile(filepath, TSQueryType.MethodDefinition);
break;
case "function_definition":
query = await getQueryForFile(filepath, TSQueryType.FunctionDefinition);
break;
case "method_declaration":
query = await getQueryForFile(filepath, TSQueryType.MethodDeclaration);
break;
default:
break;
}

View file

@ -123,6 +123,8 @@ export enum TSQueryType {
// Used in HierarchicalContextService.ts
FunctionDeclaration = "hierarchical-context-queries/function_declaration",
MethodDefinition = "hierarchical-context-queries/method_definition",
FunctionDefinition = "hierarchical-context-queries/function_definition",
MethodDeclaration = "hierarchical-context-queries/method_declaration",
}
export async function getQueryForFile(

View file

@ -1,5 +1,15 @@
def main():
from typing import List
Vector = List[float]
def main(a: Vector):
print("Hello Nested!")
class MyClass:
def test(a: Vector) -> Vector:
return a
raise Exception("This is an error")

View file

@ -0,0 +1,13 @@
(function_definition
(function_declarator
(parameter_list
(parameter_declaration
(type_identifier) @a
)
)
)
)
(function_definition
(type_identifier) @b
)

View file

@ -0,0 +1,17 @@
(
(function_definition
(parameters
(_
(type) @a
(#not-match? @a "^(str|int|float|bool|list|dict|tuple)$")
)
)
)
)
(
(function_definition
(type) @b
(#not-match? @b "^(str|int|float|bool|list|dict|tuple)$")
)
)

View file

@ -0,0 +1,13 @@
; Method parameters
(method_declaration
(formal_parameters
(formal_parameter
(type_identifier) @a
)
)
)
; Return type
(method_declaration
(type_identifier) @b
)

View file

@ -0,0 +1,9 @@
(using_declaration
(qualified_identifier
(identifier) @a))
(namespace_alias_definition
(nested_namespace_specifier) @b)
(preproc_include
(system_lib_string) @c)

View file

@ -0,0 +1,3 @@
(import_declaration
(scoped_identifier
(identifier) @import))

View file

@ -0,0 +1,8 @@
(import_from_statement
(dotted_name) ; skip the first (this is the module)
(dotted_name
(identifier) @importa))
(import_statement
(dotted_name
(identifier) @importb ))