From 7ee64314fdd05984c65b1aa6df7ef3cd2dd435cd Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Thu, 5 Jun 2025 19:29:33 -0400 Subject: Add hover support for implicit selector expr --- src/server/hover.odin | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') diff --git a/src/server/hover.odin b/src/server/hover.odin index 9e4e20c..d378696 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -234,6 +234,33 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } } + } else if position_context.implicit_selector_expr != nil { + implicit_selector := position_context.implicit_selector_expr + if symbol, ok := resolve_implicit_selector(&ast_context, &position_context, implicit_selector); ok { + #partial switch v in symbol.value { + case SymbolEnumValue: + for name, i in v.names { + if strings.compare(name, implicit_selector.field.name) == 0 { + symbol.pkg = symbol.name + symbol.name = name + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } + case SymbolUnionValue: + if enum_value, ok := unwrap_super_enum(&ast_context, v); ok { + for name, i in enum_value.names { + if strings.compare(name, implicit_selector.field.name) == 0 { + symbol.pkg = symbol.name + symbol.name = name + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } + } + } + } + return {}, false, true } else if position_context.identifier != nil { reset_ast_context(&ast_context) -- cgit v1.2.3 From e81770b1ededb36770fd2393feb2d4450df445ef Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Thu, 5 Jun 2025 21:03:04 -0400 Subject: Update implicit expression hover text to include package --- src/server/hover.odin | 6 ++---- tests/hover_test.odin | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/server/hover.odin b/src/server/hover.odin index d378696..cc3c5b2 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -241,8 +241,7 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> case SymbolEnumValue: for name, i in v.names { if strings.compare(name, implicit_selector.field.name) == 0 { - symbol.pkg = symbol.name - symbol.name = name + symbol.signature = fmt.tprintf(".%s", name) hover.contents = write_hover_content(&ast_context, symbol) return hover, true, true } @@ -251,8 +250,7 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> if enum_value, ok := unwrap_super_enum(&ast_context, v); ok { for name, i in enum_value.names { if strings.compare(name, implicit_selector.field.name) == 0 { - symbol.pkg = symbol.name - symbol.name = name + symbol.signature = fmt.tprintf(".%s", name) hover.contents = write_hover_content(&ast_context, symbol) return hover, true, true } diff --git a/tests/hover_test.odin b/tests/hover_test.odin index dafc81c..028fbdb 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -390,7 +390,7 @@ ast_hover_enum_implicit_selector :: proc(t: ^testing.T) { ` } - test.expect_hover(t, &source, "Foo.Foo1") + test.expect_hover(t, &source, "test.Foo: .Foo1") } @(test) @@ -409,7 +409,7 @@ ast_hover_union_implicit_selector :: proc(t: ^testing.T) { ` } - test.expect_hover(t, &source, "Bar.Foo1") + test.expect_hover(t, &source, "test.Bar: .Foo1") } /* -- cgit v1.2.3 From 24e32736b3c19b541a810e07927db50d71e07423 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Thu, 5 Jun 2025 21:20:02 -0400 Subject: Fix definition and hover for union enum types --- src/server/analysis.odin | 7 ++++--- tests/hover_test.odin | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 7f0007e..668260b 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -3727,9 +3727,10 @@ unwrap_super_enum :: proc( for type in symbol_union.types { symbol := resolve_type_expression(ast_context, type) or_return - value := symbol.value.(SymbolEnumValue) or_return - append(&names, ..value.names) - append(&ranges, ..value.ranges) + if value, ok := symbol.value.(SymbolEnumValue); ok { + append(&names, ..value.names) + append(&ranges, ..value.ranges) + } } ret_value.names = names[:] diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 028fbdb..bdd583a 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -402,7 +402,7 @@ ast_hover_union_implicit_selector :: proc(t: ^testing.T) { Foo2, } - Bar :: union { Foo } + Bar :: union { Foo, int } bar: Bar bar = .Fo{*}o1 -- cgit v1.2.3