diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-06-07 21:31:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-07 21:31:44 +0200 |
| commit | a42400e0c9f1471ec27454476f6fe6c19dc95242 (patch) | |
| tree | d1626db02ab4f255806fac323fc386163b60ca53 | |
| parent | c2a2283bf4e0cc2c2b25a6ee2014a18c3b11f3c7 (diff) | |
| parent | 24e32736b3c19b541a810e07927db50d71e07423 (diff) | |
Merge pull request #648 from BradLewis/feat/add-hover-to-enum-values
Add hover support for implicit selector expr
| -rw-r--r-- | src/server/analysis.odin | 7 | ||||
| -rw-r--r-- | src/server/hover.odin | 25 | ||||
| -rw-r--r-- | tests/hover_test.odin | 36 |
3 files changed, 65 insertions, 3 deletions
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/src/server/hover.odin b/src/server/hover.odin index 9e4e20c..cc3c5b2 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -234,6 +234,31 @@ 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.signature = fmt.tprintf(".%s", 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.signature = fmt.tprintf(".%s", 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) diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 9f1a9f0..bdd583a 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -376,6 +376,42 @@ ast_hover_proc_with_proc_parameter_with_return :: proc(t: ^testing.T) { test.expect_hover(t, &source, "test.aa: proc(p: proc() -> int)") } +@(test) +ast_hover_enum_implicit_selector :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: enum { + Foo1, + Foo2, + } + + foo: Foo + foo = .Fo{*}o1 + ` + } + + test.expect_hover(t, &source, "test.Foo: .Foo1") +} + +@(test) +ast_hover_union_implicit_selector :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: enum { + Foo1, + Foo2, + } + + Bar :: union { Foo, int } + + bar: Bar + bar = .Fo{*}o1 + ` + } + + test.expect_hover(t, &source, "test.Bar: .Foo1") +} + /* Waiting for odin fix |