Skip to content

Commit

Permalink
Fix issues with bitsets in procedures not completing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Mar 18, 2024
1 parent 207fe98 commit ff6d5c9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 34 deletions.
16 changes: 9 additions & 7 deletions src/server/analysis.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1728,13 +1725,18 @@ 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,
symbol,
position_context.parent_comp_lit,
) or_return

ast_context.current_package = old_package

return symbol, true
}

Expand Down
3 changes: 2 additions & 1 deletion src/server/completion.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/server/documents.odin
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ document_apply_changes :: proc(
}
}

//log.info(string(document.text[:document.used_text]));

return document_refresh(document, config, writer)
}

Expand Down
59 changes: 35 additions & 24 deletions tests/completions_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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" (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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"})
}

0 comments on commit ff6d5c9

Please sign in to comment.