aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-18 14:37:46 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-24 08:55:23 -0400
commite239a9a74e732d91cc3e7e1c4b2dc68da1f2cb4c (patch)
treebb993d953e9bc62ab23ae79facd7bb7ecc7642bd /src
parentebbb1f9aabd238a9ca2801bb8147aded8da4bb9f (diff)
Ignore `any` arg types
Diffstat (limited to 'src')
-rw-r--r--src/server/completion.odin140
1 files changed, 80 insertions, 60 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 2dbb9cc..0b00f5b 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -154,13 +154,41 @@ get_completion_list :: proc(
}
}
- arg_symbol: Maybe(Symbol)
+ arg_symbol := get_target_symbol(&ast_context, &position_context)
+ results := make([dynamic]CompletionResult, 0, allocator = context.temp_allocator)
+ is_incomplete := false
+
+ // TODO: as these are mutally exclusive, should probably just make them return a slice?
+ switch completion_type {
+ case .Comp_Lit:
+ is_incomplete = get_comp_lit_completion(&ast_context, &position_context, &results)
+ case .Identifier:
+ is_incomplete = get_identifier_completion(&ast_context, &position_context, &results)
+ case .Implicit:
+ is_incomplete = get_implicit_completion(&ast_context, &position_context, &results)
+ case .Selector:
+ is_incomplete = get_selector_completion(&ast_context, &position_context, &results)
+ case .Switch_Type:
+ is_incomplete = get_type_switch_completion(&ast_context, &position_context, &results)
+ case .Directive:
+ is_incomplete = get_directive_completion(&ast_context, &position_context, &results)
+ case .Package:
+ is_incomplete = get_package_completion(&ast_context, &position_context, &results)
+ }
+
+ items := convert_completion_results(&ast_context, &position_context, results[:], completion_type, arg_symbol)
+ list.items = items
+ list.isIncomplete = is_incomplete
+ return list, true
+}
+
+get_target_symbol :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext) -> Maybe(Symbol) {
if position_context.call != nil {
if call, ok := position_context.call.derived.(^ast.Call_Expr); ok {
- if call_symbol, ok := resolve_type_expression(&ast_context, call.expr); ok {
+ if call_symbol, ok := resolve_type_expression(ast_context, call.expr); ok {
if value, ok := call_symbol.value.(SymbolProcedureValue); ok {
- if param_index, ok := find_position_in_call_param(&position_context, call^); ok {
+ if param_index, ok := find_position_in_call_param(position_context, call^); ok {
if arg_type, arg_type_ok := get_proc_arg_type_from_index(value, param_index); ok {
if position_context.field_value != nil {
// we are using a named param so we want to ensure we use that type and not the
@@ -173,16 +201,16 @@ get_completion_list :: proc(
}
if arg_type != nil {
if arg_type.type != nil {
- if resolved_arg_symbol, ok := resolve_type_expression(&ast_context, arg_type.type);
+ if resolved_arg_symbol, ok := resolve_type_expression(ast_context, arg_type.type);
ok {
- arg_symbol = resolved_arg_symbol
+ return resolved_arg_symbol
}
} else if arg_type.default_value != nil {
if resolved_arg_symbol, ok := resolve_type_expression(
- &ast_context,
+ ast_context,
arg_type.default_value,
); ok {
- arg_symbol = resolved_arg_symbol
+ return resolved_arg_symbol
}
}
}
@@ -192,32 +220,7 @@ get_completion_list :: proc(
}
}
}
-
- results := make([dynamic]CompletionResult, 0, allocator = context.temp_allocator)
- is_incomplete := false
-
- // TODO: as these are mutally exclusive, should probably just make them return a slice?
- switch completion_type {
- case .Comp_Lit:
- is_incomplete = get_comp_lit_completion(&ast_context, &position_context, &results)
- case .Identifier:
- is_incomplete = get_identifier_completion(&ast_context, &position_context, &results)
- case .Implicit:
- is_incomplete = get_implicit_completion(&ast_context, &position_context, &results)
- case .Selector:
- is_incomplete = get_selector_completion(&ast_context, &position_context, &results)
- case .Switch_Type:
- is_incomplete = get_type_switch_completion(&ast_context, &position_context, &results)
- case .Directive:
- is_incomplete = get_directive_completion(&ast_context, &position_context, &results)
- case .Package:
- is_incomplete = get_package_completion(&ast_context, &position_context, &results)
- }
-
- items := convert_completion_results(&ast_context, &position_context, results[:], completion_type, arg_symbol)
- list.items = items
- list.isIncomplete = is_incomplete
- return list, true
+ return nil
}
convert_completion_results :: proc(
@@ -315,33 +318,7 @@ convert_completion_results :: proc(
}
if s, ok := symbol.(Symbol); ok && (completion_type == .Selector || completion_type == .Identifier) {
- diff := result.symbol.pointers - s.pointers
- suffix := ""
- prefix := ""
- if diff > 0 {
- suffix = repeat("^", diff, context.temp_allocator)
- }
- if diff < 0 {
- prefix = "&"
- }
-
- if completion_type == .Identifier {
- item.insertText = fmt.tprint(prefix, item.label, suffix, sep = "")
- } else if completion_type == .Selector {
- item.insertText = fmt.tprint(item.label, suffix, sep = "")
- if prefix != "" {
- if range, ok := get_range_from_selection_start_to_dot(position_context); ok {
- prefix_edit := TextEdit {
- range = {start = range.start, end = range.start},
- newText = "&",
- }
-
- additionalTextEdits := make([]TextEdit, 1, context.temp_allocator)
- additionalTextEdits[0] = prefix_edit
- item.additionalTextEdits = additionalTextEdits
- }
- }
- }
+ handle_pointers(position_context, result.symbol, s, &item, completion_type)
}
if common.config.enable_label_details {
@@ -393,6 +370,49 @@ convert_completion_results :: proc(
return items[:]
}
+@(private = "file")
+handle_pointers :: proc(
+ position_context: ^DocumentPositionContext,
+ result_symbol: Symbol,
+ arg_symbol: Symbol,
+ item: ^CompletionItem,
+ completion_type: Completion_Type,
+) {
+ if v, ok := arg_symbol.value.(SymbolBasicValue); ok {
+ if v.ident.name == "any" {
+ return
+ }
+ }
+
+ diff := result_symbol.pointers - arg_symbol.pointers
+ suffix := ""
+ prefix := ""
+ if diff > 0 {
+ suffix = repeat("^", diff, context.temp_allocator)
+ }
+ if diff < 0 {
+ prefix = "&"
+ }
+
+ if completion_type == .Identifier {
+ item.insertText = fmt.tprint(prefix, item.label, suffix, sep = "")
+ } else if completion_type == .Selector {
+ item.insertText = fmt.tprint(item.label, suffix, sep = "")
+ if prefix != "" {
+ if range, ok := get_range_from_selection_start_to_dot(position_context); ok {
+ prefix_edit := TextEdit {
+ range = {start = range.start, end = range.start},
+ newText = "&",
+ }
+
+ additionalTextEdits := make([]TextEdit, 1, context.temp_allocator)
+ additionalTextEdits[0] = prefix_edit
+ item.additionalTextEdits = additionalTextEdits
+ }
+ }
+ }
+}
+
get_completion_details :: proc(ast_context: ^AstContext, symbol: Symbol) -> string {
#partial switch v in symbol.value {
case SymbolProcedureValue: