diff options
| -rw-r--r-- | src/server/completion.odin | 7 | ||||
| -rw-r--r-- | src/server/hover.odin | 7 | ||||
| -rw-r--r-- | src/server/locals.odin | 2 | ||||
| -rw-r--r-- | src/server/symbol.odin | 17 | ||||
| -rw-r--r-- | tests/hover_test.odin | 17 |
5 files changed, 38 insertions, 12 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index 262ba3f..4f36d6e 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1658,12 +1658,7 @@ get_identifier_completion :: proc( if symbol, ok := resolve_type_identifier(ast_context, ident^); ok { if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 { - symbol.type_name = symbol.name - symbol.type_pkg = symbol.pkg - if symbol.type == .Variable { - symbol.pkg = ast_context.document_package - } - symbol.name = clean_ident(ident.name) + construct_ident_symbol_info(&symbol, ident, ast_context.document_package) append(results, CompletionResult{score = score * 1.7, symbol = symbol}) } } diff --git a/src/server/hover.odin b/src/server/hover.odin index 844c64a..e76cf1f 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -433,12 +433,7 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { - resolved.type_name = resolved.name - resolved.type_pkg = resolved.pkg - resolved.name = ident.name - if resolved.type == .Variable { - resolved.pkg = ast_context.document_package - } + construct_ident_symbol_info(&resolved, &ident, ast_context.document_package) build_documentation(&ast_context, &resolved, false) hover.contents = write_hover_content(&ast_context, resolved) diff --git a/src/server/locals.odin b/src/server/locals.odin index c913ab1..b9ba308 100644 --- a/src/server/locals.odin +++ b/src/server/locals.odin @@ -399,6 +399,8 @@ get_locals_stmt :: proc( get_locals_stmt(file, v.body, ast_context, document_position) case ^Case_Clause: get_locals_case_clause(file, v, ast_context, document_position) + case ^ast.Defer_Stmt: + get_locals_stmt(file, v.stmt, ast_context, document_position) case: //log.debugf("default node local stmt %v", v); } diff --git a/src/server/symbol.odin b/src/server/symbol.odin index e87cb70..3384d3b 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -873,3 +873,20 @@ construct_enum_field_symbol :: proc(symbol: ^Symbol, value: SymbolEnumValue, ind symbol.comment = get_comment(value.comments[index]) symbol.signature = get_enum_field_signature(value, index) } + +// Adds name and type information to the symbol when it's for an identifier +construct_ident_symbol_info :: proc(symbol: ^Symbol, ident: ^ast.Ident, document_pkg: string) { + symbol.type_name = symbol.name + symbol.type_pkg = symbol.pkg + symbol.name = clean_ident(ident.name) + if symbol.type == .Variable { + symbol.pkg = document_pkg + } + + // If the pkg + name is the same as the type pkg + name, we use the underlying type instead + // This is used for things like anonymous structs + if symbol.name == symbol.type_name && symbol.pkg == symbol.type_pkg { + symbol.type_name = "" + symbol.type_pkg = "" + } +} diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 9001300..adddb89 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -4400,6 +4400,23 @@ ast_hover_ternary :: proc(t: ^testing.T) { } test.expect_hover(t, &source, "test.foo: int") } + +@(test) +ast_hover_defer_statement :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + foo :: proc() { + defer { + s{*}: struct { + bar: int, + } + } + } + ` + } + test.expect_hover(t, &source, "test.s: struct {\n\tbar: int,\n}") +} /* Waiting for odin fix |