diff options
| -rw-r--r-- | src/server/analysis.odin | 10 | ||||
| -rw-r--r-- | src/server/completion.odin | 3 | ||||
| -rw-r--r-- | tests/completions_test.odin | 36 |
3 files changed, 48 insertions, 1 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 4a1980c..2dfed25 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -3267,6 +3267,16 @@ get_using_packages :: proc(ast_context: ^AstContext) -> []string { return usings } +// Returns whether the provided package is being used with a `using` statement +is_using_package :: proc(ast_context: ^AstContext, pkg: string) -> bool { + for u in ast_context.usings { + if strings.compare(pkg, u.pkg_name) == 0 { + return true + } + } + return false +} + get_symbol_pkg_name :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { return get_pkg_name(ast_context, symbol.pkg) } diff --git a/src/server/completion.odin b/src/server/completion.odin index 2d249bd..44916d7 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -934,7 +934,8 @@ get_selector_completion :: proc( if symbol.pkg == ast_context.document_package || base == "runtime" || base == "$builtin" || - is_selector { + is_selector || + is_using_package(ast_context, symbol.pkg) { item.label = fmt.aprintf( "(%v%v)", repeat("^", symbol.pointers, context.temp_allocator), diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 0f9aded..43f4984 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -5028,3 +5028,39 @@ ast_completion_empty_selector_for_init :: proc(t: ^testing.T) { } test.expect_completion_docs(t, &source, "", {"Foo.bars: [5]int"}) } + +@(test) +ast_completion_union_option_with_using :: 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{} + + Bar :: struct{} + + Bazz :: union { + ^Foo, + ^Bar, + } + `, + }, + ) + source := test.Source { + main = `package test + import "my_package" + + main :: proc() { + using my_package + + bazz: Bazz + if foo, ok := bazz.{*} + } + `, + packages = packages[:], + } + test.expect_completion_labels(t, &source, "", {"(^Foo)", "(^Bar)"}) +} |