diff options
author | Raphael <glephunter@gmail.com> | 2023-12-13 22:19:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 08:19:53 -0600 |
commit | 8122470f8310ae34bcd5e436e8474f9255eb16f2 (patch) | |
tree | 2ee80d67ea635ff8b5b733ed8b69b71bc13e8ee3 /test/functional/lua/diagnostic_spec.lua | |
parent | e527842211188a5c069ef4f4759aa291353b707f (diff) | |
download | rneovim-8122470f8310ae34bcd5e436e8474f9255eb16f2.tar.gz rneovim-8122470f8310ae34bcd5e436e8474f9255eb16f2.tar.bz2 rneovim-8122470f8310ae34bcd5e436e8474f9255eb16f2.zip |
refactor(diagnostic): set sign by using extmark (#26193)
after sign implementation refactor by using extmark, we can use
`nvim_buf_set_extmark` to set diagnostic sign instead use `sign_define`
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index f061fac50a..e867ed32b0 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1080,9 +1080,19 @@ end) table.insert(virt_texts, (string.gsub(virt_text[i][2], "DiagnosticVirtualText", ""))) end + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns local signs = {} - for _, v in ipairs(vim.fn.sign_getplaced(diagnostic_bufnr, {group = "*"})[1].signs) do - table.insert(signs, (string.gsub(v.name, "DiagnosticSign", ""))) + local all_signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type = 'sign', details = true}) + table.sort(all_signs, function(a, b) + return a[1] > b[1] + end) + + for _, v in ipairs(all_signs) do + local s = v[4].sign_hl_group:gsub('DiagnosticSign', "") + if not vim.tbl_contains(signs, s) then + signs[#signs + 1] = s + end end return {virt_texts, signs} @@ -1498,7 +1508,15 @@ end) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) - return vim.fn.sign_getplaced(diagnostic_bufnr, {group = '*'})[1].signs + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns + + local signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type ='sign', details = true}) + local result = {} + for _, s in ipairs(signs) do + result[#result + 1] = { lnum = s[2] + 1, name = s[4].sign_hl_group } + end + return result ]] eq({2, 'DiagnosticSignError'}, {result[1].lnum, result[1].name}) |