aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-11-04 19:16:56 +0100
committerDaniel Gavin <danielgavin5@hotmail.com>2022-11-04 19:16:56 +0100
commit40fdad6b5a2ffddc464cc8ebc4e560cdfd77924d (patch)
tree79ed2264c76bde2a614ccb48315570c7a3b4fd28
parent79b34ae986c713f7786f7f89575330fc40044d6e (diff)
Fix completion on call expr that return structs
-rw-r--r--src/server/completion.odin11
-rw-r--r--tests/completions_test.odin25
2 files changed, 31 insertions, 5 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin
index e8c3a4a..7c3b397 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -100,7 +100,7 @@ get_completion_list :: proc(
if position_context.import_stmt != nil {
completion_type = .Package
}
-
+
done: if position_context.switch_type_stmt != nil &&
position_context.case_clause != nil {
@@ -130,7 +130,7 @@ get_completion_list :: proc(
if position_context.basic_lit != nil {
if _, ok := position_context.basic_lit.derived.(^ast.Basic_Lit); ok {
return list, true
- }
+ }
}
switch completion_type {
@@ -295,7 +295,8 @@ get_selector_completion :: proc(
if selector.type != .Variable &&
selector.type != .Package &&
- selector.type != .Enum {
+ selector.type != .Enum &&
+ selector.type != .Function {
return
}
@@ -1042,8 +1043,8 @@ get_identifier_completion :: proc(
if position_context.identifier != nil {
if ident, ok := position_context.identifier.derived.(^ast.Ident); ok {
lookup_name = ident.name
- }
- }
+ }
+ }
pkgs := make([dynamic]string, context.temp_allocator)
diff --git a/tests/completions_test.odin b/tests/completions_test.odin
index 21b89a2..d8a5d82 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -2031,3 +2031,28 @@ ast_vector_with_matrix_mult :: proc(t: ^testing.T) {
test.expect_completion_details(t, &source, "", {"test.my_vector: [4]f32"})
}
+
+@(test)
+ast_completion_on_call_expr :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package main
+ My_Struct :: struct {
+ a: int,
+ b: int,
+ }
+
+ my_function :: proc() -> My_Struct {}
+
+ main :: proc() {
+ my_function().{*}
+ }
+ `,
+ }
+
+ test.expect_completion_details(
+ t,
+ &source,
+ ".",
+ {"My_Struct.a: int", "My_Struct.b: int"},
+ )
+}