diff options
| -rw-r--r-- | src/server/analysis.odin | 16 | ||||
| -rw-r--r-- | src/server/completion.odin | 3 | ||||
| -rw-r--r-- | src/server/documents.odin | 2 | ||||
| -rw-r--r-- | tests/completions_test.odin | 59 |
4 files changed, 46 insertions, 34 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e3857c1..45e2e74 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1698,13 +1698,10 @@ resolve_comp_literal :: proc( } else if position_context.call != nil { if call_expr, ok := position_context.call.derived.(^ast.Call_Expr); ok { - arg_index := 0 - for arg, i in call_expr.args { - if position_in_node(arg, position_context.position) { - arg_index = i - break - } - } + arg_index := find_position_in_call_param( + position_context, + call_expr^, + ) or_return symbol = resolve_type_expression( ast_context, @@ -1728,6 +1725,9 @@ resolve_comp_literal :: proc( } } + old_package := ast_context.current_package + ast_context.current_package = symbol.pkg + symbol, _ = resolve_type_comp_literal( ast_context, position_context, @@ -1735,6 +1735,8 @@ resolve_comp_literal :: proc( position_context.parent_comp_lit, ) or_return + ast_context.current_package = old_package + return symbol, true } diff --git a/src/server/completion.odin b/src/server/completion.odin index eb83432..c10a48b 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -233,7 +233,7 @@ get_comp_lit_completion :: proc( } ast_context.current_package = symbol.pkg - + if resolved, ok := resolve_type_expression( ast_context, v.types[i], @@ -1128,6 +1128,7 @@ get_implicit_completion :: proc( ast_context, proc_value.arg_types[parameter_index].type, ); ok { + ast_context.current_package = bitset_symbol.pkg if enum_value, ok := unwrap_bitset( ast_context, bitset_symbol, diff --git a/src/server/documents.odin b/src/server/documents.odin index e2cc322..7b3cba4 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -284,8 +284,6 @@ document_apply_changes :: proc( } } - //log.info(string(document.text[:document.used_text])); - return document_refresh(document, config, writer) } diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 962e944..b17605d 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -2302,8 +2302,6 @@ ast_bitset_assignment_diff_pkg :: proc(t: ^testing.T) { @(test) ast_local_global_function :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package main import "my_package" @@ -2333,8 +2331,6 @@ ast_local_global_function :: proc(t: ^testing.T) { @(test) ast_generic_struct_with_array :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package main Test :: struct($T: typeid) { @@ -2360,8 +2356,6 @@ ast_generic_struct_with_array :: proc(t: ^testing.T) { @(test) ast_assign_to_global_function :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test import "my_package" @@ -2383,8 +2377,6 @@ ast_assign_to_global_function :: proc(t: ^testing.T) { @(test) ast_poly_dynamic_type :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test import "my_package" @@ -2413,8 +2405,6 @@ ast_poly_dynamic_type :: proc(t: ^testing.T) { @(test) ast_poly_array_type :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test import "my_package" @@ -2438,8 +2428,6 @@ ast_poly_array_type :: proc(t: ^testing.T) { @(test) ast_poly_struct_with_poly :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test Small_Array :: struct($N: int, $T: typeid) where N >= 0 { @@ -2471,8 +2459,6 @@ ast_poly_struct_with_poly :: proc(t: ^testing.T) { @(test) ast_poly_proc_array_constant :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test make_f32_array :: proc($N: int, $val: f32) -> (res: [N]f32) { @@ -2496,8 +2482,6 @@ ast_poly_proc_array_constant :: proc(t: ^testing.T) { @(test) ast_poly_proc_matrix_type :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test @@ -2521,8 +2505,6 @@ ast_poly_proc_matrix_type :: proc(t: ^testing.T) { @(test) ast_poly_proc_matrix_constant_array :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test @@ -2545,8 +2527,6 @@ ast_poly_proc_matrix_constant_array :: proc(t: ^testing.T) { @(test) ast_poly_proc_matrix_constant_array_2 :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test array_cast :: proc "contextless" ( @@ -2574,8 +2554,6 @@ ast_poly_proc_matrix_constant_array_2 :: proc(t: ^testing.T) { @(test) ast_poly_proc_matrix_whole :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test @@ -2610,8 +2588,6 @@ ast_poly_proc_matrix_whole :: proc(t: ^testing.T) { ast_completion_comp_lit_in_proc :: proc(t: ^testing.T) { - packages := make([dynamic]test.Package) - source := test.Source { main = `package test My_Struct :: struct { @@ -2632,3 +2608,38 @@ ast_completion_comp_lit_in_proc :: proc(t: ^testing.T) { test.expect_completion_details(t, &source, "", {"My_Struct.one: int"}) } + + +ast_completion_infer_bitset_package :: proc(t: ^testing.T) { + packages := make([dynamic]test.Package) + + + append( + &packages, + test.Package { + pkg = "my_package", + source = `package my_package + My_Enum :: enum { + ONE, + TWO, + } + My_Bitset :: bit_set[My_Enum] + `, + }, + ) + + source := test.Source { + main = `package test + import "my_package" + + my_function :: proc(my_bitset: my_package.My_Bitset) + + main :: proc() { + my_function({.{*}}) + } + `, + packages = packages[:], + } + + test.expect_completion_labels(t, &source, ".", {"ONE", "TWO"}) +} |