diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-04-06 14:36:07 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-04-06 14:36:07 +0200 |
| commit | 7ca20296e16ab36c196140e34a47afea0a64b805 (patch) | |
| tree | f0312a2a103c61d2400b41bfb03ca5ee56ccf758 | |
| parent | 9652ef501f0085fd5e335427de95482625b2d1ea (diff) | |
Call expression should always increment the current argument counter, since argument 1 is always the struct type.
| -rw-r--r-- | src/server/completion.odin | 10 | ||||
| -rw-r--r-- | tests/objc_test.odin | 48 |
2 files changed, 56 insertions, 2 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index e09aa0a..eabac77 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1099,8 +1099,14 @@ get_implicit_completion :: proc( ok && parameter_ok { ast_context.current_package = symbol.pkg - if .ObjC in symbol.flags { - parameter_index += 1 + //Selector call expression always set the first argument to be the type of struct called, so increment it. + if position_context.selector_expr != nil { + if selector_call, ok := position_context.selector_expr.derived.(^ast.Selector_Call_Expr); + ok { + if selector_call.call == position_context.call { + parameter_index += 1 + } + } } if proc_value, ok := symbol.value.(SymbolProcedureValue); ok { diff --git a/tests/objc_test.odin b/tests/objc_test.odin index af17c0a..f86f331 100644 --- a/tests/objc_test.odin +++ b/tests/objc_test.odin @@ -144,3 +144,51 @@ cobj_hover_chained_selector :: proc(t: ^testing.T) { "Window.initWithContentRect: proc(self: ^Window, contentRect: Rect, styleMask: WindowStyleMask, backing: BackingStoreType, doDefer: BOOL)", ) } + +@(test) +cobj_hover_chained_selector :: proc(t: ^testing.T) { + packages := make([dynamic]test.Package) + + append( + &packages, + test.Package { + pkg = "my_package", + source = `package my_package + My_Enum :: enum { + Regular = 0, + Accessory = 1, + Prohibited = 2, + } + + @(objc_class="NSWindow") + Window :: struct { dummy: int} + + @(objc_type=Window, objc_name="alloc", objc_is_class_method=true) + Window_alloc :: proc "c" () -> ^Window { + } + @(objc_type=Window, objc_name="initWithContentRect") + Window_initWithContentRect :: proc (self: ^Window, my_enum: My_Enum) -> ^Window { + } + + My_Struct :: struct { + dummy: int, + } + `, + }, + ) + + source := test.Source { + main = `package test + import "my_package" + + main :: proc() { + window := my_package.Window.alloc()->initWithContentRect( + .{*} + ) + } + `, + packages = packages[:], + } + + test.expect_completion_labels(t, &source, ".", {"Accessory"}) +} |