aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-30 19:20:52 -0400
committerGitHub <noreply@github.com>2025-08-30 19:20:52 -0400
commit2ec8e676dc375e951f89f9d679adfd485b247d3c (patch)
treea320079abb49e191c49ab560247886103b13da4c
parentaae20c2190e619715b9f9a55e757d50c2d517cd7 (diff)
parent16ff934662bc9286549df938d205175d183a2ede (diff)
Merge pull request #946 from BradLewis/feat/pointer-matching-with-overloaded-procs
When resolving locals, don't resolve all possibilities for overloaded procs
-rw-r--r--src/server/analysis.odin11
-rw-r--r--src/server/locals.odin3
-rw-r--r--tests/completions_test.odin38
3 files changed, 50 insertions, 2 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 9afdbc2..544ad6e 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -45,6 +45,7 @@ AstContext :: struct {
non_mutable_only: bool, //Only store local value declarations that are non mutable.
overloading: bool,
position_hint: DocumentPositionContextHint,
+ resolving_locals: bool,
}
make_ast_context :: proc(
@@ -621,8 +622,14 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou
ast_context.overloading = false
}
- resolve_all_possibilities :=
- ast_context.position_hint == .Completion || ast_context.position_hint == .SignatureHelp || call_expr == nil
+ resolve_all_possibilities: bool
+ if ast_context.resolving_locals {
+ resolve_all_possibilities = false
+ } else {
+ resolve_all_possibilities =
+ ast_context.position_hint == .Completion || ast_context.position_hint == .SignatureHelp || call_expr == nil
+ }
+
call_unnamed_arg_count := 0
if call_expr != nil {
diff --git a/src/server/locals.odin b/src/server/locals.odin
index ac577b1..267a2a2 100644
--- a/src/server/locals.odin
+++ b/src/server/locals.odin
@@ -1026,6 +1026,9 @@ get_locals :: proc(
ast_context: ^AstContext,
document_position: ^DocumentPositionContext,
) {
+ ast_context.resolving_locals = true
+ defer ast_context.resolving_locals = false
+
proc_lit, ok := function.derived.(^ast.Proc_Lit)
if !ok || proc_lit.body == nil {
diff --git a/tests/completions_test.odin b/tests/completions_test.odin
index b31f082..a19ab22 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -4561,3 +4561,41 @@ ast_completion_proc_bit_set_comp_lit_default_param_with_no_type :: proc(t: ^test
{"A", "B"},
)
}
+
+@(test)
+ast_completion_handle_matching_from_overloaded_proc :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+
+ Foo :: struct {
+ a: int,
+ }
+
+ get_foo :: proc {
+ get_foo_none,
+ get_foo_a,
+ }
+
+ get_foo_none :: proc() -> Foo {
+ return Foo{}
+ }
+
+ get_foo_a :: proc(a: int) -> Foo {
+ return Foo{
+ a = a,
+ }
+ }
+
+ do_foo :: proc(foo: ^Foo) {}
+
+ main :: proc() {
+ foo := get_foo()
+ do_foo(f{*})
+ }
+ `,
+ config = {
+ enable_completion_matching = true,
+ },
+ }
+ test.expect_completion_insert_text(t, &source, "", {"&foo"})
+}