aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-12-16 19:32:27 +1100
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-12-16 19:32:27 +1100
commit45bb4a16cd821fb49d9c5b082dade954e59570ec (patch)
treec29fcf277e3d4fc217ac403448a3b7a0cc5a6e1d
parent79dc7bb79998428a96ab25f6c122dfc4c1909ac1 (diff)
Only use field for selector completions if the position is within the field
-rw-r--r--src/common/util_windows.odin2
-rw-r--r--src/server/completion.odin2
-rw-r--r--tests/completions_test.odin32
3 files changed, 33 insertions, 3 deletions
diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin
index 4281808..3be65b4 100644
--- a/src/common/util_windows.odin
+++ b/src/common/util_windows.odin
@@ -1,9 +1,7 @@
package common
-import "core:fmt"
import "core:log"
import "core:mem"
-import "core:strings"
import "core:time"
import win32 "core:sys/windows"
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 6663be9..e16c49c 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -741,7 +741,7 @@ get_selector_completion :: proc(
field: string
- if position_context.field != nil {
+ if position_context.field != nil && position_in_node(position_context.field, position_context.position) {
#partial switch v in position_context.field.derived {
case ^ast.Ident:
field = v.name
diff --git a/tests/completions_test.odin b/tests/completions_test.odin
index 5ab4181..4403e02 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -5148,3 +5148,35 @@ ast_completion_global_selector_from_local_scope :: proc(t: ^testing.T) {
}
test.expect_completion_docs(t, &source, "", {"Foo.foo: int"})
}
+
+@(test)
+ast_completion_empty_selector_with_ident_newline :: proc(t: ^testing.T) {
+ packages := make([dynamic]test.Package, context.temp_allocator)
+
+ append(
+ &packages,
+ test.Package {
+ pkg = "my_package",
+ source = `package my_package
+ Foo :: struct{}
+ `,
+ },
+ )
+ source := test.Source {
+ main = `package test
+
+ Foo :: struct{
+ x: int,
+ }
+
+ import "my_package"
+
+ main :: proc() {
+ my_package.{*}
+ y := 2
+ }
+ `,
+ packages = packages[:],
+ }
+ test.expect_completion_docs(t, &source, "", {"my_package.Foo :: struct{}"})
+}