diff options
| -rw-r--r-- | src/server/analysis.odin | 12 | ||||
| -rw-r--r-- | src/server/hover.odin | 37 | ||||
| -rw-r--r-- | tests/hover_test.odin | 52 |
3 files changed, 79 insertions, 22 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 0c3178a..2219b98 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -670,7 +670,19 @@ get_proc_call_argument_type :: proc(value: SymbolProcedureValue, parameter_index index += 1 } } + return nil, false +} +get_proc_arg_type_from_name :: proc(v: SymbolProcedureValue, name: string) -> (^ast.Field, bool) { + for arg in v.arg_types { + for arg_name in arg.names { + if ident, ok := arg_name.derived.(^ast.Ident); ok { + if name == ident.name { + return arg, true + } + } + } + } return nil, false } diff --git a/src/server/hover.odin b/src/server/hover.odin index 9d8519c..4843391 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -201,10 +201,8 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> symbol.type_pkg = symbol.pkg symbol.pkg = bit_field_symbol.name symbol.name = identifier.name - if value, ok := bit_field_symbol.value.(SymbolBitFieldValue); ok { - symbol.comment = get_comment(value.comments[i]) - symbol.doc = get_doc(value.docs[i], context.temp_allocator) - } + symbol.comment = get_comment(value.comments[i]) + symbol.doc = get_doc(value.docs[i], context.temp_allocator) symbol.signature = get_bit_field_field_signature(value, i) hover.contents = write_hover_content(&ast_context, symbol) return hover, true, true @@ -215,6 +213,37 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } } + + if position_context.call != nil { + // Check if we're resolving the name of a parameter being passed to a proc call + if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { + if proc_symbol, ok := resolve_type_expression(&ast_context, call); ok { + if value, ok := proc_symbol.value.(SymbolProcedureValue); ok { + for arg in call.args { + if field_value, ok := arg.derived.(^ast.Field_Value); ok { + if position_in_node(field_value.field, position_context.position) { + if identifier, ok := field_value.field.derived.(^ast.Ident); ok { + if arg_type, arg_type_ok := get_proc_arg_type_from_name(value, identifier.name); ok { + if symbol, ok := resolve_type_expression(&ast_context, arg_type.type); ok { + symbol.range = common.get_token_range(field_value.field, ast_context.file.src) + symbol.type_name = symbol.name + symbol.type_pkg = symbol.pkg + symbol.pkg = proc_symbol.name + symbol.name = identifier.name + symbol.signature = get_signature(&ast_context, symbol) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } + } + } + break + } + } + } + } + } + } } if position_context.field_value != nil && position_context.comp_lit != nil { diff --git a/tests/hover_test.odin b/tests/hover_test.odin index a69b494..ff22e43 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -2177,7 +2177,7 @@ ast_hover_bitset_enum :: proc(t: ^testing.T) { } `, } - test.expect_hover( t, &source, "test.Foo: .Aaa") + test.expect_hover(t, &source, "test.Foo: .Aaa") } @(test) @@ -2203,7 +2203,7 @@ ast_hover_enumerated_array_key :: proc(t: ^testing.T) { } `, } - test.expect_hover( t, &source, "test.Foo: .A") + test.expect_hover(t, &source, "test.Foo: .A") } @(test) @@ -2229,7 +2229,7 @@ ast_hover_enumerated_array_value :: proc(t: ^testing.T) { } `, } - test.expect_hover( t, &source, "test.Bar: struct {\n\tbar: int,\n}") + test.expect_hover(t, &source, "test.Bar: struct {\n\tbar: int,\n}") } @(test) @@ -2254,7 +2254,7 @@ ast_hover_struct_fields_when_not_specifying_type_at_use :: proc(t: ^testing.T) { } `, } - test.expect_hover( t, &source, "Bar.foo: Foo") + test.expect_hover(t, &source, "Bar.foo: Foo") } @(test) @@ -2278,7 +2278,7 @@ ast_hover_struct_field_value_when_not_specifying_type_at_use :: proc(t: ^testing } `, } - test.expect_hover( t, &source, "test.Foo: .B") + test.expect_hover(t, &source, "test.Foo: .B") } @(test) @@ -2344,7 +2344,7 @@ ast_hover_struct_field_should_show_docs_and_comments :: proc(t: ^testing.T) { } `, } - test.expect_hover( t, &source, "Foo.a: int // a comment\n a docs") + test.expect_hover(t, &source, "Foo.a: int // a comment\n a docs") } @(test) @@ -2358,7 +2358,7 @@ ast_hover_struct_field_should_show_docs_and_comments_field :: proc(t: ^testing.T } `, } - test.expect_hover( t, &source, "Foo.a: int // a comment\n a docs") + test.expect_hover(t, &source, "Foo.a: int // a comment\n a docs") } @(test) @@ -2379,7 +2379,7 @@ ast_hover_struct_field_should_show_docs_and_comments_struct_types :: proc(t: ^te } `, } - test.expect_hover( t, &source, "Foo.bar: test.Bar // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: test.Bar // bar comment\n bar docs") } @(test) @@ -2398,7 +2398,7 @@ ast_hover_struct_field_should_show_docs_and_comments_procs :: proc(t: ^testing.T } `, } - test.expect_hover( t, &source, "// bar comment\nFoo.bar: proc(a: int) -> int\n bar docs") + test.expect_hover(t, &source, "// bar comment\nFoo.bar: proc(a: int) -> int\n bar docs") } @(test) @@ -2419,7 +2419,7 @@ ast_hover_struct_field_should_show_docs_and_comments_named_procs :: proc(t: ^tes } `, } - test.expect_hover( t, &source, "// bar comment\nFoo.bar: proc(a: int) -> string\n bar docs") + test.expect_hover(t, &source, "// bar comment\nFoo.bar: proc(a: int) -> string\n bar docs") } @(test) @@ -2438,7 +2438,7 @@ ast_hover_struct_field_should_show_docs_and_comments_maps :: proc(t: ^testing.T) } `, } - test.expect_hover( t, &source, "Foo.bar: map[int]int // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: map[int]int // bar comment\n bar docs") } @(test) @@ -2457,7 +2457,7 @@ ast_hover_struct_field_should_show_docs_and_comments_bit_sets :: proc(t: ^testin } `, } - test.expect_hover( t, &source, "Foo.bar: bit_set[0 ..< 10] // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: bit_set[0 ..< 10] // bar comment\n bar docs") } @(test) @@ -2481,7 +2481,7 @@ ast_hover_struct_field_should_show_docs_and_comments_unions :: proc(t: ^testing. } `, } - test.expect_hover( t, &source, "Foo.bar: test.Bar // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: test.Bar // bar comment\n bar docs") } @(test) @@ -2500,7 +2500,7 @@ ast_hover_struct_field_should_show_docs_and_comments_multipointers :: proc(t: ^t } `, } - test.expect_hover( t, &source, "Foo.bar: [^]int // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: [^]int // bar comment\n bar docs") } @(test) @@ -2519,7 +2519,7 @@ ast_hover_struct_field_should_show_docs_and_comments_dynamic_arrays :: proc(t: ^ } `, } - test.expect_hover( t, &source, "Foo.bar: [dynamic]int // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: [dynamic]int // bar comment\n bar docs") } @(test) @@ -2538,7 +2538,7 @@ ast_hover_struct_field_should_show_docs_and_comments_fixed_arrays :: proc(t: ^te } `, } - test.expect_hover( t, &source, "Foo.bar: [5]int // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: [5]int // bar comment\n bar docs") } @(test) @@ -2557,7 +2557,7 @@ ast_hover_struct_field_should_show_docs_and_comments_matrix :: proc(t: ^testing. } `, } - test.expect_hover( t, &source, "Foo.bar: matrix[4,5]int // bar comment\n bar docs") + test.expect_hover(t, &source, "Foo.bar: matrix[4,5]int // bar comment\n bar docs") } @(test) @@ -2580,7 +2580,23 @@ ast_hover_variable_from_comparison :: proc(t: ^testing.T) { } `, } - test.expect_hover( t, &source, "test.bazz: bool") + test.expect_hover(t, &source, "test.bazz: bool") +} + +@(test) +ast_hover_named_parameter_same_as_variable :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + foo :: proc(a: int) {} + + main :: proc() { + a := "hellope" + foo(a{*} = 0) + } + `, + } + test.expect_hover(t, &source, "foo.a: int") } /* |