aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-10 12:36:29 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-10 13:11:28 -0400
commitf6335de738e47dff08ab4fefc8aad027f860076b (patch)
treef59db5d6ce11805469eb0b6cf1ffd9e033ac468c
parenta42400e0c9f1471ec27454476f6fe6c19dc95242 (diff)
Ensure for locals that they are defined in the same file as the identifier
-rw-r--r--src/server/analysis.odin7
-rw-r--r--tests/hover_test.odin43
2 files changed, 49 insertions, 1 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 668260b..1988353 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1111,7 +1111,12 @@ get_local :: proc(ast_context: AstContext, ident: ast.Ident) -> (DocumentLocal,
local_stack := locals[ident.name] or_continue
#reverse for local in local_stack {
- if local.offset <= ident.pos.offset || local.local_global || local.lhs.pos.offset == ident.pos.offset {
+ if local.local_global {
+ return local, true
+ }
+ // Ensure that if the identifier has a file, the local is also part of the same file
+ correct_file := ident.pos.file == "" || local.lhs.pos.file == ident.pos.file
+ if correct_file && (local.offset <= ident.pos.offset || local.lhs.pos.offset == ident.pos.offset) {
// checking equal offsets is a hack to allow matching lhs ident in var decls
// because otherwise minimal offset begins after the decl
return local, true
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index bdd583a..244a4f9 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -412,6 +412,49 @@ ast_hover_union_implicit_selector :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "test.Bar: .Foo1")
}
+@(test)
+ast_hover_foreign_package_name_collision :: proc(t: ^testing.T) {
+ packages := make([dynamic]test.Package, context.temp_allocator)
+
+ append(
+ &packages,
+ test.Package {
+ pkg = "my_package",
+ source = `package my_package
+
+ data :: struct {
+ nodes: []node,
+ }
+
+ bar :: struct {
+ }
+
+ node :: struct {
+ bar: ^bar
+ }
+
+ get_data :: proc() -> ^data {
+ return &data{}
+ }
+ `,
+ },
+ )
+ source := test.Source {
+ main = `package test
+ import "my_package"
+ main :: proc() {
+ data := my_package.get_data()
+
+ for node in data.nodes {
+ bar := node.b{*}ar
+ }
+ }
+ `,
+ packages = packages[:],
+ }
+
+ test.expect_hover(t, &source, "node.bar: ^bar")
+}
/*
Waiting for odin fix