diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-26 21:39:29 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-29 15:49:11 -0400 |
| commit | 83d6bd2630fbcba45a3c912c4a141e4995def4f8 (patch) | |
| tree | 04c40ead41b257642a162e5cde7f4b2afbddf36b /src/server | |
| parent | 7333f046381ee3e19a8935c797efca09a923fa14 (diff) | |
Fix completion and hover tests with documentation changes
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/completion.odin | 38 | ||||
| -rw-r--r-- | src/server/documentation.odin | 87 | ||||
| -rw-r--r-- | src/server/hover.odin | 5 | ||||
| -rw-r--r-- | src/server/symbol.odin | 2 | ||||
| -rw-r--r-- | src/server/types.odin | 1 |
5 files changed, 59 insertions, 74 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index 6f8d8c7..ed27270 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -205,6 +205,17 @@ convert_completion_results :: proc( for result in top_results { result := result if item, ok := result.completion_item.?; ok { + if common.config.enable_label_details { + item.labelDetails = CompletionItemLabelDetails { + detail = item.detail, + } + } + // temporary as we move things to use the symbols directly + if item.documentation == nil { + item.documentation = item.detail + } else if s, ok := item.documentation.(string); ok && s == "" { + item.documentation = item.detail + } append(&items, item) continue } @@ -241,7 +252,7 @@ convert_completion_results :: proc( continue } - build_documentation(ast_context, &result.symbol, false) + build_documentation(ast_context, &result.symbol, true) item := CompletionItem { label = result.symbol.name, documentation = write_hover_content(ast_context, result.symbol) @@ -393,8 +404,8 @@ get_comp_lit_completion :: proc( continue } - construct_struct_field_symbol(&symbol, symbol.name, v, i) - append(results, CompletionResult{symbol = symbol}) + construct_struct_field_symbol(&resolved, symbol.name, v, i) + append(results, CompletionResult{symbol = resolved}) } } case SymbolBitFieldValue: @@ -410,8 +421,8 @@ get_comp_lit_completion :: proc( continue } - construct_bit_field_field_symbol(&symbol, symbol.name, v, i) - append(results, CompletionResult{symbol = symbol}) + construct_bit_field_field_symbol(&resolved, symbol.name, v, i) + append(results, CompletionResult{symbol = resolved}) } } case SymbolFixedArrayValue: @@ -699,16 +710,7 @@ get_selector_completion :: proc( } construct_struct_field_symbol(&symbol, selector.name, v, i) - build_documentation(ast_context, &symbol) - - item := CompletionItem { - label = name, - kind = .Field, - detail = concatenate_symbol_information(ast_context, symbol), - documentation = symbol.doc, - } - - append(results, CompletionResult{completion_item = item}) + append(results, CompletionResult{symbol = symbol}) } else { //just give some generic symbol with name. item := CompletionItem { @@ -1400,8 +1402,10 @@ get_identifier_completion :: proc( ident.name = k if symbol, ok := resolve_type_identifier(ast_context, ident^); ok { - symbol.name = k if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 { + symbol.type_name = symbol.name + symbol.type_pkg = symbol.pkg + symbol.name = clean_ident(ident.name) append(results, CompletionResult{score = score * 1.1, symbol = symbol}) } } @@ -1428,6 +1432,8 @@ get_identifier_completion :: proc( if symbol, ok := resolve_type_identifier(ast_context, ident^); ok { if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 { + symbol.type_name = symbol.name + symbol.type_pkg = symbol.pkg symbol.name = clean_ident(ident.name) append(results, CompletionResult{score = score * 1.7, symbol = symbol}) } diff --git a/src/server/documentation.odin b/src/server/documentation.odin index 9634a06..fa6eff5 100644 --- a/src/server/documentation.odin +++ b/src/server/documentation.odin @@ -145,15 +145,15 @@ construct_symbol_docs :: proc(docs, comment: string, allocator := context.temp_a // Returns the fully detailed signature for the symbol, including things like attributes and fields get_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { - is_variable := symbol.type == .Variable + show_type_info := symbol.type == .Variable || symbol.type == .Field pointer_prefix := repeat("^", symbol.pointers, ast_context.allocator) #partial switch v in symbol.value { case SymbolEnumValue: sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) strings.write_string(&sb, " :: ") } if len(v.names) == 0 { @@ -189,15 +189,8 @@ get_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { return strings.to_string(sb) case SymbolStructValue: sb := strings.builder_make(ast_context.allocator) - if symbol.type_name != "" { - if symbol.type_pkg == "" { - fmt.sbprintf(&sb, "%s%s :: ", pointer_prefix, symbol.type_name) - } else { - pkg_name := get_pkg_name(ast_context, symbol.type_pkg) - fmt.sbprintf(&sb, "%s%s.%s :: ", pointer_prefix, pkg_name, symbol.type_name) - } - } else if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) strings.write_string(&sb, " :: ") } if len(v.names) == 0 { @@ -211,8 +204,8 @@ get_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { return strings.to_string(sb) case SymbolUnionValue: sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) strings.write_string(&sb, " :: ") } if len(v.types) == 0 { @@ -241,24 +234,16 @@ get_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { return strings.to_string(sb) case SymbolProcedureValue: sb := strings.builder_make(ast_context.allocator) - if symbol.type_pkg != "" && symbol.type_name != "" { - pkg_name := get_pkg_name(ast_context, symbol.type_pkg) - fmt.sbprintf(&sb, "%s%s.%s :: ", pointer_prefix, pkg_name, symbol.type_name) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) } write_procedure_symbol_signature(&sb, v, detailed_signature=true) return strings.to_string(sb) case SymbolBitFieldValue: sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) strings.write_string(&sb, " :: ") - } else if symbol.type_name != "" { - if symbol.type_pkg == "" { - fmt.sbprintf(&sb, "%s%s :: ", pointer_prefix, symbol.type_name) - } else { - pkg_name := get_pkg_name(ast_context, symbol.type_pkg) - fmt.sbprintf(&sb, "%s%s.%s :: ", pointer_prefix, pkg_name, symbol.type_name) - } } strings.write_string(&sb, "bit_field ") build_string_node(v.backing_type, &sb, false) @@ -300,17 +285,14 @@ get_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { } get_short_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string { - if symbol.signature != "" { - return symbol.signature - } - - is_variable := symbol.type == .Variable + // TODO: this is also a bit much, might need to clean it up into a function + show_type_info := (symbol.type == .Variable || symbol.type == .Field) && !(.Anonymous in symbol.flags) && symbol.type_name != "" pointer_prefix := repeat("^", symbol.pointers, ast_context.allocator) #partial switch v in symbol.value { case SymbolBasicValue: sb := strings.builder_make(ast_context.allocator) - if symbol.type_name != "" { + if show_type_info { write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) } else if .Distinct in symbol.flags { if symbol.type == .Keyword { @@ -331,11 +313,13 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string strings.write_string(&sb, "]") return strings.to_string(sb) case SymbolEnumValue: + // TODO: we need a better way to do this for enum fields + if symbol.type == .Field && symbol.type_name == "" { + return symbol.signature + } sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) - } else if symbol.type_name != "" { - write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) } else { strings.write_string(&sb, pointer_prefix) strings.write_string(&sb, "enum {..}") @@ -350,9 +334,8 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string return strings.to_string(sb) case SymbolProcedureValue: sb := strings.builder_make(ast_context.allocator) - if symbol.type_pkg != "" && symbol.type_name != "" { - pkg_name := get_pkg_name(ast_context, symbol.type_pkg) - fmt.sbprintf(&sb, "%s%s.%s :: ", pointer_prefix, pkg_name, symbol.type_name) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) } write_procedure_symbol_signature(&sb, v, detailed_signature=false) return strings.to_string(sb) @@ -360,10 +343,8 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string return "proc" case SymbolStructValue: sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) - } else if symbol.type_name != "" { - write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) } else { strings.write_string(&sb, pointer_prefix) strings.write_string(&sb, "struct {..}") @@ -371,10 +352,8 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string return strings.to_string(sb) case SymbolUnionValue: sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) - } else if symbol.type_name != "" { - write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) } else { strings.write_string(&sb, pointer_prefix) strings.write_string(&sb, "union {..}") @@ -382,10 +361,8 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> string return strings.to_string(sb) case SymbolBitFieldValue: sb := strings.builder_make(ast_context.allocator) - if is_variable { - append_variable_full_name(&sb, ast_context, symbol, pointer_prefix) - } else if symbol.type_name != "" { - write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) + if show_type_info { + append_type_information(&sb, ast_context, symbol, pointer_prefix) } else { fmt.sbprintf(&sb, "%sbit_field ", pointer_prefix) build_string_node(v.backing_type, &sb, false) @@ -627,18 +604,18 @@ write_struct_hover :: proc(ast_context: ^AstContext, sb: ^strings.Builder, v: Sy strings.write_string(sb, "}") } -append_variable_full_name :: proc( +append_type_information :: proc( sb: ^strings.Builder, ast_context: ^AstContext, symbol: ^Symbol, pointer_prefix: string, ) { - pkg_name := get_symbol_pkg_name(ast_context, symbol) + pkg_name := get_pkg_name(ast_context, symbol.type_pkg) if pkg_name == "" { - fmt.sbprintf(sb, "%s%s", pointer_prefix, symbol.name) + fmt.sbprintf(sb, "%s%s", pointer_prefix, symbol.type_name) return } - fmt.sbprintf(sb, "%s%s.%s", pointer_prefix, pkg_name, symbol.name) + fmt.sbprintf(sb, "%s%s.%s", pointer_prefix, pkg_name, symbol.type_name) return } diff --git a/src/server/hover.odin b/src/server/hover.odin index d5801cf..0a82406 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -413,13 +413,14 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { - build_documentation(&ast_context, &resolved, false) + resolved.type_name = resolved.name + resolved.type_pkg = resolved.pkg resolved.name = ident.name - if resolved.type == .Variable { resolved.pkg = ast_context.document_package } + build_documentation(&ast_context, &resolved, false) hover.contents = write_hover_content(&ast_context, resolved) return hover, true, true } diff --git a/src/server/symbol.odin b/src/server/symbol.odin index e5705a2..0ead07f 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -787,7 +787,9 @@ construct_bit_field_field_symbol :: proc(symbol: ^Symbol, parent_name: string, v symbol.type = .Field symbol.doc = get_doc(value.docs[index], context.temp_allocator) symbol.comment = get_comment(value.comments[index]) + symbol.doc = construct_symbol_docs(symbol.doc, symbol.comment) symbol.signature = get_bit_field_field_signature(value, index) + //build_bit_field_field_documentation(symbol, value, index) } construct_enum_field_symbol :: proc(symbol: ^Symbol, value: SymbolEnumValue, index: int) { diff --git a/src/server/types.odin b/src/server/types.odin index da3e142..78a7158 100644 --- a/src/server/types.odin +++ b/src/server/types.odin @@ -360,7 +360,6 @@ CompletionDocumention :: union { string, } -// test CompletionItem :: struct { label: string, kind: CompletionItemKind, |