diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-07 16:49:59 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-08 21:09:30 -0400 |
| commit | 0b0ed964435bdd5b89e8df525e20e86cc332f573 (patch) | |
| tree | de3664b608834728e2e3fc7004c345cea16f4aae | |
| parent | 6a10502edbc83373344ac252869a1e33e8032e0e (diff) | |
Remove completions when entering bit_field or struct field names
| -rw-r--r-- | src/server/completion.odin | 22 | ||||
| -rw-r--r-- | tests/completions_test.odin | 30 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index 88bdfdd..aceff60 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1661,6 +1661,28 @@ get_identifier_completion :: proc( lookup_name := "" is_incomplete := true + if position_context.value_decl != nil { + for value in position_context.value_decl.values { + if struct_type, ok := value.derived.(^ast.Struct_Type); ok { + if struct_type.fields != nil { + for field in struct_type.fields.list { + for name in field.names { + if position_in_node(name, position_context.position) { + return false + } + } + } + } + } else if bit_field_type, ok := value.derived.(^ast.Bit_Field_Type); ok { + for field in bit_field_type.fields { + if position_in_node(field.name, position_context.position) { + return false + } + } + } + } + } + if position_context.identifier != nil { if ident, ok := position_context.identifier.derived.(^ast.Ident); ok { lookup_name = ident.name diff --git a/tests/completions_test.odin b/tests/completions_test.odin index a2c6883..d3a2eb7 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -4668,3 +4668,33 @@ ast_completion_union_with_enums_from_package :: proc(t: ^testing.T) { {"my_package.Foo.A", "my_package.Foo.B", "my_package.Bar.A", "my_package.Bar.C"}, ) } + +@(test) +ast_completion_struct_field_name :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Foo :: struct{} + + Bar :: struct { + f{*} + } + `, + } + test.expect_completion_docs(t, &source, "", {}, {"test.Foo: struct {}"}) +} + +@(test) +ast_completion_struct_field_value :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Foo :: struct{} + + Bar :: struct { + foo: F{*} + } + `, + } + test.expect_completion_docs(t, &source, "", {"test.Foo: struct {}"}) +} |