aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-29 19:50:55 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-29 19:50:55 -0400
commitf6a16912a968d4afc527b6784694085cd857626e (patch)
treed408fdbbcbba30629a44349d71a4ccd342bd3e4f
parentc9af6de66b4ab64ed65a9ea118db9036f4ea414d (diff)
Mark collected distinct symbols as distinct and improve hover information
-rw-r--r--src/server/collector.odin3
-rw-r--r--src/server/documentation.odin9
-rw-r--r--tests/hover_test.odin39
3 files changed, 48 insertions, 3 deletions
diff --git a/src/server/collector.odin b/src/server/collector.odin
index c59a46c..5888326 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -469,10 +469,12 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
col_expr = helper.type
}
}
+ is_distinct := false
if dist, ok := col_expr.derived.(^ast.Distinct_Type); ok {
if dist.type != nil {
col_expr = dist.type
+ is_distinct = true
}
}
@@ -612,6 +614,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.doc = get_doc(expr.docs, collection.allocator)
comment := get_file_comment(file, symbol.range.start.line + 1)
symbol.comment = strings.clone(get_comment(comment), collection.allocator)
+ symbol.flags |= {.Distinct}
if expr.builtin || strings.contains(uri, "builtin.odin") {
symbol.pkg = "$builtin"
diff --git a/src/server/documentation.odin b/src/server/documentation.odin
index b50a18d..3be174f 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -84,15 +84,18 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string
is_variable := symbol.type == .Variable
pointer_prefix := repeat("^", symbol.pointers, context.temp_allocator)
-
-
#partial switch v in symbol.value {
case SymbolBasicValue:
sb := strings.builder_make(ast_context.allocator)
if symbol.type_name != "" {
write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix)
} else if .Distinct in symbol.flags {
- fmt.sbprintf(&sb, "%s%s", pointer_prefix, symbol.name)
+ if symbol.type == .Keyword {
+ strings.write_string(&sb, "distinct ")
+ build_string_node(v.ident, &sb, false)
+ } else {
+ fmt.sbprintf(&sb, "%s%s", pointer_prefix, symbol.name)
+ }
} else {
strings.write_string(&sb, pointer_prefix)
build_string_node(v.ident, &sb, false)
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 32a37ad..84047c3 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -1549,6 +1549,45 @@ ast_hover_struct_field_distinct_external_package :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "S.fb: my_package.A")
}
+
+@(test)
+ast_hover_distinct_definition :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ A{*} :: distinct u64
+ `,
+ }
+
+ test.expect_hover(t, &source, "test.A: distinct u64")
+}
+
+@(test)
+ast_hover_distinct_definition_external_package :: proc(t: ^testing.T) {
+ packages := make([dynamic]test.Package, context.temp_allocator)
+
+ append(
+ &packages,
+ test.Package {
+ pkg = "my_package",
+ source = `package my_package
+
+ A :: distinct u64
+ `,
+ },
+ )
+ source := test.Source {
+ main = `package test
+ import "my_package"
+
+ Foo :: struct {
+ a: my_package.A{*},
+ }
+ `,
+ packages = packages[:],
+ }
+
+ test.expect_hover(t, &source, "my_package.A: distinct u64")
+}
/*
Waiting for odin fix