diff options
author | Maria José Solano <majosolano99@gmail.com> | 2023-09-18 11:04:01 -0700 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2023-09-19 14:47:37 +0100 |
commit | 5a363ccac8ff5889332bafbf68e7e8d20bca316c (patch) | |
tree | 22ea7a0d9bb6b58655288c21bbf9620a359b2117 /runtime/lua/vim | |
parent | cfd4a9dfaf5fd900264a946ca33c4a4f26f66a49 (diff) | |
download | rneovim-5a363ccac8ff5889332bafbf68e7e8d20bca316c.tar.gz rneovim-5a363ccac8ff5889332bafbf68e7e8d20bca316c.tar.bz2 rneovim-5a363ccac8ff5889332bafbf68e7e8d20bca316c.zip |
fix(lsp)!: deprecate trim_empty_lines
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 29 |
2 files changed, 14 insertions, 19 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index f8407be159..d43d9a7cfa 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -375,11 +375,10 @@ function M.hover(_, result, ctx, config) local contents ---@type string[] if type(result.contents) == 'table' and result.contents.kind == 'plaintext' then format = 'plaintext' - contents = { result.contents.value or '' } + contents = vim.split(result.contents.value or '', '\n', { trimempty = true }) else contents = util.convert_input_to_markdown_lines(result.contents) end - contents = util.trim_empty_lines(contents) if vim.tbl_isempty(contents) then if config.silent ~= true then vim.notify('No information available') @@ -477,7 +476,6 @@ function M.signature_help(_, result, ctx, config) vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters') local ft = vim.bo[ctx.bufnr].filetype local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers) - lines = util.trim_empty_lines(lines) if vim.tbl_isempty(lines) then if config.silent ~= true then print('No signature help available') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 32e85578d3..988057f5f9 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -102,7 +102,7 @@ end local function split_lines(value) value = string.gsub(value, '\r\n?', '\n') - return split(value, '\n', { plain = true }) + return split(value, '\n', { plain = true, trimempty = true }) end local function create_window_without_focus() @@ -947,7 +947,7 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers -- wrap inside a code block for proper rendering label = ('```%s\n%s\n```'):format(ft, label) end - list_extend(contents, split(label, '\n', { plain = true })) + list_extend(contents, split(label, '\n', { plain = true, trimempty = true })) if signature.documentation then -- if LSP returns plain string, we treat it as plaintext. This avoids -- special characters like underscore or similar from being interpreted @@ -1351,7 +1351,7 @@ function M.stylize_markdown(bufnr, contents, opts) end -- Clean up - contents = M.trim_empty_lines(contents) + contents = vim.split(table.concat(contents, '\n'), '\n', { trimempty = true }) local stripped = {} local highlights = {} @@ -1510,10 +1510,9 @@ end --- --- The following transformations are made: --- ---- 1. Empty lines at the beginning or end of the content are removed ---- 2. Carriage returns ('\r') are removed ---- 3. Successive empty lines are collapsed into a single empty line ---- 4. Thematic breaks are expanded to the given width +--- 1. Carriage returns ('\r') and empty lines at the beginning and end are removed +--- 2. Successive empty lines are collapsed into a single empty line +--- 3. Thematic breaks are expanded to the given width --- ---@private ---@param contents string[] @@ -1527,16 +1526,13 @@ function M._normalize_markdown(contents, opts) }) opts = opts or {} - -- 1. Empty lines at the beginning or end of the content are removed - contents = M.trim_empty_lines(contents) + -- 1. Carriage returns are removed + contents = vim.split(table.concat(contents, '\n'):gsub('\r', ''), '\n', { trimempty = true }) - -- 2. Carriage returns are removed - contents = vim.split(table.concat(contents, '\n'):gsub('\r', ''), '\n') - - -- 3. Successive empty lines are collapsed into a single empty line + -- 2. Successive empty lines are collapsed into a single empty line contents = collapse_blank_lines(contents) - -- 4. Thematic breaks are expanded to the given width + -- 3. Thematic breaks are expanded to the given width local divider = string.rep('─', opts.width or 80) contents = replace_separators(contents, divider) @@ -1738,8 +1734,8 @@ function M.open_floating_preview(contents, syntax, opts) vim.treesitter.start(floating_bufnr) api.nvim_buf_set_lines(floating_bufnr, 0, -1, false, contents) else - -- Clean up input: trim empty lines from the end, pad - contents = M.trim_empty_lines(contents) + -- Clean up input: trim empty lines + contents = vim.split(table.concat(contents, '\n'), '\n', { trimempty = true }) if syntax then vim.bo[floating_bufnr].syntax = syntax @@ -1969,6 +1965,7 @@ function M.symbols_to_items(symbols, bufnr) end --- Removes empty lines from the beginning and end. +---@deprecated use `vim.split()` with `trimempty` instead ---@param lines table list of lines to trim ---@return table trimmed list of lines function M.trim_empty_lines(lines) |