aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-30 16:13:43 -0400
committerGitHub <noreply@github.com>2025-07-30 16:13:43 -0400
commit0e4157ebfd357e5fdb181408185cca42dcd24047 (patch)
treecc475bdef8b8b5dab1375e8b303e28f6a6b9a825 /src/server
parent97e83b6c825b451c44bdee207e9521bf2cc9c7a5 (diff)
parent72e564940b4c08598b7f0da78e0df586b58861e0 (diff)
Merge pull request #806 from BradLewis/feat/add-poly-params-union-documentation
Add parapoly information to union documentation
Diffstat (limited to 'src/server')
-rw-r--r--src/server/analysis.odin1
-rw-r--r--src/server/completion.odin3
-rw-r--r--src/server/documentation.odin94
-rw-r--r--src/server/generics.odin6
-rw-r--r--src/server/symbol.odin5
5 files changed, 69 insertions, 40 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index f483a75..81fe560 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -3151,6 +3151,7 @@ make_symbol_union_from_ast :: proc(
symbol.value = SymbolUnionValue {
types = types[:],
+ poly = v.poly_params,
}
if v.poly_params != nil {
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 5bf2e88..cc0bdbb 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -1445,6 +1445,9 @@ get_identifier_completion :: proc(
if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 {
symbol.type_name = symbol.name
symbol.type_pkg = symbol.pkg
+ if symbol.type == .Variable {
+ symbol.pkg = ast_context.document_package
+ }
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 17d0204..6518006 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -209,11 +209,13 @@ get_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string {
append_type_information(&sb, ast_context, symbol, pointer_prefix)
strings.write_string(&sb, " :: ")
}
+ strings.write_string(&sb, "union")
+ write_poly_list(&sb, v.poly, v.poly_names)
if len(v.types) == 0 {
- strings.write_string(&sb, "union {}")
+ strings.write_string(&sb, " {}")
return strings.to_string(sb)
}
- strings.write_string(&sb, "union {\n")
+ strings.write_string(&sb, " {\n")
for i in 0 ..< len(v.types) {
strings.write_string(&sb, "\t")
build_string_node(v.types[i], &sb, false)
@@ -348,18 +350,24 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string
sb := strings.builder_make(ast_context.allocator)
if show_type_info {
append_type_information(&sb, ast_context, symbol, pointer_prefix)
+ write_poly_list(&sb, v.poly, v.poly_names)
} else {
strings.write_string(&sb, pointer_prefix)
- strings.write_string(&sb, "struct {..}")
+ strings.write_string(&sb, "struct")
+ write_poly_list(&sb, v.poly, v.poly_names)
+ strings.write_string(&sb, " {..}")
}
return strings.to_string(sb)
case SymbolUnionValue:
sb := strings.builder_make(ast_context.allocator)
if show_type_info {
append_type_information(&sb, ast_context, symbol, pointer_prefix)
+ write_poly_list(&sb, v.poly, v.poly_names)
} else {
strings.write_string(&sb, pointer_prefix)
- strings.write_string(&sb, "union {..}")
+ strings.write_string(&sb, "union")
+ write_poly_list(&sb, v.poly, v.poly_names)
+ strings.write_string(&sb, " {..}")
}
return strings.to_string(sb)
case SymbolBitFieldValue:
@@ -546,36 +554,7 @@ write_struct_hover :: proc(ast_context: ^AstContext, sb: ^strings.Builder, v: Sy
using_index := -1
strings.write_string(sb, "struct")
- poly_name_index := 0
- if v.poly != nil {
- strings.write_string(sb, "(")
- for field, i in v.poly.list {
- write_type := true
- for name, j in field.names {
- if poly_name_index < len(v.poly_names) {
- poly_name := v.poly_names[poly_name_index]
- if !strings.starts_with(poly_name, "$") {
- write_type = false
- }
- strings.write_string(sb, poly_name)
- } else {
- build_string_node(name, sb, false)
- }
- if j != len(field.names) - 1 {
- strings.write_string(sb, ", ")
- }
- poly_name_index += 1
- }
- if write_type {
- strings.write_string(sb, ": ")
- build_string_node(field.type, sb, false)
- }
- if i != len(v.poly.list) - 1 {
- strings.write_string(sb, ", ")
- }
- }
- strings.write_string(sb, ")")
- }
+ write_poly_list(sb, v.poly, v.poly_names)
strings.write_string(sb, " {\n")
for i in 0 ..< len(v.names) {
@@ -612,6 +591,39 @@ write_struct_hover :: proc(ast_context: ^AstContext, sb: ^strings.Builder, v: Sy
strings.write_string(sb, "}")
}
+write_poly_list :: proc(sb: ^strings.Builder, poly: ^ast.Field_List, poly_names: []string) {
+ if poly != nil {
+ poly_name_index := 0
+ strings.write_string(sb, "(")
+ for field, i in poly.list {
+ write_type := true
+ for name, j in field.names {
+ if poly_name_index < len(poly_names) {
+ poly_name := poly_names[poly_name_index]
+ if !strings.starts_with(poly_name, "$") {
+ write_type = false
+ }
+ strings.write_string(sb, poly_name)
+ } else {
+ build_string_node(name, sb, false)
+ }
+ if j != len(field.names) - 1 {
+ strings.write_string(sb, ", ")
+ }
+ poly_name_index += 1
+ }
+ if write_type {
+ strings.write_string(sb, ": ")
+ build_string_node(field.type, sb, false)
+ }
+ if i != len(poly.list) - 1 {
+ strings.write_string(sb, ", ")
+ }
+ }
+ strings.write_string(sb, ")")
+ }
+}
+
append_type_information :: proc(
sb: ^strings.Builder,
ast_context: ^AstContext,
@@ -619,7 +631,7 @@ append_type_information :: proc(
pointer_prefix: string,
) {
pkg_name := get_pkg_name(ast_context, symbol.type_pkg)
- if pkg_name == "" {
+ if pkg_name == "" || pkg_name == "$builtin"{
fmt.sbprintf(sb, "%s%s", pointer_prefix, symbol.type_name)
return
}
@@ -674,11 +686,14 @@ concatenate_raw_symbol_information :: proc(ast_context: ^AstContext, symbol: Sym
strings.write_string(&sb, ")\n")
}
- fmt.sbprintf(&sb, "%v.%v", pkg, symbol.name)
+ if pkg != "" && pkg != "$builtin" {
+ fmt.sbprintf(&sb, "%v.", pkg)
+ }
+ fmt.sbprintf(&sb, "%v", symbol.name)
if symbol.signature != "" {
fmt.sbprintf(&sb, ": %v", symbol.signature)
}
- return strings.to_string(sb)
+ return strings.to_string(sb)
}
return concatenate_raw_string_information(
@@ -703,7 +718,10 @@ concatenate_raw_string_information :: proc(
return fmt.tprintf("%v: package", name)
}
sb := strings.builder_make()
- fmt.sbprintf(&sb, "%v.%v", pkg, name)
+ if pkg != "" && pkg != "$builtin" {
+ fmt.sbprintf(&sb, "%v.", pkg)
+ }
+ fmt.sbprintf(&sb, "%v", name)
if signature != "" {
fmt.sbprintf(&sb, ": %v", signature)
}
diff --git a/src/server/generics.odin b/src/server/generics.odin
index 2cb1f5c..1802efb 100644
--- a/src/server/generics.odin
+++ b/src/server/generics.odin
@@ -787,9 +787,11 @@ resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_Lis
i := 0
poly_map := make(map[string]^ast.Expr, 0, context.temp_allocator)
+ poly_names := make([dynamic]string, 0, context.temp_allocator)
for param in poly_params.list {
for name in param.names {
+ append(&poly_names, node_to_string(name))
if len(ast_context.call.args) <= i {
break
}
@@ -801,9 +803,11 @@ resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_Lis
if poly, ok := param.type.derived.(^ast.Typeid_Type); ok {
if ident, ok := name.derived.(^ast.Ident); ok {
poly_map[ident.name] = ast_context.call.args[i]
+ poly_names[i] = node_to_string(ast_context.call.args[i])
} else if poly, ok := name.derived.(^ast.Poly_Type); ok {
if poly.type != nil {
poly_map[poly.type.name] = ast_context.call.args[i]
+ poly_names[i] = node_to_string(ast_context.call.args[i])
}
}
}
@@ -831,4 +835,6 @@ resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_Lis
}
}
}
+
+ symbol_value.poly_names = poly_names[:]
}
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index dc6b126..7700362 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -80,8 +80,9 @@ SymbolEnumValue :: struct {
}
SymbolUnionValue :: struct {
- types: []^ast.Expr,
- poly: ^ast.Field_List,
+ types: []^ast.Expr,
+ poly: ^ast.Field_List,
+ poly_names: []string,
}
SymbolDynamicArrayValue :: struct {