diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-03 16:49:07 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-03 19:48:15 -0400 |
| commit | 5ff21d6abb6747f584b488a61d2048e298dbf786 (patch) | |
| tree | fd180afaa80a5d054d139c92d67e92669acfbd3b /src/server | |
| parent | 650ddc73125112ad8e4fe638114c0cda2854c993 (diff) | |
Add hover information for enum fields
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/hover.odin | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/src/server/hover.odin b/src/server/hover.odin index aaddd08..39f6814 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -112,12 +112,44 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } - if position_context.struct_type != nil { - for field in position_context.struct_type.fields.list { - for name in field.names { - if position_in_node(name, position_context.position) { - if identifier, ok := name.derived.(^ast.Ident); ok && field.type != nil { - if position_context.value_decl != nil && len(position_context.value_decl.names) != 0 { + if position_context.value_decl != nil && len(position_context.value_decl.names) != 0 { + if position_context.enum_type != nil { + if enum_symbol, ok := resolve_type_expression(&ast_context, position_context.value_decl.names[0]); ok { + for field in position_context.enum_type.fields { + if ident, ok := field.derived.(^ast.Ident); ok { + if position_in_node(ident, position_context.position) { + symbol := Symbol { + pkg = ast_context.current_package, + name = enum_symbol.name, + range = common.get_token_range(ident, ast_context.file.src), + signature = fmt.tprintf(".%s", ident.name), + } + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } else if value, ok := field.derived.(^ast.Field_Value); ok { + if position_in_node(value.field, position_context.position) { + if ident, ok := value.field.derived.(^ast.Ident); ok { + symbol := Symbol { + pkg = ast_context.current_package, + range = common.get_token_range(value.field, ast_context.file.src), + name = enum_symbol.name, + signature = fmt.tprintf(".%s", ident.name), + } + hover.contents = write_hover_content(&ast_context, symbol) + } + return hover, true, true + } + } + } + } + } + + if position_context.struct_type != nil { + for field in position_context.struct_type.fields.list { + for name in field.names { + if position_in_node(name, position_context.position) { + if identifier, ok := name.derived.(^ast.Ident); ok && field.type != nil { if symbol, ok := resolve_type_expression(&ast_context, field.type); ok { if struct_symbol, ok := resolve_type_expression( &ast_context, @@ -139,7 +171,9 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> break } } - if index != -1 && value.comments[index] != nil && len(value.comments[index].list) > 0 { + if index != -1 && + value.comments[index] != nil && + len(value.comments[index].list) > 0 { symbol.comment = value.comments[index].list[0].text } } @@ -306,7 +340,7 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> if name == field { symbol := Symbol { name = selector.name, - pkg = selector.pkg, + pkg = selector.pkg, } // TODO: update this to go through some kind of common `get_signature` symbol.signature = fmt.tprintf(".%s", name) |