From 2229e99ef918ad82c4d20d654b0299195f0ed15c Mon Sep 17 00:00:00 2001 From: Shadman Date: Sat, 3 Jul 2021 06:47:18 +0600 Subject: [PATCH 1/6] backport: fixup(clipboard): Use case matching #14962 Context: https://github.com/neovim/neovim/pull/14848#discussion_r663203173 --- runtime/autoload/provider/clipboard.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index dea79f21f0..0687abd4dc 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -158,7 +158,7 @@ function! s:clipboard.get(reg) abort end let clipboard_data = s:try_cmd(s:paste[a:reg]) - if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 && get(s:selections[a:reg].data, 0, []) == clipboard_data + if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 && get(s:selections[a:reg].data, 0, []) ==# clipboard_data " When system clipboard return is same as our cache return the cache " as it contains regtype information return s:selections[a:reg].data From ae89330ec0479cfa9eaaa2b64d8164e3309a1fea Mon Sep 17 00:00:00 2001 From: jadedpasta <86900272+jadedpasta@users.noreply.github.com> Date: Sun, 4 Jul 2021 02:14:39 -0500 Subject: [PATCH 2/6] backport: fix(vim.opt): vimL map string values not trimmed (#14982) Options formatted as a list of comma-separated key-value pairs may have values that contain leading and trailing whitespace characters. For example, the `listchars` option has a default value of `"tab:> ,trail:-,nbsp:+"`. When converting this value to a lua table, leading and trailing whitespace should not be trimmed. Co-authored-by: Robert Hrusecky --- runtime/lua/vim/_meta.lua | 1 - test/functional/lua/vim_spec.lua | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index b1f935541c..f7d47c1030 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -494,7 +494,6 @@ local convert_value_to_lua = (function() for _, key_value_str in ipairs(comma_split) do local key, value = unpack(vim.split(key_value_str, ":")) key = vim.trim(key) - value = vim.trim(value) result[key] = value end diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index eff838aea3..976e63b44d 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1332,12 +1332,12 @@ describe('lua stdlib', function() it('should work for key-value pair options', function() local listchars = exec_lua [[ - vim.opt.listchars = "tab:>~,space:_" + vim.opt.listchars = "tab:> ,space:_" return vim.opt.listchars:get() ]] eq({ - tab = ">~", + tab = "> ", space = "_", }, listchars) end) From 2ae4c96d9176de307822d5e93f3aca4496beeaa1 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 5 Jul 2021 00:39:46 +0200 Subject: [PATCH 3/6] backport: fix(lsp): prevent double for cached plaintext markup --- runtime/lua/vim/lsp/util.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 195e3a0e65..06afc2c5e2 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -810,16 +810,16 @@ function M.convert_input_to_markdown_lines(input, contents) -- If it's plaintext, then wrap it in a block -- Some servers send input.value as empty, so let's ignore this :( - input.value = input.value or '' + local value = input.value or '' if input.kind == "plaintext" then -- wrap this in a block so that stylize_markdown -- can properly process it as plaintext - input.value = string.format("\n%s\n", input.value or "") + value = string.format("\n%s\n", value) end - -- assert(type(input.value) == 'string') - list_extend(contents, split_lines(input.value)) + -- assert(type(value) == 'string') + list_extend(contents, split_lines(value)) -- MarkupString variation 2 elseif input.language then -- Some servers send input.value as empty, so let's ignore this :( From 989ccb822203213c845350e993e1ad2e6b9e3a91 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 7 Jul 2021 22:31:39 +0200 Subject: [PATCH 4/6] backport: fix(lsp): restore diagnostics extmarks on buffer changes (#15011) --- runtime/lua/vim/lsp/diagnostic.lua | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 64dde78f17..c67ea0c07a 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -203,8 +203,10 @@ local bufnr_and_client_cacher_mt = { -- Diagnostic Saving & Caching {{{ local _diagnostic_cleanup = setmetatable({}, bufnr_and_client_cacher_mt) local diagnostic_cache = setmetatable({}, bufnr_and_client_cacher_mt) +local diagnostic_cache_extmarks = setmetatable({}, bufnr_and_client_cacher_mt) local diagnostic_cache_lines = setmetatable({}, bufnr_and_client_cacher_mt) local diagnostic_cache_counts = setmetatable({}, bufnr_and_client_cacher_mt) +local diagnostic_attached_buffers = {} local _bufs_waiting_to_update = setmetatable({}, bufnr_and_client_cacher_mt) @@ -826,6 +828,7 @@ function M.clear(bufnr, client_id, diagnostic_ns, sign_ns) diagnostic_ns = diagnostic_ns or M._get_diagnostic_namespace(client_id) sign_ns = sign_ns or M._get_sign_namespace(client_id) + diagnostic_cache_extmarks[bufnr][client_id] = {} assert(bufnr, "bufnr is required") assert(diagnostic_ns, "Need diagnostic_ns, got nil") @@ -1038,6 +1041,53 @@ function M.on_publish_diagnostics(_, _, params, client_id, _, config) M.display(diagnostics, bufnr, client_id, config) end +-- restores the extmarks set by M.display +-- @private +local function restore_extmarks(bufnr) + local lcount = api.nvim_buf_line_count(bufnr) + for client_id, extmarks in pairs(diagnostic_cache_extmarks[bufnr]) do + local ns = M._get_diagnostic_namespace(client_id) + local extmarks_current = api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {details = true}) + local found = {} + for _, extmark in ipairs(extmarks_current) do + -- HACK: the missing extmarks seem to still exist, but at the line after the last + if extmark[2] < lcount then + found[extmark[1]] = true + end + end + for _, extmark in ipairs(extmarks) do + if not found[extmark[1]] then + local opts = extmark[4] + opts.id = extmark[1] + -- HACK: end_row should be end_line + if opts.end_row then + opts.end_line = opts.end_row + opts.end_row = nil + end + pcall(api.nvim_buf_set_extmark, bufnr, ns, extmark[2], extmark[3], opts) + end + end + end +end + +-- caches the extmarks set by M.display +-- @private +local function save_extmarks(bufnr, client_id) + bufnr = bufnr == 0 and api.nvim_get_current_buf() or bufnr + if not diagnostic_attached_buffers[bufnr] then + api.nvim_buf_attach(bufnr, false, { + on_lines = function() + restore_extmarks(bufnr) + end, + on_detach = function() + diagnostic_cache_extmarks[bufnr] = nil + end}) + diagnostic_attached_buffers[bufnr] = true + end + local ns = M._get_diagnostic_namespace(client_id) + diagnostic_cache_extmarks[bufnr][client_id] = api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {details = true}) +end + --@private --- Display diagnostics for the buffer, given a configuration. function M.display(diagnostics, bufnr, client_id, config) @@ -1108,7 +1158,11 @@ function M.display(diagnostics, bufnr, client_id, config) if signs_opts then M.set_signs(diagnostics, bufnr, client_id, nil, signs_opts) end + + -- cache extmarks + save_extmarks(bufnr, client_id) end + -- }}} -- Diagnostic User Functions {{{ From a9cca1b050f40521a02fc4b11a9b9cc5bb5520ff Mon Sep 17 00:00:00 2001 From: Shadman Date: Sun, 11 Jul 2021 19:19:54 +0600 Subject: [PATCH 5/6] backport: fixup(clipboard): Fix error not properly handled #14984 fixes #14967 --- runtime/autoload/provider/clipboard.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index 0687abd4dc..991bed6bbd 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -158,7 +158,9 @@ function! s:clipboard.get(reg) abort end let clipboard_data = s:try_cmd(s:paste[a:reg]) - if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 && get(s:selections[a:reg].data, 0, []) ==# clipboard_data + if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 + \ && type(clipboard_data) == v:t_list + \ && get(s:selections[a:reg].data, 0, []) ==# clipboard_data " When system clipboard return is same as our cache return the cache " as it contains regtype information return s:selections[a:reg].data From 917f30666657acc3ad3daf44425c4d28f7ffb299 Mon Sep 17 00:00:00 2001 From: Daniel Steinberg Date: Sat, 10 Jul 2021 23:15:38 -0400 Subject: [PATCH 6/6] backport: test/memory_usage_spec: skip on MacOS #15043 Memory compression could complicate the measurements. --- test/functional/legacy/memory_usage_spec.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua index 0f2d77093a..d86caca0e9 100644 --- a/test/functional/legacy/memory_usage_spec.lua +++ b/test/functional/legacy/memory_usage_spec.lua @@ -168,6 +168,9 @@ describe('memory usage', function() end) it('releases memory when closing windows when folds exist', function() + if helpers.is_os('mac') then + pending('macOS memory compression causes flakiness') + end local pid = eval('getpid()') source([[ new