mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
fix(tree-sitter-typescript-tags): correct tree-sitter queries
Add a new test case for typescript. Fix queries for typescript.
This commit is contained in:
parent
edd66f7fe6
commit
19c8fa389f
2 changed files with 67 additions and 14 deletions
|
@ -1,23 +1,17 @@
|
||||||
(function_signature
|
(function_declaration
|
||||||
name: (identifier) @name.definition.function) @definition.function
|
name: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
(method_signature
|
(method_definition
|
||||||
name: (property_identifier) @name.definition.method) @definition.method
|
name: (property_identifier) @name.definition.method) @definition.method
|
||||||
|
|
||||||
(abstract_method_signature
|
(class_declaration
|
||||||
name: (property_identifier) @name.definition.method) @definition.method
|
|
||||||
|
|
||||||
(abstract_class_declaration
|
|
||||||
name: (type_identifier) @name.definition.class) @definition.class
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
(module
|
|
||||||
name: (identifier) @name.definition.module) @definition.module
|
|
||||||
|
|
||||||
(interface_declaration
|
(interface_declaration
|
||||||
name: (type_identifier) @name.definition.interface) @definition.interface
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
(type_annotation
|
(type_alias_declaration
|
||||||
(type_identifier) @name.reference.type) @reference.type
|
name: (type_identifier) @name.definition.type) @definition.type
|
||||||
|
|
||||||
(new_expression
|
(enum_declaration
|
||||||
constructor: (identifier) @name.reference.class) @reference.class
|
name: (identifier) @name.definition.enum) @definition.enum
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
from collections import defaultdict
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
import networkx as nx
|
||||||
|
|
||||||
from aider.dump import dump # noqa: F401
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.io import InputOutput
|
from aider.io import InputOutput
|
||||||
from aider.repomap import RepoMap
|
from aider.repomap import RepoMap
|
||||||
|
from aider import models
|
||||||
from aider.utils import IgnorantTemporaryDirectory
|
from aider.utils import IgnorantTemporaryDirectory
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,5 +154,60 @@ print(my_function(3, 4))
|
||||||
del repo_map
|
del repo_map
|
||||||
|
|
||||||
|
|
||||||
|
class TestRepoMapTypescript(unittest.TestCase):
|
||||||
|
def test_get_repo_map_typescript(self):
|
||||||
|
# Create a temporary directory with a sample TypeScript file
|
||||||
|
test_file_ts = "test_file.ts"
|
||||||
|
file_content_ts = """\
|
||||||
|
interface IMyInterface {
|
||||||
|
someMethod(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExampleType = {
|
||||||
|
key: string;
|
||||||
|
value: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Status {
|
||||||
|
New,
|
||||||
|
InProgress,
|
||||||
|
Completed,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MyClass {
|
||||||
|
constructor(public value: number) {}
|
||||||
|
|
||||||
|
add(input: number): number {
|
||||||
|
return this.value + input;
|
||||||
|
return this.value + input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function myFunction(input: number): number {
|
||||||
|
return input * 2;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
with IgnorantTemporaryDirectory() as temp_dir:
|
||||||
|
with open(os.path.join(temp_dir, test_file_ts), "w") as f:
|
||||||
|
f.write(file_content_ts)
|
||||||
|
|
||||||
|
io = InputOutput()
|
||||||
|
repo_map = RepoMap(root=temp_dir, io=io)
|
||||||
|
other_files = [os.path.join(temp_dir, test_file_ts)]
|
||||||
|
result = repo_map.get_repo_map([], other_files)
|
||||||
|
|
||||||
|
# Check if the result contains the expected tags map with TypeScript identifiers
|
||||||
|
self.assertIn("test_file.ts", result)
|
||||||
|
self.assertIn("IMyInterface", result)
|
||||||
|
self.assertIn("ExampleType", result)
|
||||||
|
self.assertIn("Status", result)
|
||||||
|
self.assertIn("MyClass", result)
|
||||||
|
self.assertIn("add", result)
|
||||||
|
self.assertIn("myFunction", result)
|
||||||
|
|
||||||
|
# close the open cache files, so Windows won't error
|
||||||
|
del repo_map
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue