aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-07-29 12:57:25 +0200
committerGitHub <noreply@github.com>2024-07-29 12:57:25 +0200
commit9a33cc2fbe7e2dbc82a281af60f56e8232fe03d5 (patch)
tree87671e8933453d586e151c610a3e316ac0f2e7c0
parent03dfdacae8ef216d36bffe933ba7e6d0d2be6431 (diff)
parent75add788487b2a4a1b5069484b97818142555ed0 (diff)
Merge pull request #452 from thetarnav/correct-collecting-array-symbols
Correct collecting symbols for array types
-rw-r--r--src/server/collector.odin32
-rw-r--r--src/testing/testing.odin20
-rw-r--r--tests/hover_test.odin23
-rw-r--r--tests/objc_test.odin2
4 files changed, 49 insertions, 28 deletions
diff --git a/src/server/collector.odin b/src/server/collector.odin
index bdc69a6..92b4137 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -313,38 +313,38 @@ collect_slice :: proc(
collection: ^SymbolCollection,
array: ast.Array_Type,
package_map: map[string]string,
-) -> SymbolFixedArrayValue {
+) -> SymbolSliceValue {
elem := clone_type(
array.elem,
collection.allocator,
&collection.unique_strings,
)
- len := clone_type(
- array.len,
- collection.allocator,
- &collection.unique_strings,
- )
replace_package_alias(elem, package_map, collection)
- replace_package_alias(len, package_map, collection)
- return SymbolFixedArrayValue{expr = elem, len = len}
+ return SymbolSliceValue{expr = elem}
}
collect_array :: proc(
collection: ^SymbolCollection,
array: ast.Array_Type,
package_map: map[string]string,
-) -> SymbolSliceValue {
+) -> SymbolFixedArrayValue {
elem := clone_type(
array.elem,
collection.allocator,
&collection.unique_strings,
)
+ len := clone_type(
+ array.len,
+ collection.allocator,
+ &collection.unique_strings,
+ )
replace_package_alias(elem, package_map, collection)
+ replace_package_alias(len, package_map, collection)
- return SymbolSliceValue{expr = elem}
+ return SymbolFixedArrayValue{expr = elem, len = len}
}
collect_map :: proc(
@@ -610,7 +610,7 @@ collect_symbols :: proc(
#partial switch v in col_expr.derived {
case ^ast.Matrix_Type:
token = v^
- token_type = .Variable
+ token_type = .Type
symbol.value = collect_matrix(collection, v^, package_map)
case ^ast.Proc_Lit:
token = v^
@@ -636,7 +636,7 @@ collect_symbols :: proc(
}
case ^ast.Proc_Type:
token = v^
- token_type = .Function
+ token_type = .Type_Function
symbol.value = collect_procedure_fields(
collection,
cast(^ast.Proc_Type)col_expr,
@@ -706,11 +706,11 @@ collect_symbols :: proc(
symbol.signature = "bit_field"
case ^ast.Map_Type:
token = v^
- token_type = .Variable
+ token_type = .Type
symbol.value = collect_map(collection, v^, package_map)
case ^ast.Array_Type:
token = v^
- token_type = .Variable
+ token_type = .Type
if v.len == nil {
symbol.value = collect_slice(collection, v^, package_map)
} else {
@@ -718,11 +718,11 @@ collect_symbols :: proc(
}
case ^ast.Dynamic_Array_Type:
token = v^
- token_type = .Variable
+ token_type = .Type
symbol.value = collect_dynamic_array(collection, v^, package_map)
case ^ast.Multi_Pointer_Type:
token = v^
- token_type = .Variable
+ token_type = .Type
symbol.value = collect_multi_pointer(collection, v^, package_map)
case ^ast.Typeid_Type:
if v.specialization == nil {
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 0d9c028..a9b8362 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -329,18 +329,18 @@ expect_hover :: proc(
log.error(t, "Failed get_hover_information")
}
- if expect_hover_string == "" && hover.contents.value != "" {
+ /*
+ ```odin\n
+ content\n
+ ```
+ */
+ content_without_markdown := hover.contents.value[8:len(hover.contents.value)-5]
+
+ if content_without_markdown != expect_hover_string {
log.errorf(
- "Expected empty hover string, but received %v",
- hover.contents.value,
- )
- }
-
- if !strings.contains(hover.contents.value, expect_hover_string) {
- log.errorf(
- "Expected hover string %v, but received %v",
+ "Expected hover string:\n\"%v\", but received:\n\"%v\"",
expect_hover_string,
- hover.contents.value,
+ content_without_markdown,
)
}
}
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index dcf3a57..f74f02a 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -53,7 +53,7 @@ ast_hover_parameter :: proc(t: ^testing.T) {
packages = {},
}
- test.expect_hover(t, &source, "cool: int")
+ test.expect_hover(t, &source, "test.cool: int")
}
@(test)
@@ -223,3 +223,24 @@ ast_hover_struct_field_selector_completion :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "my_package.My_Struct: struct")
}
+
+/*
+TODO: Allow for testing multiple files
+*/
+// @(test)
+// ast_hover_array_type_multiple_files_hover :: proc(t: ^testing.T) {
+// source := test.Source {
+// main = \
+// `package test
+
+// Vec :: [2]f32
+// `,
+// another_file = \
+// `package test
+
+// v: Ve{*}c
+// `
+// }
+
+// test.expect_hover(t, &source, "test.Vec: [2]f32")
+// }
diff --git a/tests/objc_test.odin b/tests/objc_test.odin
index 9c69afb..915a3b1 100644
--- a/tests/objc_test.odin
+++ b/tests/objc_test.odin
@@ -141,7 +141,7 @@ objc_hover_chained_selector :: proc(t: ^testing.T) {
test.expect_hover(
t,
&source,
- "Window.initWithContentRect: proc(self: ^Window, contentRect: Rect, styleMask: WindowStyleMask, backing: BackingStoreType, doDefer: BOOL)",
+ "Window.initWithContentRect: proc(self: ^Window, contentRect: Rect, styleMask: WindowStyleMask, backing: BackingStoreType, doDefer: BOOL) -> ^Window",
)
}