aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-07 11:56:37 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-07 11:56:37 -0400
commit1c4a7bc3544d355bcd041a0673758bbf072a55f9 (patch)
tree2f864e545254acbbbdf8f8c567cc8731cdfcc947 /src/server
parentf9c23d7ec2841d8580fb55acd4fb26aaae8d605b (diff)
Remove incorrectly added doc comments from symbols
Diffstat (limited to 'src/server')
-rw-r--r--src/server/analysis.odin2
-rw-r--r--src/server/ast.odin32
-rw-r--r--src/server/collector.odin2
-rw-r--r--src/server/symbol.odin6
4 files changed, 25 insertions, 17 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 47722e8..fc5df05 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1861,7 +1861,7 @@ resolve_global_identifier :: proc(ast_context: ^AstContext, node: ast.Ident, glo
}
if global.docs != nil {
- return_symbol.doc = get_doc(global.docs, ast_context.allocator)
+ return_symbol.doc = get_doc(global.name_expr, global.docs, ast_context.allocator)
}
if global.comment != nil {
diff --git a/src/server/ast.odin b/src/server/ast.odin
index 326fd2d..04993d0 100644
--- a/src/server/ast.odin
+++ b/src/server/ast.odin
@@ -473,20 +473,28 @@ get_ast_node_string :: proc(node: ^ast.Node, src: string) -> string {
return string(src[node.pos.offset:node.end.offset])
}
-get_doc :: proc(comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string {
- if comment != nil {
- tmp: string
+get_doc :: proc(node: ^ast.Expr, comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string {
+ if comment == nil {
+ return ""
+ }
- for doc in comment.list {
- tmp = strings.concatenate({tmp, "\n", doc.text}, context.temp_allocator)
- }
+ // The odin parser currently incorrectly adds comments that are more than a line above
+ // the symbol as a doc comment. We do a quick check here to handle that specific case.
+ if node != nil && comment.list[len(comment.list)-1].pos.line < node.pos.line-1 {
+ return ""
+ }
- if tmp != "" {
- no_lines, _ := strings.replace_all(tmp, "//", "", context.temp_allocator)
- no_begin_comments, _ := strings.replace_all(no_lines, "/*", "", context.temp_allocator)
- no_end_comments, _ := strings.replace_all(no_begin_comments, "*/", "", context.temp_allocator)
- return strings.clone(no_end_comments, allocator)
- }
+ tmp: string
+
+ for doc in comment.list {
+ tmp = strings.concatenate({tmp, "\n", doc.text}, context.temp_allocator)
+ }
+
+ if tmp != "" {
+ no_lines, _ := strings.replace_all(tmp, "//", "", context.temp_allocator)
+ no_begin_comments, _ := strings.replace_all(no_lines, "/*", "", context.temp_allocator)
+ no_end_comments, _ := strings.replace_all(no_begin_comments, "*/", "", context.temp_allocator)
+ return strings.clone(no_end_comments, allocator)
}
return ""
diff --git a/src/server/collector.odin b/src/server/collector.odin
index c06879d..eaf1229 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -644,7 +644,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.range = common.get_token_range(expr.name_expr, file.src)
symbol.name = get_index_unique_string(collection, name)
symbol.type = token_type
- symbol.doc = get_doc(expr.docs, collection.allocator)
+ symbol.doc = get_doc(expr.name_expr, expr.docs, collection.allocator)
symbol.uri = get_index_unique_string(collection, uri)
comment, _ := get_file_comment(file, symbol.range.start.line + 1)
symbol.comment = strings.clone(get_comment(comment), collection.allocator)
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index a41a310..147626b 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -787,7 +787,7 @@ construct_struct_field_symbol :: proc(symbol: ^Symbol, parent_name: string, valu
symbol.name = value.names[index]
symbol.pkg = parent_name
symbol.type = .Field
- symbol.doc = get_doc(value.docs[index], context.temp_allocator)
+ symbol.doc = get_doc(value.types[index], value.docs[index], context.temp_allocator)
symbol.comment = get_comment(value.comments[index])
}
@@ -797,14 +797,14 @@ construct_bit_field_field_symbol :: proc(symbol: ^Symbol, parent_name: string, v
symbol.name = value.names[index]
symbol.pkg = parent_name
symbol.type = .Field
- symbol.doc = get_doc(value.docs[index], context.temp_allocator)
+ symbol.doc = get_doc(value.types[index], value.docs[index], context.temp_allocator)
symbol.comment = get_comment(value.comments[index])
symbol.signature = get_bit_field_field_signature(value, index)
}
construct_enum_field_symbol :: proc(symbol: ^Symbol, value: SymbolEnumValue, index: int) {
symbol.type = .Field
- symbol.doc = get_doc(value.docs[index], context.temp_allocator)
+ symbol.doc = get_doc(nil, value.docs[index], context.temp_allocator)
symbol.comment = get_comment(value.comments[index])
symbol.signature = get_enum_field_signature(value, index)
}