diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-12 14:37:06 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-12 16:16:06 -0400 |
| commit | 59f5f715f8720597134cafcbb2a26da43b21d370 (patch) | |
| tree | 8c422115e9afce1f3f95453eac4bed1d65e8873c /src/server | |
| parent | 82c8a0b2cb1373afeb9f87339cc3aaccdffb31ff (diff) | |
Update all short signatures to be consistent across types
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/ast.odin | 38 | ||||
| -rw-r--r-- | src/server/documentation.odin | 117 | ||||
| -rw-r--r-- | src/server/hover.odin | 2 |
3 files changed, 112 insertions, 45 deletions
diff --git a/src/server/ast.odin b/src/server/ast.odin index 81ec5c7..31d13b8 100644 --- a/src/server/ast.odin +++ b/src/server/ast.odin @@ -10,7 +10,6 @@ import path "core:path/slashpath" import "core:strings" keyword_map: map[string]bool = { - "typeid" = true, "int" = true, "uint" = true, "string" = true, @@ -68,6 +67,43 @@ keyword_map: map[string]bool = { "quaternion128" = true, "quaternion256" = true, "uintptr" = true, + // taken from https://github.com/odin-lang/Odin/wiki/Keywords-and-Operators + "asm" = true, + "auto_cast" = true, + "bit_field" = true, + "bit_set" = true, + "break" = true, + "case" = true, + "cast" = true, + "context" = true, + "continue" = true, + "defer" = true, + "distinct" = true, + "do" = true, + "dynamic" = true, + "else" = true, + "enum" = true, + "fallthrough" = true, + "for" = true, + "foreign" = true, + "if" = true, + "import" = true, + "in" = true, + "map" = true, + "not_in" = true, + "or_else" = true, + "or_return" = true, + "package" = true, + "proc" = true, + "return" = true, + "struct" = true, + "switch" = true, + "transmute" = true, + "typeid" = true, + "union" = true, + "using" = true, + "when" = true, + "where" = true, } GlobalExpr :: struct { diff --git a/src/server/documentation.odin b/src/server/documentation.odin index df0b523..5f24f7a 100644 --- a/src/server/documentation.odin +++ b/src/server/documentation.odin @@ -179,10 +179,14 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string } return strings.to_string(sb) case SymbolBitSetValue: - return strings.concatenate( - a = {pointer_prefix, "bit_set[", node_to_string(v.expr), "]"}, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%sbit_set[", pointer_prefix) + build_string_node(v.expr, &sb, false) + strings.write_string(&sb, "]") + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolEnumValue: sb := strings.builder_make(ast_context.allocator) if is_variable { @@ -190,14 +194,23 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string } else if symbol.type_name != "" { write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) } else { - strings.write_string(&sb, "enum") + strings.write_string(&sb, pointer_prefix) + strings.write_string(&sb, "enum {..}") + } + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) } return strings.to_string(sb) case SymbolMapValue: - return strings.concatenate( - a = {pointer_prefix, "map[", node_to_string(v.key), "]", node_to_string(v.value)}, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%smap[", pointer_prefix) + build_string_node(v.key, &sb, false) + strings.write_string(&sb, "]") + build_string_node(v.value, &sb, false) + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolProcedureValue: sb := strings.builder_make(ast_context.allocator) if symbol.type_pkg != "" && symbol.type_name != "" { @@ -215,7 +228,8 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string } else if symbol.type_name != "" { write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) } else { - strings.write_string(&sb, "struct") + strings.write_string(&sb, pointer_prefix) + strings.write_string(&sb, "struct {..}") } if symbol.comment != "" { fmt.sbprintf(&sb, " %s", symbol.comment) @@ -225,8 +239,14 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string 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) } else { - strings.write_string(&sb, "union") + strings.write_string(&sb, pointer_prefix) + strings.write_string(&sb, "union {..}") + } + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) } return strings.to_string(sb) case SymbolBitFieldValue: @@ -236,8 +256,9 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string } else if symbol.type_name != "" { write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix) } else { - strings.write_string(&sb, "bit_field ") + fmt.sbprintf(&sb, "%sbit_field ", pointer_prefix) build_string_node(v.backing_type, &sb, false) + strings.write_string(&sb, " {..}") } if symbol.comment != "" { fmt.sbprintf(&sb, " %s", symbol.comment) @@ -245,39 +266,51 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string return strings.to_string(sb) case SymbolMultiPointerValue: - return strings.concatenate( - a = {pointer_prefix, "[^]", node_to_string(v.expr)}, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%s[^]", pointer_prefix) + build_string_node(v.expr, &sb, false) + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolDynamicArrayValue: - return strings.concatenate( - a = {pointer_prefix, "[dynamic]", node_to_string(v.expr)}, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%s[dynamic]", pointer_prefix) + build_string_node(v.expr, &sb, false) + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolSliceValue: - return strings.concatenate( - a = {pointer_prefix, "[]", node_to_string(v.expr)}, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%s[]", pointer_prefix) + build_string_node(v.expr, &sb, false) + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolFixedArrayValue: - return strings.concatenate( - a = {pointer_prefix, "[", node_to_string(v.len), "]", node_to_string(v.expr)}, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%s[", pointer_prefix) + build_string_node(v.len, &sb, false) + strings.write_string(&sb, "]") + build_string_node(v.expr, &sb, false) + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolMatrixValue: - return strings.concatenate( - a = { - pointer_prefix, - "matrix", - "[", - node_to_string(v.x), - ",", - node_to_string(v.y), - "]", - node_to_string(v.expr), - }, - allocator = ast_context.allocator, - ) + sb := strings.builder_make(ast_context.allocator) + fmt.sbprintf(&sb, "%smatrix[", pointer_prefix) + build_string_node(v.x, &sb, false) + strings.write_string(&sb, ",") + build_string_node(v.y, &sb, false) + strings.write_string(&sb, "]") + build_string_node(v.expr, &sb, false) + if symbol.comment != "" { + fmt.sbprintf(&sb, " %s", symbol.comment) + } + return strings.to_string(sb) case SymbolPackageValue: return "package" case SymbolUntypedValue: @@ -518,7 +551,7 @@ concatenate_raw_string_information :: proc( // return name } else { sb := strings.builder_make() - if type == .Function && comment != "" { + if (type == .Function || type == .Type_Function) && comment != "" { fmt.sbprintf(&sb, "%s\n", comment) } fmt.sbprintf(&sb, "%v.%v", pkg, name) diff --git a/src/server/hover.odin b/src/server/hover.odin index 7044ad2..9d8519c 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -166,7 +166,6 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> position_context.value_decl.names[0], ); ok { if value, ok := struct_symbol.value.(SymbolStructValue); ok { - symbol.type = .Field symbol.range = common.get_token_range(field.node, ast_context.file.src) symbol.type_name = symbol.name symbol.type_pkg = symbol.pkg @@ -197,7 +196,6 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> position_context.value_decl.names[0], ); ok { if value, ok := bit_field_symbol.value.(SymbolBitFieldValue); ok { - symbol.type = .Field symbol.range = common.get_token_range(field.node, ast_context.file.src) symbol.type_name = symbol.name symbol.type_pkg = symbol.pkg |