diff --git a/core/autocomplete/context/root-path-context/test/files/generators.ts b/core/autocomplete/context/root-path-context/test/files/generators.ts new file mode 100644 index 000000000..79811b478 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/generators.ts @@ -0,0 +1,33 @@ +// @ts-nocheck + +function* getAddress(person: Person): Address { + // TODO +} + +function* getFirstAddress(people: Person[]): Address { + // TODO +} + +function* logPerson(person: Person) { + // TODO +} + +function* getHardcodedAddress(): Address { + // TODO +} + +function* getAddresses(people: Person[]): Address[] { + // TODO +} + +function* logPersonWithAddress(person: Person
): Person { + // TODO +} + +function* logPersonOrAddress(person: Person | Address): Person | Address { + // TODO +} + +function* logPersonAndAddress(person: Person, address: Address) { + // TODO +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index dcadb528a..f945a02a9 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -85,6 +85,93 @@ const FUNCTIONS = [ }, ]; +const GENERATORS = [ + { + nodeType: "function_declaration with a param and a return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 3, character: 9 }, + definitionPositions: [ + { row: 2, column: 35 }, // Person + { row: 2, column: 45 }, // Address + ], + }, + { + nodeType: "function_declaration with array param", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 7, character: 9 }, + definitionPositions: [ + { row: 6, column: 40 }, // Person + { row: 6, column: 52 }, // Address + ], + }, + { + nodeType: "function_declaration without return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 11, character: 9 }, + definitionPositions: [ + { row: 10, column: 34 }, // Person + ], + }, + { + nodeType: "function_declaration without params", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 15, character: 9 }, + definitionPositions: [ + { row: 14, column: 40 }, // Person + ], + }, + { + nodeType: "function_declaration with array params and array return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 19, character: 9 }, + definitionPositions: [ + { row: 18, column: 37 }, // Person + { row: 18, column: 49 }, // Address + ], + }, + { + nodeType: + "function_declaration with generic params and generic return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 23, character: 9 }, + definitionPositions: [ + { row: 22, column: 45 }, // Person + { row: 22, column: 53 }, // Address + { row: 22, column: 63 }, // Person + { row: 22, column: 71 }, // Address + ], + }, + { + nodeType: + "function_declaration with union type params and union return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 27, character: 9 }, + definitionPositions: [ + { row: 26, column: 43 }, // Person + { row: 26, column: 53 }, // Address + { row: 26, column: 62 }, // Person + { row: 26, column: 72 }, // Address + ], + }, + { + nodeType: "function_declaration with two arguments", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 31, character: 9 }, + definitionPositions: [ + { row: 30, column: 44 }, // Person + { row: 30, column: 62 }, // Address + ], + }, +]; + const ARROW_FUNCTIONS = [ { nodeType: "arrow_function with a param and a return type", @@ -303,6 +390,7 @@ const CLASS_DEFINITIONS = [ export const TYPESCRIPT_TEST_CASES = [ ...FUNCTIONS, + ...GENERATORS, ...ARROW_FUNCTIONS, ...CLASS_METHODS, ...CLASS_DEFINITIONS, diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm new file mode 100644 index 000000000..b6417f45c --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm @@ -0,0 +1,77 @@ +; Pattern for return type with direct type_identifier +( + (generator_function_declaration + (type_annotation + (type_identifier) @return_type + ) + ) +) + +; Pattern for return type with one level of nesting +( + (generator_function_declaration + (type_annotation + (_ + (type_identifier) @return_type + ) + ) + ) +) + +; Pattern for return type with two levels of nesting +( + (generator_function_declaration + (type_annotation + (_ + (_ + (type_identifier) @return_type + ) + ) + ) + ) +) + +; Pattern for parameters with direct type_identifier +( + (generator_function_declaration + (formal_parameters + (_ + (type_annotation + (type_identifier) @param_type + ) + ) + ) + ) +) + +; Pattern for parameters with one level of nesting +( + (generator_function_declaration + (formal_parameters + (_ + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) +) + +; Pattern for parameters with two levels of nesting +( + (generator_function_declaration + (formal_parameters + (_ + (type_annotation + (_ + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) + ) +) \ No newline at end of file