hierarchical context support for more languages
This commit is contained in:
parent
196992c6bd
commit
0d70cd7420
9 changed files with 82 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
(function_definition
|
||||
(function_declarator
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(type_identifier) @a
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(function_definition
|
||||
(type_identifier) @b
|
||||
)
|
||||
|
|
@ -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)$")
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
; Method parameters
|
||||
(method_declaration
|
||||
(formal_parameters
|
||||
(formal_parameter
|
||||
(type_identifier) @a
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
; Return type
|
||||
(method_declaration
|
||||
(type_identifier) @b
|
||||
)
|
||||
9
extensions/vscode/tree-sitter/import-queries/cpp.scm
Normal file
9
extensions/vscode/tree-sitter/import-queries/cpp.scm
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(using_declaration
|
||||
(qualified_identifier
|
||||
(identifier) @a))
|
||||
|
||||
(namespace_alias_definition
|
||||
(nested_namespace_specifier) @b)
|
||||
|
||||
(preproc_include
|
||||
(system_lib_string) @c)
|
||||
3
extensions/vscode/tree-sitter/import-queries/java.scm
Normal file
3
extensions/vscode/tree-sitter/import-queries/java.scm
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(import_declaration
|
||||
(scoped_identifier
|
||||
(identifier) @import))
|
||||
8
extensions/vscode/tree-sitter/import-queries/python.scm
Normal file
8
extensions/vscode/tree-sitter/import-queries/python.scm
Normal 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 ))
|
||||
Loading…
Add table
Reference in a new issue