aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-07-02 16:06:49 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-07-02 16:06:49 +0200
commit2ab51698771b550f7a735aa9995d8e6b1bba5723 (patch)
tree416884e6e44802aeb634e137d342b7a066bb2a05
parent0e7d21ee627cf152f8c6e80db20f52a94535ad5e (diff)
Check if the identifier is in the imports before checking anything else.
-rw-r--r--src/server/analysis.odin28
-rw-r--r--tests/completions_test.odin3
-rw-r--r--tests/hover_test.odin38
3 files changed, 52 insertions, 17 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 8956c70..b5cd385 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1394,6 +1394,20 @@ internal_resolve_type_identifier :: proc(
}
}
+ for imp in ast_context.imports {
+ if strings.compare(imp.base, node.name) == 0 {
+ symbol := Symbol {
+ type = .Package,
+ pkg = imp.name,
+ value = SymbolPackageValue{},
+ }
+
+ try_build_package(symbol.pkg)
+
+ return symbol, true
+ }
+ }
+
if local, ok := get_local(ast_context^, node);
ok && ast_context.use_locals {
is_distinct := false
@@ -1706,20 +1720,6 @@ internal_resolve_type_identifier :: proc(
}
}
- for imp in ast_context.imports {
- if strings.compare(imp.base, node.name) == 0 {
- symbol := Symbol {
- type = .Package,
- pkg = imp.name,
- value = SymbolPackageValue{},
- }
-
- try_build_package(symbol.pkg)
-
- return symbol, true
- }
- }
-
for built in indexer.builtin_packages {
if symbol, ok := lookup(node.name, built); ok {
return resolve_symbol_return(ast_context, symbol)
diff --git a/tests/completions_test.odin b/tests/completions_test.odin
index 76ed98a..04baade 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -407,9 +407,6 @@ index_package_completion :: proc(t: ^testing.T) {
)
}
-import "core:odin/ast"
-import "core:odin/parser"
-
@(test)
ast_generic_make_slice :: proc(t: ^testing.T) {
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 22403a0..dcf3a57 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -185,3 +185,41 @@ ast_hover_on_bitset_variable :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "test.derived_bit_set: bit_set[Foo]")
}
+
+@(test)
+ast_hover_struct_field_selector_completion :: proc(t: ^testing.T) {
+
+ packages := make([dynamic]test.Package, context.temp_allocator)
+
+ append(
+ &packages,
+ test.Package {
+ pkg = "my_package",
+ source = `package my_package
+ My_Struct :: struct {
+ one: int,
+ two: int,
+ three: int,
+ }
+ `,
+ },
+ )
+
+ source := test.Source {
+ main = `package test
+
+ import "my_package"
+ My_Foo :: struct {
+ bar: my_package.My_Stru{*}ct,
+ }
+
+ my_package :: proc() {
+
+ }
+
+ `,
+ packages = packages[:],
+ }
+
+ test.expect_hover(t, &source, "my_package.My_Struct: struct")
+}