diff options
| author | Damian Tarnawski <gthetarnav@gmail.com> | 2025-09-11 00:38:40 +0200 |
|---|---|---|
| committer | Damian Tarnawski <gthetarnav@gmail.com> | 2025-09-11 00:38:40 +0200 |
| commit | 23de8c183d052844f6b23b8ead9d03a33012af27 (patch) | |
| tree | 8ea4398b82bd8cdbe028ca1a774b3380c8e5daa9 | |
| parent | 4f808a95f55a940d0dc013ca8b4fd1df427cc3da (diff) | |
Take expected inlay hints from the source code
| -rw-r--r-- | src/testing/testing.odin | 49 | ||||
| -rw-r--r-- | tests/inlay_hints_test.odin | 92 |
2 files changed, 65 insertions, 76 deletions
diff --git a/src/testing/testing.odin b/src/testing/testing.odin index 57354e1..fed1510 100644 --- a/src/testing/testing.odin +++ b/src/testing/testing.odin @@ -532,12 +532,57 @@ expect_semantic_tokens :: proc(t: ^testing.T, src: ^Source, expected: []server.S } } -expect_inlay_hints :: proc(t: ^testing.T, src: ^Source, expected_hints: []server.InlayHint) { +expect_inlay_hints :: proc(t: ^testing.T, src: ^Source) { + + src_builder := strings.builder_make(context.temp_allocator) + expected_hints := make([dynamic]server.InlayHint, context.temp_allocator) + + { + last, line, col: int + saw_brackets: bool + for i:= 0; i < len(src.main); i += 1 { + if saw_brackets { + if i+1 < len(src.main) && src.main[i:i+2] == "]]" { + saw_brackets = false + hint_str := src.main[last:i] + last = i+2 + i += 1 + append(&expected_hints, server.InlayHint{ + position = {line, col}, + label = hint_str, + kind = .Parameter, + }) + } + } else { + if i+1 < len(src.main) && src.main[i:i+2] == "[[" { + strings.write_string(&src_builder, src.main[last:i]) + saw_brackets = true + last = i+2 + i += 1 + } else if src.main[i] == '\n' { + line += 1 + col = 0 + } else { + col += 1 + } + } + } + + if saw_brackets { + log.error("Unclosed inlay hint marker") + return + } + + strings.write_string(&src_builder, src.main[last:len(src.main)]) + } + + src.main = strings.to_string(src_builder) + setup(src) defer teardown(src) resolve_flag: server.ResolveReferenceFlag - symbols_and_nodes := server.resolve_entire_file(src.document, resolve_flag, context.temp_allocator) + symbols_and_nodes := server.resolve_entire_file(src.document, resolve_flag, ) hints, ok := server.get_inlay_hints(src.document, symbols_and_nodes, &src.config) if !ok { diff --git a/tests/inlay_hints_test.odin b/tests/inlay_hints_test.odin index 005253a..9d9d074 100644 --- a/tests/inlay_hints_test.odin +++ b/tests/inlay_hints_test.odin @@ -13,7 +13,7 @@ ast_inlay_hints_default_params :: proc(t: ^testing.T) { my_function :: proc(a := false, b := 42) {} main :: proc() { - my_function() + my_function([[a = false]][[, b = 42]]) } `, packages = {}, @@ -22,15 +22,7 @@ ast_inlay_hints_default_params :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 15}, - kind = .Parameter, - label = "a = false", - }, { - position = {5, 15}, - kind = .Parameter, - label = ", b = 42", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -41,7 +33,7 @@ ast_inlay_hints_default_params_after_required :: proc(t: ^testing.T) { my_function :: proc(a: int, b := false, c := 42) {} main :: proc() { - my_function(1) + my_function(1[[, b = false]][[, c = 42]]) } `, packages = {}, @@ -50,15 +42,7 @@ ast_inlay_hints_default_params_after_required :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 16}, - kind = .Parameter, - label = ", b = false", - }, { - position = {5, 16}, - kind = .Parameter, - label = ", c = 42", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -69,7 +53,7 @@ ast_inlay_hints_default_params_after_named :: proc(t: ^testing.T) { my_function :: proc(a: int, b := false, c := 42) {} main :: proc() { - my_function(a=1) + my_function(a=1[[, b = false]][[, c = 42]]) } `, packages = {}, @@ -79,15 +63,7 @@ ast_inlay_hints_default_params_after_named :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 18}, - kind = .Parameter, - label = ", b = false", - }, { - position = {5, 18}, - kind = .Parameter, - label = ", c = 42", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -98,7 +74,7 @@ ast_inlay_hints_default_params_named_ooo :: proc(t: ^testing.T) { my_function :: proc(a: int, b := false, c := 42) {} main :: proc() { - my_function(1, c=42) + my_function(1, c=42[[, b = false]]) } `, packages = {}, @@ -107,11 +83,7 @@ ast_inlay_hints_default_params_named_ooo :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 22}, - kind = .Parameter, - label = ", b = false", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -122,7 +94,7 @@ ast_inlay_hints_params :: proc(t: ^testing.T) { my_function :: proc(param1: int, param2: string) {} main :: proc() { - my_function(123, "hello") + my_function([[param1 = ]]123, [[param2 = ]]"hello") } `, packages = {}, @@ -131,15 +103,7 @@ ast_inlay_hints_params :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 15}, - kind = .Parameter, - label = "param1 = ", - }, { - position = {5, 20}, - kind = .Parameter, - label = "param2 = ", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -150,7 +114,7 @@ ast_inlay_hints_mixed_params :: proc(t: ^testing.T) { my_function :: proc(required: int, optional := false) {} main :: proc() { - my_function(42) + my_function([[required = ]]42[[, optional = false]]) } `, packages = {}, @@ -160,15 +124,7 @@ ast_inlay_hints_mixed_params :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 15}, - kind = .Parameter, - label = "required = ", - }, { - position = {5, 17}, - kind = .Parameter, - label = ", optional = false", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -183,7 +139,7 @@ ast_inlay_hints_selector_call :: proc(t: ^testing.T) { main :: proc() { p: Point - p->move(1.0, 2.0) + p->move([[dx = ]]1.0, [[dy = ]]2.0) } `, packages = {}, @@ -192,15 +148,7 @@ ast_inlay_hints_selector_call :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {9, 11}, - kind = .Parameter, - label = "dx = ", - }, { - position = {9, 16}, - kind = .Parameter, - label = "dy = ", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -222,7 +170,7 @@ ast_inlay_hints_no_hints_same_name :: proc(t: ^testing.T) { } // No hints should be shown when argument name matches parameter name - test.expect_inlay_hints(t, &source, {}) + test.expect_inlay_hints(t, &source) } @(test) @@ -233,7 +181,7 @@ ast_inlay_hints_variadic_params :: proc(t: ^testing.T) { variadic_func :: proc(args: ..int) {} main :: proc() { - variadic_func(1, 2, 3) + variadic_func([[args = ]]1, 2, 3) } `, packages = {}, @@ -242,11 +190,7 @@ ast_inlay_hints_variadic_params :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {{ - position = {5, 17}, - kind = .Parameter, - label = "args = ", - }}) + test.expect_inlay_hints(t, &source) } @(test) @@ -267,5 +211,5 @@ ast_inlay_hints_disabled :: proc(t: ^testing.T) { }, } - test.expect_inlay_hints(t, &source, {}) + test.expect_inlay_hints(t, &source) } |