aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorMaria José Solano <majosolano99@gmail.com>2023-09-18 11:04:01 -0700
committerLewis Russell <me@lewisr.dev>2023-09-19 14:47:37 +0100
commit5a363ccac8ff5889332bafbf68e7e8d20bca316c (patch)
tree22ea7a0d9bb6b58655288c21bbf9620a359b2117 /runtime/lua/vim/lsp/util.lua
parentcfd4a9dfaf5fd900264a946ca33c4a4f26f66a49 (diff)
downloadrneovim-5a363ccac8ff5889332bafbf68e7e8d20bca316c.tar.gz
rneovim-5a363ccac8ff5889332bafbf68e7e8d20bca316c.tar.bz2
rneovim-5a363ccac8ff5889332bafbf68e7e8d20bca316c.zip
fix(lsp)!: deprecate trim_empty_lines
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua29
1 files changed, 13 insertions, 16 deletions
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)