From b3c78f4b3c5c97b1d71b6da2af36c755d5ee35aa Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Tue, 17 Jun 2025 13:41:49 -0700 Subject: [PATCH] test(lsp): return tables instead of deserializing strings #34554 --- .../functional/plugin/lsp/inlay_hint_spec.lua | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 3ff190fb55..1e59912ae4 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -24,13 +24,30 @@ int main() { } }]]) - local response = [==[ -[ -{"kind":1,"paddingLeft":false,"label":"-> int","position":{"character":22,"line":0},"paddingRight":false}, -{"kind":2,"paddingLeft":false,"label":"a:","position":{"character":15,"line":5},"paddingRight":true}, -{"kind":2,"paddingLeft":false,"label":"b:","position":{"character":17,"line":5},"paddingRight":true} -] -]==] + ---@type lsp.InlayHint[] + local response = { + { + kind = 1, + paddingLeft = false, + paddingRight = false, + label = '-> int', + position = { character = 22, line = 0 }, + }, + { + kind = 2, + paddingLeft = false, + paddingRight = true, + label = 'a:', + position = { character = 15, line = 5 }, + }, + { + kind = 2, + paddingLeft = false, + paddingRight = true, + label = 'b:', + position = { character = 17, line = 5 }, + }, + } local grid_without_inlay_hints = [[ auto add(int a, int b) { return a + b; } | @@ -78,7 +95,7 @@ int main() { }, handlers = { ['textDocument/inlayHint'] = function(_, _, callback) - callback(nil, vim.json.decode(response)) + callback(nil, response) end, }, }) @@ -217,8 +234,6 @@ int main() { describe('get()', function() it('returns filtered inlay hints', function() - --- @type lsp.InlayHint[] - local expected = vim.json.decode(response) local expected2 = { kind = 1, paddingLeft = false, @@ -248,9 +263,9 @@ int main() { --- @type vim.lsp.inlay_hint.get.ret eq( { - { bufnr = 1, client_id = 1, inlay_hint = expected[1] }, - { bufnr = 1, client_id = 1, inlay_hint = expected[2] }, - { bufnr = 1, client_id = 1, inlay_hint = expected[3] }, + { bufnr = 1, client_id = 1, inlay_hint = response[1] }, + { bufnr = 1, client_id = 1, inlay_hint = response[2] }, + { bufnr = 1, client_id = 1, inlay_hint = response[3] }, { bufnr = 1, client_id = 2, inlay_hint = expected2 }, }, exec_lua(function() @@ -274,8 +289,8 @@ int main() { eq( { - { bufnr = 1, client_id = 1, inlay_hint = expected[2] }, - { bufnr = 1, client_id = 1, inlay_hint = expected[3] }, + { bufnr = 1, client_id = 1, inlay_hint = response[2] }, + { bufnr = 1, client_id = 1, inlay_hint = response[3] }, }, exec_lua(function() return vim.lsp.inlay_hint.get({ @@ -349,15 +364,13 @@ describe('Inlay hints handler', function() test text ]]) - local response = [==[ - [ - { "position": { "line": 0, "character": 0 }, "label": "0" }, - { "position": { "line": 0, "character": 0 }, "label": "1" }, - { "position": { "line": 0, "character": 0 }, "label": "2" }, - { "position": { "line": 0, "character": 0 }, "label": "3" }, - { "position": { "line": 0, "character": 0 }, "label": "4" } - ] - ]==] + local response = { + { position = { line = 0, character = 0 }, label = '0' }, + { position = { line = 0, character = 0 }, label = '1' }, + { position = { line = 0, character = 0 }, label = '2' }, + { position = { line = 0, character = 0 }, label = '3' }, + { position = { line = 0, character = 0 }, label = '4' }, + } local grid_without_inlay_hints = [[ test text | @@ -393,7 +406,7 @@ test text }, handlers = { ['textDocument/inlayHint'] = function(_, _, callback) - callback(nil, vim.json.decode(response)) + callback(nil, response) end, }, })