aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-28 18:23:47 -0400
committerGitHub <noreply@github.com>2025-08-28 18:23:47 -0400
commit9f911012c3496fdc5e56733f0e7e52229ec37726 (patch)
treea56915f8fc0a253cc562e5b7b5acbe629a72445a /src
parent95adee92d78ba24478ed4be2c7b6e5b4212c7581 (diff)
parentff7f24adedf39fbd69a68a7bf691277d34d1e638 (diff)
Merge pull request #942 from BradLewis/feat/parse-defer-statements
Process defer statements and correct hover info for anonymous types
Diffstat (limited to 'src')
-rw-r--r--src/server/completion.odin7
-rw-r--r--src/server/hover.odin7
-rw-r--r--src/server/locals.odin2
-rw-r--r--src/server/symbol.odin17
4 files changed, 21 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 = ""
+ }
+}