From e0ae4ceb567d7288021259b2cd39ac68d138863b Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 11:11:47 -0800 Subject: [PATCH 1/2] test: go --- .../context/root-path-context/test/files/file1.go | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 core/autocomplete/context/root-path-context/test/files/file1.go diff --git a/core/autocomplete/context/root-path-context/test/files/file1.go b/core/autocomplete/context/root-path-context/test/files/file1.go new file mode 100644 index 000000000..94eec171c --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/file1.go @@ -0,0 +1,9 @@ +package main + +import ( + "core/autocomplete/context/root-path-context/test/files/models" +) + +func getAddress(user *models.User) *models.Address { + return user.Address +} \ No newline at end of file From bf65b1ebbdd3b0913d141e9f60a11414088bc78f Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 11:33:09 -0800 Subject: [PATCH 2/2] feat: go definitions --- .../test/RootPathContextService.test.ts | 12 +++++++++++- .../function_declaration/go.scm | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm 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 4bc099c28..58da8982a 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -57,7 +57,7 @@ const TEST_CASES = [ ], }, { - nodeType: "function_definition (inside a class)", + nodeType: "method_declaration", fileName: "file1.php", language: "PHP", cursorPosition: { line: 26, character: 35 }, @@ -69,6 +69,16 @@ const TEST_CASES = [ { row: 25, column: 61 }, // Address ], }, + { + nodeType: "function_declaration", + fileName: "file1.go", + language: "Go", + cursorPosition: { line: 7, character: 21 }, + definitionPositions: [ + { row: 6, column: 33 }, // models.User + { row: 6, column: 50 }, // models.Address + ], + }, ]; describe("RootPathContextService", () => { diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm new file mode 100644 index 000000000..482f50841 --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm @@ -0,0 +1,12 @@ +( + (function_declaration + (parameter_list + (parameter_declaration + type: (_) @param_type + )* + ) + ; Optional return type node before the block + ([_] @return_type)? + (block) + ) +) \ No newline at end of file