aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/diagnostic.txt22
-rw-r--r--runtime/filetype.vim5
-rw-r--r--runtime/lua/vim/diagnostic.lua108
-rw-r--r--runtime/lua/vim/lsp/sync.lua8
-rw-r--r--runtime/scripts.vim8
-rw-r--r--src/nvim/testdir/test_filetype.vim4
-rw-r--r--test/functional/lua/diagnostic_spec.lua267
-rw-r--r--test/functional/plugin/lsp/incremental_sync_spec.lua150
8 files changed, 474 insertions, 98 deletions
diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt
index 6ada27edd0..1dd9c4f301 100644
--- a/runtime/doc/diagnostic.txt
+++ b/runtime/doc/diagnostic.txt
@@ -424,8 +424,9 @@ disable({bufnr}, {namespace}) *vim.diagnostic.disable()*
Disable diagnostics in the given buffer.
Parameters: ~
- {bufnr} number|nil Buffer number. Defaults to the
- current buffer.
+ {bufnr} number|nil Buffer number, or 0 for current
+ buffer. When omitted, disable diagnostics in
+ all buffers.
{namespace} number|nil Only disable diagnostics for the
given namespace.
@@ -433,8 +434,9 @@ enable({bufnr}, {namespace}) *vim.diagnostic.enable()*
Enable diagnostics in the given buffer.
Parameters: ~
- {bufnr} number|nil Buffer number. Defaults to the
- current buffer.
+ {bufnr} number|nil Buffer number, or 0 for current
+ buffer. When omitted, enable diagnostics in
+ all buffers.
{namespace} number|nil Only enable diagnostics for the
given namespace.
@@ -560,8 +562,9 @@ hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
{namespace} number|nil Diagnostic namespace. When
omitted, hide diagnostics from all
namespaces.
- {bufnr} number|nil Buffer number. Defaults to the
- current buffer.
+ {bufnr} number|nil Buffer number, or 0 for current
+ buffer. When omitted, hide diagnostics in all
+ buffers.
*vim.diagnostic.match()*
match({str}, {pat}, {groups}, {severity_map}, {defaults})
@@ -711,15 +714,16 @@ show({namespace}, {bufnr}, {diagnostics}, {opts})
{namespace} number|nil Diagnostic namespace. When
omitted, show diagnostics from all
namespaces.
- {bufnr} number|nil Buffer number. Defaults to the
- current buffer.
+ {bufnr} number|nil Buffer number, or 0 for current
+ buffer. When omitted, show diagnostics in
+ all buffers.
{diagnostics} table|nil The diagnostics to display. When
omitted, use the saved diagnostics for the
given namespace and buffer. This can be
used to display a list of diagnostics
without saving them or to display only a
subset of diagnostics. May not be used when
- {namespace} is nil.
+ {namespace} or {bufnr} is nil.
{opts} table|nil Display options. See
|vim.diagnostic.config()|.
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 75354968e9..02faafc85f 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -643,7 +643,7 @@ au BufNewFile,BufRead *.fsl setf framescript
au BufNewFile,BufRead fstab,mtab setf fstab
" GDB command files
-au BufNewFile,BufRead .gdbinit setf gdb
+au BufNewFile,BufRead .gdbinit,gdbinit setf gdb
" GDMO
au BufNewFile,BufRead *.mo,*.gdmo setf gdmo
@@ -1486,6 +1486,9 @@ au BufNewFile,BufRead robots.txt setf robots
" Rpcgen
au BufNewFile,BufRead *.x setf rpcgen
+" MikroTik RouterOS script
+au BufRead,BufNewFile *.rsc setf routeros
+
" reStructuredText Documentation Format
au BufNewFile,BufRead *.rst setf rst
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 80efa20f27..191b9b9145 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -245,6 +245,11 @@ local bufs_waiting_to_update = setmetatable({}, bufnr_and_namespace_cacher_mt)
---@private
local function is_disabled(namespace, bufnr)
+ local ns = M.get_namespace(namespace)
+ if ns.disabled then
+ return true
+ end
+
if type(diagnostic_disabled[bufnr]) == "table" then
return diagnostic_disabled[bufnr][namespace]
end
@@ -1046,19 +1051,22 @@ end
---
---@param namespace number|nil Diagnostic namespace. When omitted, hide
--- diagnostics from all namespaces.
----@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param bufnr number|nil Buffer number, or 0 for current buffer. When
+--- omitted, hide diagnostics in all buffers.
function M.hide(namespace, bufnr)
vim.validate {
namespace = { namespace, 'n', true },
bufnr = { bufnr, 'n', true },
}
- bufnr = get_bufnr(bufnr)
- local namespaces = namespace and {namespace} or vim.tbl_keys(diagnostic_cache[bufnr])
- for _, iter_namespace in ipairs(namespaces) do
- for _, handler in pairs(M.handlers) do
- if handler.hide then
- handler.hide(iter_namespace, bufnr)
+ local buffers = bufnr and {get_bufnr(bufnr)} or vim.tbl_keys(diagnostic_cache)
+ for _, iter_bufnr in ipairs(buffers) do
+ local namespaces = namespace and {namespace} or vim.tbl_keys(diagnostic_cache[iter_bufnr])
+ for _, iter_namespace in ipairs(namespaces) do
+ for _, handler in pairs(M.handlers) do
+ if handler.hide then
+ handler.hide(iter_namespace, iter_bufnr)
+ end
end
end
end
@@ -1068,12 +1076,14 @@ end
---
---@param namespace number|nil Diagnostic namespace. When omitted, show
--- diagnostics from all namespaces.
----@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param bufnr number|nil Buffer number, or 0 for current buffer. When omitted, show
+--- diagnostics in all buffers.
---@param diagnostics table|nil The diagnostics to display. When omitted, use the
--- saved diagnostics for the given namespace and
--- buffer. This can be used to display a list of diagnostics
--- without saving them or to display only a subset of
---- diagnostics. May not be used when {namespace} is nil.
+--- diagnostics. May not be used when {namespace}
+--- or {bufnr} is nil.
---@param opts table|nil Display options. See |vim.diagnostic.config()|.
function M.show(namespace, bufnr, diagnostics, opts)
vim.validate {
@@ -1083,11 +1093,18 @@ function M.show(namespace, bufnr, diagnostics, opts)
opts = { opts, 't', true },
}
- bufnr = get_bufnr(bufnr)
- if not namespace then
- assert(not diagnostics, "Cannot show diagnostics without a namespace")
- for iter_namespace in pairs(diagnostic_cache[bufnr]) do
- M.show(iter_namespace, bufnr, nil, opts)
+ if not bufnr or not namespace then
+ assert(not diagnostics, "Cannot show diagnostics without a buffer and namespace")
+ if not bufnr then
+ for iter_bufnr in pairs(diagnostic_cache) do
+ M.show(namespace, iter_bufnr, nil, opts)
+ end
+ else
+ -- namespace is nil
+ bufnr = get_bufnr(bufnr)
+ for iter_namespace in pairs(diagnostic_cache[bufnr]) do
+ M.show(iter_namespace, bufnr, nil, opts)
+ end
end
return
end
@@ -1354,44 +1371,67 @@ end
--- Disable diagnostics in the given buffer.
---
----@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param bufnr number|nil Buffer number, or 0 for current buffer. When
+--- omitted, disable diagnostics in all buffers.
---@param namespace number|nil Only disable diagnostics for the given namespace.
function M.disable(bufnr, namespace)
vim.validate { bufnr = {bufnr, 'n', true}, namespace = {namespace, 'n', true} }
- bufnr = get_bufnr(bufnr)
- if namespace == nil then
- diagnostic_disabled[bufnr] = true
- for ns in pairs(diagnostic_cache[bufnr]) do
- M.hide(ns, bufnr)
+ if bufnr == nil then
+ if namespace == nil then
+ -- Disable everything (including as yet non-existing buffers and
+ -- namespaces) by setting diagnostic_disabled to an empty table and set
+ -- its metatable to always return true. This metatable is removed
+ -- in enable()
+ diagnostic_disabled = setmetatable({}, {
+ __index = function() return true end,
+ })
+ else
+ local ns = M.get_namespace(namespace)
+ ns.disabled = true
end
else
- if type(diagnostic_disabled[bufnr]) ~= "table" then
- diagnostic_disabled[bufnr] = {}
+ bufnr = get_bufnr(bufnr)
+ if namespace == nil then
+ diagnostic_disabled[bufnr] = true
+ else
+ if type(diagnostic_disabled[bufnr]) ~= "table" then
+ diagnostic_disabled[bufnr] = {}
+ end
+ diagnostic_disabled[bufnr][namespace] = true
end
- diagnostic_disabled[bufnr][namespace] = true
- M.hide(namespace, bufnr)
end
+
+ M.hide(namespace, bufnr)
end
--- Enable diagnostics in the given buffer.
---
----@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param bufnr number|nil Buffer number, or 0 for current buffer. When
+--- omitted, enable diagnostics in all buffers.
---@param namespace number|nil Only enable diagnostics for the given namespace.
function M.enable(bufnr, namespace)
vim.validate { bufnr = {bufnr, 'n', true}, namespace = {namespace, 'n', true} }
- bufnr = get_bufnr(bufnr)
- if namespace == nil then
- diagnostic_disabled[bufnr] = nil
- for ns in pairs(diagnostic_cache[bufnr]) do
- M.show(ns, bufnr)
+ if bufnr == nil then
+ if namespace == nil then
+ -- Enable everything by setting diagnostic_disabled to an empty table
+ diagnostic_disabled = {}
+ else
+ local ns = M.get_namespace(namespace)
+ ns.disabled = false
end
else
- if type(diagnostic_disabled[bufnr]) ~= "table" then
- return
+ bufnr = get_bufnr(bufnr)
+ if namespace == nil then
+ diagnostic_disabled[bufnr] = nil
+ else
+ if type(diagnostic_disabled[bufnr]) ~= "table" then
+ return
+ end
+ diagnostic_disabled[bufnr][namespace] = nil
end
- diagnostic_disabled[bufnr][namespace] = nil
- M.show(namespace, bufnr)
end
+
+ M.show(namespace, bufnr)
end
--- Parse a diagnostic from a string.
diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua
index 37247c61b9..585c14a00f 100644
--- a/runtime/lua/vim/lsp/sync.lua
+++ b/runtime/lua/vim/lsp/sync.lua
@@ -219,6 +219,10 @@ local function compute_end_range(prev_lines, curr_lines, start_range, firstline,
-- Iterate from end to beginning of shortest line
local prev_end_byte_idx = prev_line_length - byte_offset + 1
+ -- Handle case where lines match
+ if prev_end_byte_idx == 0 then
+ prev_end_byte_idx = 1
+ end
local prev_byte_idx, prev_char_idx = align_position(prev_line, prev_end_byte_idx, 'start', offset_encoding)
local prev_end_range = { line_idx = prev_line_idx, byte_idx = prev_byte_idx, char_idx = prev_char_idx }
@@ -228,6 +232,10 @@ local function compute_end_range(prev_lines, curr_lines, start_range, firstline,
curr_end_range = { line_idx = start_line_idx, byte_idx = 1, char_idx = 1 }
else
local curr_end_byte_idx = curr_line_length - byte_offset + 1
+ -- Handle case where lines match
+ if curr_end_byte_idx == 0 then
+ curr_end_byte_idx = 1
+ end
local curr_byte_idx, curr_char_idx = align_position(curr_line, curr_end_byte_idx, 'start', offset_encoding)
curr_end_range = { line_idx = curr_line_idx, byte_idx = curr_byte_idx, char_idx = curr_char_idx }
end
diff --git a/runtime/scripts.vim b/runtime/scripts.vim
index 0b3fdc3514..79fd0a77e9 100644
--- a/runtime/scripts.vim
+++ b/runtime/scripts.vim
@@ -190,6 +190,10 @@ if s:line1 =~# "^#!"
elseif s:name =~# 'fennel\>'
set ft=fennel
+ " MikroTik RouterOS script
+ elseif s:name =~# 'rsc\>'
+ set ft=routeros
+
endif
unlet s:name
@@ -390,6 +394,10 @@ else
elseif s:line1 =~# '^%YAML'
set ft=yaml
+ " MikroTik RouterOS script
+ elseif s:line1 =~# '^#.*by RouterOS.*$'
+ set ft=routeros
+
" CVS diff
else
let s:lnum = 1
diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim
index 18e59bb6b7..cc8181c597 100644
--- a/src/nvim/testdir/test_filetype.vim
+++ b/src/nvim/testdir/test_filetype.vim
@@ -188,7 +188,7 @@ let s:filename_checks = {
\ 'freebasic': ['file.fb', 'file.bi'],
\ 'fstab': ['fstab', 'mtab'],
\ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'],
- \ 'gdb': ['.gdbinit'],
+ \ 'gdb': ['.gdbinit', 'gdbinit'],
\ 'gdmo': ['file.mo', 'file.gdmo'],
\ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'],
\ 'gemtext': ['file.gmi', 'file.gemini'],
@@ -419,6 +419,7 @@ let s:filename_checks = {
\ 'rnc': ['file.rnc'],
\ 'rng': ['file.rng'],
\ 'robots': ['robots.txt'],
+ \ 'routeros': ['file.rsc'],
\ 'rpcgen': ['file.x'],
\ 'rpl': ['file.rpl'],
\ 'rst': ['file.rst'],
@@ -659,6 +660,7 @@ let s:script_checks = {
\ 'yaml': [['%YAML 1.2']],
\ 'pascal': [['#!/path/instantfpc']],
\ 'fennel': [['#!/path/fennel']],
+ \ 'routeros': [['#!/path/rsc']],
\ }
" Various forms of "env" optional arguments.
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index bd513208e8..6414483c0d 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -271,6 +271,8 @@ describe('vim.diagnostic', function()
describe('show() and hide()', function()
it('works', function()
local result = exec_lua [[
+ local other_bufnr = vim.api.nvim_create_buf(true, false)
+
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
local result = {}
@@ -284,36 +286,279 @@ describe('vim.diagnostic', function()
local ns_2_diags = {
make_warning("Warning 1", 2, 1, 2, 5),
}
+ local other_buffer_diags = {
+ make_info("This is interesting", 0, 0, 0, 0)
+ }
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
+ vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags)
- -- Both
- table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns))
+ -- All buffers and namespaces
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
-- Hide one namespace
vim.diagnostic.hide(diagnostic_ns)
- table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns))
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
-- Show one namespace
vim.diagnostic.show(diagnostic_ns)
- table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns))
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
- -- Hide all namespaces
+ -- Hide one buffer
+ vim.diagnostic.hide(nil, other_bufnr)
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ -- Hide everything
vim.diagnostic.hide()
- table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns))
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ -- Show one buffer
+ vim.diagnostic.show(nil, diagnostic_bufnr)
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ return result
+ ]]
+
+ eq(4, result[1])
+ eq(1, result[2])
+ eq(4, result[3])
+ eq(3, result[4])
+ eq(0, result[5])
+ eq(3, result[6])
+ end)
+ end)
+
+ describe('enable() and disable()', function()
+ it('works without arguments', function()
+ local result = exec_lua [[
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+
+ local result = {}
+
+ vim.diagnostic.config({ underline = false, virtual_text = true })
+
+ local ns_1_diags = {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 2, 1, 2, 5),
+ }
+ local ns_2_diags = {
+ make_warning("Warning 1", 2, 1, 2, 5),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
+ vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns))
+
+ vim.diagnostic.disable()
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns))
+
+ -- Create a new buffer
+ local other_bufnr = vim.api.nvim_create_buf(true, false)
+ local other_buffer_diags = {
+ make_info("This is interesting", 0, 0, 0, 0)
+ }
- -- Show all namespaces
- vim.diagnostic.show()
- table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns))
+ vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.enable()
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
return result
]]
eq(3, result[1])
eq(0, result[2])
- eq(2, result[3])
- eq(0, result[4])
+ eq(0, result[3])
+ eq(4, result[4])
+ end)
+
+ it('works with only a buffer argument', function()
+ local result = exec_lua [[
+ local other_bufnr = vim.api.nvim_create_buf(true, false)
+
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+
+ local result = {}
+
+ vim.diagnostic.config({ underline = false, virtual_text = true })
+
+ local ns_1_diags = {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 2, 1, 2, 5),
+ }
+ local ns_2_diags = {
+ make_warning("Warning 1", 2, 1, 2, 5),
+ }
+ local other_buffer_diags = {
+ make_info("This is interesting", 0, 0, 0, 0)
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
+ vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
+ vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.disable(diagnostic_bufnr)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.enable(diagnostic_bufnr)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.disable(other_bufnr)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ return result
+ ]]
+
+ eq(4, result[1])
+ eq(1, result[2])
+ eq(4, result[3])
+ eq(3, result[4])
+ end)
+
+ it('works with only a namespace argument', function()
+ local result = exec_lua [[
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+
+ local result = {}
+
+ vim.diagnostic.config({ underline = false, virtual_text = true })
+
+ local ns_1_diags = {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 2, 1, 2, 5),
+ }
+ local ns_2_diags = {
+ make_warning("Warning 1", 2, 1, 2, 5),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
+ vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns))
+
+ vim.diagnostic.disable(nil, diagnostic_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns))
+
+ vim.diagnostic.enable(nil, diagnostic_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns))
+
+ vim.diagnostic.disable(nil, other_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns))
+
+ return result
+ ]]
+
+ eq(3, result[1])
+ eq(1, result[2])
+ eq(3, result[3])
+ eq(2, result[4])
+ end)
+
+ it('works with both a buffer and a namespace argument', function()
+ local result = exec_lua [[
+ local other_bufnr = vim.api.nvim_create_buf(true, false)
+
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+
+ local result = {}
+
+ vim.diagnostic.config({ underline = false, virtual_text = true })
+
+ local ns_1_diags = {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 2, 1, 2, 5),
+ }
+ local ns_2_diags = {
+ make_warning("Warning 1", 2, 1, 2, 5),
+ }
+ local other_buffer_diags = {
+ make_info("This is interesting", 0, 0, 0, 0)
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
+ vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
+ vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.disable(diagnostic_bufnr, other_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ -- Should have no effect
+ vim.diagnostic.disable(other_bufnr, other_ns)
+
+ table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
+ count_extmarks(diagnostic_bufnr, other_ns) +
+ count_extmarks(other_bufnr, diagnostic_ns))
+
+ return result
+ ]]
+
+ eq(4, result[1])
+ eq(2, result[2])
+ eq(1, result[3])
+ eq(3, result[4])
eq(3, result[5])
end)
end)
diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua
index fe4f8f3593..890db4abf5 100644
--- a/test/functional/plugin/lsp/incremental_sync_spec.lua
+++ b/test/functional/plugin/lsp/incremental_sync_spec.lua
@@ -66,6 +66,7 @@ local function test_edit(prev_buffer, edit_operations, expected_text_changes, of
exec_lua("test_unreg = 'test1'")
end
+
describe('incremental synchronization', function()
describe('single line edit', function()
it('inserting a character in an empty buffer', function()
@@ -163,54 +164,119 @@ describe('incremental synchronization', function()
}
test_edit({"a"}, {"rb"}, expected_text_changes, 'utf-16', '\n')
end)
- describe('multi-byte edits', function()
- it('join and undo', function()
- local expected_text_changes = {
- {
- range = {
- ['start'] = {
- character = 11,
- line = 0
- },
- ['end'] = {
- character = 11,
- line = 0
- }
+ end)
+
+ describe('multi-operation edits', function()
+ it('mult-line substitution', function()
+ local expected_text_changes = {
+ {
+ range = {
+ ["end"] = {
+ character = 11,
+ line = 2 },
+ ["start"] = {
+ character = 10,
+ line = 2 } },
+ rangeLength = 1,
+ text = '',
+ },{
+ range = {
+ ["end"] = {
+ character = 10,
+ line = 2 },
+ start = {
+ character = 10,
+ line = 2 } },
+ rangeLength = 0,
+ text = '2',
+ },{
+ range = {
+ ["end"] = {
+ character = 11,
+ line = 3 },
+ ["start"] = {
+ character = 10,
+ line = 3 } },
+ rangeLength = 1,
+ text = ''
+ },{
+ range = {
+ ['end'] = {
+ character = 10,
+ line = 3 },
+ ['start'] = {
+ character = 10,
+ line = 3 } },
+ rangeLength = 0,
+ text = '3' },
+ {
+ range = {
+ ['end'] = {
+ character = 0,
+ line = 3 },
+ ['start'] = {
+ character = 12,
+ line = 2 } },
+ rangeLength = 1,
+ text = '\n'
+ }
+ }
+ local original_lines = {
+ "\\begin{document}",
+ "\\section*{1}",
+ "\\section*{1}",
+ "\\section*{1}",
+ "\\end{document}"
+ }
+ test_edit(original_lines, {"3gg$h<C-V>jg<C-A>"}, expected_text_changes, 'utf-16', '\n')
+ end)
+ it('join and undo', function()
+ local expected_text_changes = {
+ {
+ range = {
+ ['start'] = {
+ character = 11,
+ line = 0
},
- rangeLength = 0,
- text = ' test3'
- },{
- range = {
- ['start'] = {
- character = 0,
- line = 1
- },
- ['end'] = {
- character = 0,
- line = 2
- }
+ ['end'] = {
+ character = 11,
+ line = 0
+ }
+ },
+ rangeLength = 0,
+ text = ' test3'
+ },{
+ range = {
+ ['start'] = {
+ character = 0,
+ line = 1
},
- rangeLength = 6,
- text = ''
- },{
- range = {
- ['start'] = {
- character = 11,
- line = 0
- },
- ['end'] = {
- character = 17,
- line = 0
- }
+ ['end'] = {
+ character = 0,
+ line = 2
+ }
+ },
+ rangeLength = 6,
+ text = ''
+ },{
+ range = {
+ ['start'] = {
+ character = 11,
+ line = 0
},
- rangeLength = 6,
- text = '\ntest3'
+ ['end'] = {
+ character = 17,
+ line = 0
+ }
},
- }
- test_edit({"test1 test2", "test3"}, {"J", "u"}, expected_text_changes, 'utf-16', '\n')
- end)
+ rangeLength = 6,
+ text = '\ntest3'
+ },
+ }
+ test_edit({"test1 test2", "test3"}, {"J", "u"}, expected_text_changes, 'utf-16', '\n')
end)
end)
+
describe('multi-byte edits', function()
it('deleting a multibyte character', function()
local expected_text_changes = {