From 698db54ee0cf5cdb771a7f156d1045bf8ac019cf Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 16:26:24 -0800 Subject: [PATCH 1/8] improv: handle generics in class definitons --- .../root-path-context/test/files/classes.ts | 6 ++ .../test/testCases/typescript.ts | 56 +++++++++++++++++++ .../typescript/class_declaration.scm | 38 +++++++++++-- 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/files/classes.ts b/core/autocomplete/context/root-path-context/test/files/classes.ts index 2f6b76cda..8bb829986 100644 --- a/core/autocomplete/context/root-path-context/test/files/classes.ts +++ b/core/autocomplete/context/root-path-context/test/files/classes.ts @@ -1,3 +1,9 @@ // @ts-nocheck +class Group extends BaseClass {} + +class Group implements FirstInterface {} + class Group extends BaseClass implements FirstInterface, SecondInterface {} + +class Group extends BaseClass implements FirstInterface {} 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 9c490ae23..f051668fc 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -216,8 +216,64 @@ const CLASS_METHODS = [ }, ]; +const CLASS_DEFINITIONS = [ + { + nodeType: "class_declaration with base class", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 2, character: 31 }, + definitionPositions: [ + { row: 2, column: 29 }, // BaseClass + ], + }, + { + nodeType: "class_declaration with interface", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 4, character: 39 }, + definitionPositions: [ + { row: 4, column: 37 }, // FirstInterface + ], + }, + { + nodeType: "class_declaration with base class and multiple interfaces", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 6, character: 74 }, + definitionPositions: [ + { row: 6, column: 29 }, // BaseClass + { row: 6, column: 55 }, // FirstInterface + { row: 6, column: 72 }, // SecondInterface + ], + }, + { + nodeType: "class_declaration with base class and multiple interfaces", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 6, character: 74 }, + definitionPositions: [ + { row: 6, column: 29 }, // BaseClass + { row: 6, column: 55 }, // FirstInterface + { row: 6, column: 72 }, // SecondInterface + ], + }, + { + nodeType: "class_declaration with generic base class and generic interface", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 8, character: 69 }, + definitionPositions: [ + { row: 8, column: 29 }, // BaseClass + { row: 8, column: 61 }, // FirstInterface + { row: 8, column: 34 }, // User + { row: 8, column: 66 }, // User + ], + }, +]; + export const TYPESCRIPT_TEST_CASES = [ ...FUNCTIONS, ...ARROW_FUNCTIONS, ...CLASS_METHODS, + ...CLASS_DEFINITIONS, ]; diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm index bf38152b7..d164b05a8 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm @@ -1,13 +1,21 @@ -( - (class_declaration - (class_heritage - (extends_clause - (identifier) @base-class - ) +; Match a class declaration that extends a base class +; Returns: +; @base-class: The identifier of the base class being extended +; @generic_argument: The type identifier of the generic argument, if present +(class_declaration + (class_heritage + (extends_clause + (identifier) @base-class + (type_arguments + (type_identifier) @generic_argument + )? ) ) ) +; Match a class declaration that implements an interface +; Returns: +; @interface: The type identifier of the interface being implemented ( (class_declaration (class_heritage @@ -16,4 +24,22 @@ ) ) ) +) + +; Match a class declaration that implements a generic interface +; Returns: +; @interface: The type identifier of the generic interface being implemented +; @generic_argument: The type identifier of the generic argument +( + class_declaration + (class_heritage + (implements_clause + (generic_type + (type_identifier) @interface + (type_arguments + (type_identifier) @generic_argument + ) + ) + ) + ) ) \ No newline at end of file From d34da76704b2eb2abac40220eb58154be2b467fc Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 11:46:04 -0800 Subject: [PATCH 2/8] chore: cleanup --- .../context/root-path-context/RootPathContextService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 7a9d26548..85ff5e640 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -157,7 +157,6 @@ export class RootPathContextService { parentKey = key; } - debugger; return snippets; } } From 3595293647b5d7780cfaa8c574400bc71956841f Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 11:59:48 -0800 Subject: [PATCH 3/8] test: multiple arguments --- .../test/files/arrowFunctions.ts | 4 +++ .../test/files/classMethods.ts | 4 +++ .../root-path-context/test/files/functions.ts | 4 +++ .../test/testCases/typescript.ts | 30 +++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts index 42ef247b0..aadffe065 100644 --- a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts +++ b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts @@ -23,3 +23,7 @@ const logPersonWithAddres = (person: Person
): Person
=> { const logPersonOrAddress = (person: Person | Address): Person | Address => { // TODO }; + +const logPersonAndAddress = (person: Person, address: Address) => { + // TODO +}; diff --git a/core/autocomplete/context/root-path-context/test/files/classMethods.ts b/core/autocomplete/context/root-path-context/test/files/classMethods.ts index 36224029b..08f7506a7 100644 --- a/core/autocomplete/context/root-path-context/test/files/classMethods.ts +++ b/core/autocomplete/context/root-path-context/test/files/classMethods.ts @@ -28,4 +28,8 @@ class Group { logPersonOrAddress(person: Person | Address): Person | Address { // TODO } + + logPersonAndAddress(person: Person, address: Address) { + // TODO + } } diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts index 4189f4e20..bb9d39c85 100644 --- a/core/autocomplete/context/root-path-context/test/files/functions.ts +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -27,3 +27,7 @@ function logPersonWithAddress(person: Person
): Person
{ 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 f051668fc..dcadb528a 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -73,6 +73,16 @@ const FUNCTIONS = [ { row: 26, column: 71 }, // Address ], }, + { + nodeType: "function_declaration with two arguments", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 31, character: 9 }, + definitionPositions: [ + { row: 30, column: 43 }, // Person + { row: 30, column: 61 }, // Address + ], + }, ]; const ARROW_FUNCTIONS = [ @@ -138,6 +148,16 @@ const ARROW_FUNCTIONS = [ { row: 22, column: 71 }, // Address ], }, + { + nodeType: "arrow_function with two arguments", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 27, character: 11 }, + definitionPositions: [ + { row: 26, column: 43 }, // Person + { row: 26, column: 61 }, // Address + ], + }, ]; const CLASS_METHODS = [ @@ -214,6 +234,16 @@ const CLASS_METHODS = [ { row: 27, column: 64 }, // Address ], }, + { + nodeType: "method_declaration with two arguments", + fileName: "classMethods.ts", + language: "TypeScript", + cursorPosition: { line: 32, character: 11 }, + definitionPositions: [ + { row: 31, column: 36 }, // Person + { row: 31, column: 54 }, // Address + ], + }, ]; const CLASS_DEFINITIONS = [ From 3bece78be4277aa55bb7b4576594d70159442be1 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 13:12:21 -0800 Subject: [PATCH 4/8] test: generators --- .../test/files/generators.ts | 33 +++++++ .../test/testCases/typescript.ts | 88 +++++++++++++++++++ .../generator_function_declaration.scm | 77 ++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 core/autocomplete/context/root-path-context/test/files/generators.ts create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm 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 From 051aeb7623fd0f4b4b2dfb1a5fb945371ec42b70 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 13:14:40 -0800 Subject: [PATCH 5/8] improv: readability --- .../test/RootPathContextService.test.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index fe81a0edd..78aed69a7 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -61,15 +61,17 @@ const TEST_CASES = [ ]; describe("RootPathContextService", () => { - test.each(TEST_CASES)( - "Should look for correct type definitions when editing inside a $nodeType in $language", - async ({ fileName, cursorPosition, definitionPositions }) => { - await testRootPathContext( - "files", - fileName, - cursorPosition, - definitionPositions, - ); - }, - ); + describe("should look for correct type definitions", () => { + test.each(TEST_CASES)( + "$language: $nodeType", + async ({ fileName, cursorPosition, definitionPositions }) => { + await testRootPathContext( + "files", + fileName, + cursorPosition, + definitionPositions, + ); + }, + ); + }); }); From 3c9071a09b114a019a593a7f241975f419cc4e43 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 14:10:19 -0800 Subject: [PATCH 6/8] feat: ignore node_modules in js and ts code definitions --- .../RootPathContextService.ts | 42 +++- .../root-path-context/test/testUtils.ts | 1 + core/util/treeSitter.ts | 183 +++++++++++------- 3 files changed, 142 insertions(+), 84 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 85ff5e640..2de5b0ae7 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -4,7 +4,12 @@ import { LRUCache } from "lru-cache"; import Parser from "web-tree-sitter"; import { IDE } from "../../.."; -import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; +import { + getFullLanguageName, + getQueryForFile, + IGNORE_PATH_PATTERNS, + LanguageName, +} from "../../../util/treeSitter"; import { AstPath } from "../../util/ast"; import { ImportDefinitionsService } from "../ImportDefinitionsService"; import { AutocompleteSnippet } from "../ranking"; @@ -40,6 +45,7 @@ export class RootPathContextService { private static TYPES_TO_USE = new Set([ "arrow_function", + "generator_function_declaration", "program", "function_declaration", "function_definition", @@ -68,6 +74,7 @@ export class RootPathContextService { node: Parser.SyntaxNode, ): Promise { const snippets: AutocompleteSnippet[] = []; + const language = getFullLanguageName(filepath); let query: Parser.Query | undefined; switch (node.type) { @@ -75,10 +82,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - // const type = node.type; - // debugger; - // console.log(getSyntaxTreeString(node)); - const language = getFullLanguageName(filepath); + const type = node.type; + console.log(getSyntaxTreeString(node)); + debugger; query = await getQueryForFile( filepath, @@ -95,8 +101,13 @@ export class RootPathContextService { const queries = query.matches(node).map(async (match) => { for (const item of match.captures) { try { + const text = node.text; const endPosition = item.node.endPosition; - const newSnippets = await this.getSnippets(filepath, endPosition); + const newSnippets = await this.getSnippets( + filepath, + endPosition, + language, + ); snippets.push(...newSnippets); } catch (e) { debugger; @@ -107,12 +118,14 @@ export class RootPathContextService { await Promise.all(queries); + debugger; return snippets; } private async getSnippets( filepath: string, endPosition: Parser.Point, + language: LanguageName, ): Promise { const definitions = await this.ide.gotoDefinition({ filepath, @@ -122,10 +135,18 @@ export class RootPathContextService { }, }); const newSnippets = await Promise.all( - definitions.map(async (def) => ({ - ...def, - contents: await this.ide.readRangeInFile(def.filepath, def.range), - })), + definitions + .filter((definition) => { + const isIgnoredPath = IGNORE_PATH_PATTERNS[language]?.some( + (pattern) => pattern.test(definition.filepath), + ); + + return !isIgnoredPath; + }) + .map(async (def) => ({ + ...def, + contents: await this.ide.readRangeInFile(def.filepath, def.range), + })), ); return newSnippets; @@ -157,6 +178,7 @@ export class RootPathContextService { parentKey = key; } + debugger; return snippets; } } diff --git a/core/autocomplete/context/root-path-context/test/testUtils.ts b/core/autocomplete/context/root-path-context/test/testUtils.ts index 9526cacdb..7a5c22aba 100644 --- a/core/autocomplete/context/root-path-context/test/testUtils.ts +++ b/core/autocomplete/context/root-path-context/test/testUtils.ts @@ -84,6 +84,7 @@ export async function testRootPathContext( index + 1, expect.any(String), // filepath argument position, + expect.any(String), // language argument ); }); } diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index 4fe0d1665..9118b80ee 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -3,81 +3,116 @@ import * as path from "node:path"; import Parser, { Language } from "web-tree-sitter"; -export const supportedLanguages: { [key: string]: string } = { - cpp: "cpp", - hpp: "cpp", - cc: "cpp", - cxx: "cpp", - hxx: "cpp", - cp: "cpp", - hh: "cpp", - inc: "cpp", - // Depended on this PR: https://github.com/tree-sitter/tree-sitter-cpp/pull/173 - // ccm: "cpp", - // c++m: "cpp", - // cppm: "cpp", - // cxxm: "cpp", - cs: "c_sharp", - c: "c", - h: "c", - css: "css", - php: "php", - phtml: "php", - php3: "php", - php4: "php", - php5: "php", - php7: "php", - phps: "php", - "php-s": "php", - bash: "bash", - sh: "bash", - json: "json", - ts: "typescript", - mts: "typescript", - cts: "typescript", - tsx: "tsx", - // vue: "vue", // tree-sitter-vue parser is broken - // The .wasm file being used is faulty, and yaml is split line-by-line anyway for the most part - // yaml: "yaml", - // yml: "yaml", - elm: "elm", - js: "javascript", - jsx: "javascript", - mjs: "javascript", - cjs: "javascript", - py: "python", - ipynb: "python", - pyw: "python", - pyi: "python", - el: "elisp", - emacs: "elisp", - ex: "elixir", - exs: "elixir", - go: "go", - eex: "embedded_template", - heex: "embedded_template", - leex: "embedded_template", - html: "html", - htm: "html", - java: "java", - lua: "lua", - ocaml: "ocaml", - ml: "ocaml", - mli: "ocaml", - ql: "ql", - res: "rescript", - resi: "rescript", - rb: "ruby", - erb: "ruby", - rs: "rust", - rdl: "systemrdl", - toml: "toml", - sol: "solidity", +export enum LanguageName { + CPP = "cpp", + C_SHARP = "c_sharp", + C = "c", + CSS = "css", + PHP = "php", + BASH = "bash", + JSON = "json", + TYPESCRIPT = "typescript", + TSX = "tsx", + ELM = "elm", + JAVASCRIPT = "javascript", + PYTHON = "python", + ELISP = "elisp", + ELIXIR = "elixir", + GO = "go", + EMBEDDED_TEMPLATE = "embedded_template", + HTML = "html", + JAVA = "java", + LUA = "lua", + OCAML = "ocaml", + QL = "ql", + RESCRIPT = "rescript", + RUBY = "ruby", + RUST = "rust", + SYSTEMRDL = "systemrdl", + TOML = "toml", + SOLIDITY = "solidity", +} - // jl: "julia", - // swift: "swift", - // kt: "kotlin", - // scala: "scala", +export const supportedLanguages: { [key: string]: LanguageName } = { + cpp: LanguageName.CPP, + hpp: LanguageName.CPP, + cc: LanguageName.CPP, + cxx: LanguageName.CPP, + hxx: LanguageName.CPP, + cp: LanguageName.CPP, + hh: LanguageName.CPP, + inc: LanguageName.CPP, + // Depended on this PR: https://github.com/tree-sitter/tree-sitter-cpp/pull/173 + // ccm: LanguageName.CPP, + // c++m: LanguageName.CPP, + // cppm: LanguageName.CPP, + // cxxm: LanguageName.CPP, + cs: LanguageName.C_SHARP, + c: LanguageName.C, + h: LanguageName.C, + css: LanguageName.CSS, + php: LanguageName.PHP, + phtml: LanguageName.PHP, + php3: LanguageName.PHP, + php4: LanguageName.PHP, + php5: LanguageName.PHP, + php7: LanguageName.PHP, + phps: LanguageName.PHP, + "php-s": LanguageName.PHP, + bash: LanguageName.BASH, + sh: LanguageName.BASH, + json: LanguageName.JSON, + ts: LanguageName.TYPESCRIPT, + mts: LanguageName.TYPESCRIPT, + cts: LanguageName.TYPESCRIPT, + tsx: LanguageName.TSX, + // vue: LanguageName.VUE, // tree-sitter-vue parser is broken + // The .wasm file being used is faulty, and yaml is split line-by-line anyway for the most part + // yaml: LanguageName.YAML, + // yml: LanguageName.YAML, + elm: LanguageName.ELM, + js: LanguageName.JAVASCRIPT, + jsx: LanguageName.JAVASCRIPT, + mjs: LanguageName.JAVASCRIPT, + cjs: LanguageName.JAVASCRIPT, + py: LanguageName.PYTHON, + ipynb: LanguageName.PYTHON, + pyw: LanguageName.PYTHON, + pyi: LanguageName.PYTHON, + el: LanguageName.ELISP, + emacs: LanguageName.ELISP, + ex: LanguageName.ELIXIR, + exs: LanguageName.ELIXIR, + go: LanguageName.GO, + eex: LanguageName.EMBEDDED_TEMPLATE, + heex: LanguageName.EMBEDDED_TEMPLATE, + leex: LanguageName.EMBEDDED_TEMPLATE, + html: LanguageName.HTML, + htm: LanguageName.HTML, + java: LanguageName.JAVA, + lua: LanguageName.LUA, + ocaml: LanguageName.OCAML, + ml: LanguageName.OCAML, + mli: LanguageName.OCAML, + ql: LanguageName.QL, + res: LanguageName.RESCRIPT, + resi: LanguageName.RESCRIPT, + rb: LanguageName.RUBY, + erb: LanguageName.RUBY, + rs: LanguageName.RUST, + rdl: LanguageName.SYSTEMRDL, + toml: LanguageName.TOML, + sol: LanguageName.SOLIDITY, + + // jl: LanguageName.JULIA, + // swift: LanguageName.SWIFT, + // kt: LanguageName.KOTLIN, + // scala: LanguageName.SCALA, +}; + +export const IGNORE_PATH_PATTERNS: Partial> = { + [LanguageName.TYPESCRIPT]: [/.*node_modules/], + [LanguageName.JAVASCRIPT]: [/.*node_modules/], }; export async function getParserForFile(filepath: string) { From 42c99902390321ceb8111c1fa0e8629cc8909eb0 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 14:12:01 -0800 Subject: [PATCH 7/8] refactor: clean up --- .../context/root-path-context/RootPathContextService.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 2de5b0ae7..55ba38b31 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -82,9 +82,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - const type = node.type; - console.log(getSyntaxTreeString(node)); - debugger; + // const type = node.type; + // console.log(getSyntaxTreeString(node)); + // debugger; query = await getQueryForFile( filepath, @@ -101,7 +101,6 @@ export class RootPathContextService { const queries = query.matches(node).map(async (match) => { for (const item of match.captures) { try { - const text = node.text; const endPosition = item.node.endPosition; const newSnippets = await this.getSnippets( filepath, @@ -178,7 +177,7 @@ export class RootPathContextService { parentKey = key; } - debugger; + return snippets; } } From 9d0b405f64a4c190e58cc632628cf5c13d0297a8 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 14:12:49 -0800 Subject: [PATCH 8/8] refactor: clean up --- .../context/root-path-context/RootPathContextService.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 55ba38b31..0147df151 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -92,7 +92,6 @@ export class RootPathContextService { ); break; } - const type = node.type; if (!query) { return snippets; @@ -117,7 +116,6 @@ export class RootPathContextService { await Promise.all(queries); - debugger; return snippets; }