diff options
author | Chris AtLee <chris@atlee.ca> | 2023-07-20 03:03:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-20 09:03:48 +0200 |
commit | 63b3408551561127f7845470eb51404bcd6f547b (patch) | |
tree | 8dd17a411e61db4592662b2d014e5c5a5e4ff655 /test/functional/plugin/lsp/diagnostic_spec.lua | |
parent | 86ce3878d662c1dbfec61a5ad8e7c16c4283ed5c (diff) | |
download | rneovim-63b3408551561127f7845470eb51404bcd6f547b.tar.gz rneovim-63b3408551561127f7845470eb51404bcd6f547b.tar.bz2 rneovim-63b3408551561127f7845470eb51404bcd6f547b.zip |
feat(lsp): implement textDocument/diagnostic (#24128)
Diffstat (limited to 'test/functional/plugin/lsp/diagnostic_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp/diagnostic_spec.lua | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index f58016bf01..d1c3fd6b1e 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -1,10 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) +local lsp_helpers = require('test.functional.plugin.lsp.helpers') local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq local neq = require('test.helpers').neq +local create_server_definition = lsp_helpers.create_server_definition + describe('vim.lsp.diagnostic', function() local fake_uri @@ -265,4 +268,97 @@ describe('vim.lsp.diagnostic', function() eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 0) end) end) + + describe('vim.lsp.diagnostic.on_diagnostic', function() + before_each(function() + exec_lua(create_server_definition) + exec_lua([[ + server = _create_server({ + capabilities = { + diagnosticProvider = { + } + } + }) + + function get_extmarks(bufnr, client_id) + local namespace = vim.lsp.diagnostic.get_namespace(client_id, true) + local ns = vim.diagnostic.get_namespace(namespace) + local extmarks = {} + if ns.user_data.virt_text_ns then + for _, e in pairs(vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.virt_text_ns, 0, -1, {details=true})) do + table.insert(extmarks, e) + end + end + if ns.user_data.underline_ns then + for _, e in pairs(vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.underline_ns, 0, -1, {details=true})) do + table.insert(extmarks, e) + end + end + return extmarks + end + + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + end) + + it('adds diagnostics to vim.diagnostics', function() + local diags = exec_lua([[ + vim.lsp.diagnostic.on_diagnostic(nil, + { + kind = 'full', + items = { + make_error('Pull Diagnostic', 4, 4, 4, 4), + } + }, + { + params = { + textDocument = { uri = fake_uri }, + }, + uri = fake_uri, + client_id = client_id, + }, + {} + ) + + return vim.diagnostic.get(diagnostic_bufnr) + ]]) + eq(1, #diags) + eq('Pull Diagnostic', diags[1].message) + end) + + it('allows configuring the virtual text via vim.lsp.with', function() + local expected_spacing = 10 + local extmarks = exec_lua( + [[ + Diagnostic = vim.lsp.with(vim.lsp.diagnostic.on_diagnostic, { + virtual_text = { + spacing = ..., + }, + }) + + Diagnostic(nil, + { + kind = 'full', + items = { + make_error('Pull Diagnostic', 4, 4, 4, 4), + } + }, + { + params = { + textDocument = { uri = fake_uri }, + }, + uri = fake_uri, + client_id = client_id, + }, + {} + ) + + return get_extmarks(diagnostic_bufnr, client_id) + ]], + expected_spacing + ) + eq(2, #extmarks) + eq(expected_spacing, #extmarks[1][4].virt_text[1][1]) + end) + end) end) |