fix(lsp)!: deprecate trim_empty_lines

This commit is contained in:
Maria José Solano
2023-09-18 11:04:01 -07:00
committed by Lewis Russell
parent cfd4a9dfaf
commit 5a363ccac8
5 changed files with 16 additions and 28 deletions

View File

@@ -141,6 +141,7 @@ LSP FUNCTIONS
`progress` of |vim.lsp.client| `progress` of |vim.lsp.client|
- *vim.lsp.get_active_clients()* Use |vim.lsp.get_clients()| - *vim.lsp.get_active_clients()* Use |vim.lsp.get_clients()|
- *vim.lsp.for_each_buffer_client()* Use |vim.lsp.get_clients()| - *vim.lsp.for_each_buffer_client()* Use |vim.lsp.get_clients()|
- *vim.lsp.util.trim_empty_lines()* Use |vim.split()| with `trimempty` instead.
TREESITTER FUNCTIONS TREESITTER FUNCTIONS
- *vim.treesitter.language.require_language()* Use |vim.treesitter.language.add()| - *vim.treesitter.language.require_language()* Use |vim.treesitter.language.add()|

View File

@@ -2033,15 +2033,6 @@ text_document_completion_list_to_complete_items({result}, {prefix})
See also: ~ See also: ~
• complete-items • complete-items
trim_empty_lines({lines}) *vim.lsp.util.trim_empty_lines()*
Removes empty lines from the beginning and end.
Parameters: ~
• {lines} (table) list of lines to trim
Return: ~
(table) trimmed list of lines
*vim.lsp.util.try_trim_markdown_code_blocks()* *vim.lsp.util.try_trim_markdown_code_blocks()*
try_trim_markdown_code_blocks({lines}) try_trim_markdown_code_blocks({lines})
Accepts markdown lines and tries to reduce them to a filetype if they Accepts markdown lines and tries to reduce them to a filetype if they

View File

@@ -272,6 +272,7 @@ release.
- |vim.lsp.util.get_progress_messages()| Use |vim.lsp.status()| instead. - |vim.lsp.util.get_progress_messages()| Use |vim.lsp.status()| instead.
- |vim.lsp.get_active_clients()| Use |vim.lsp.get_clients()| instead. - |vim.lsp.get_active_clients()| Use |vim.lsp.get_clients()| instead.
- |vim.lsp.for_each_buffer_client()| Use |vim.lsp.get_clients()| instead. - |vim.lsp.for_each_buffer_client()| Use |vim.lsp.get_clients()| instead.
- |vim.lsp.util.trim_empty_lines()| Use |vim.split()| with `trimempty` instead.
• `vim.loop` has been renamed to `vim.uv`. • `vim.loop` has been renamed to `vim.uv`.

View File

@@ -375,11 +375,10 @@ function M.hover(_, result, ctx, config)
local contents ---@type string[] local contents ---@type string[]
if type(result.contents) == 'table' and result.contents.kind == 'plaintext' then if type(result.contents) == 'table' and result.contents.kind == 'plaintext' then
format = 'plaintext' format = 'plaintext'
contents = { result.contents.value or '' } contents = vim.split(result.contents.value or '', '\n', { trimempty = true })
else else
contents = util.convert_input_to_markdown_lines(result.contents) contents = util.convert_input_to_markdown_lines(result.contents)
end end
contents = util.trim_empty_lines(contents)
if vim.tbl_isempty(contents) then if vim.tbl_isempty(contents) then
if config.silent ~= true then if config.silent ~= true then
vim.notify('No information available') vim.notify('No information available')
@@ -477,7 +476,6 @@ function M.signature_help(_, result, ctx, config)
vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters') vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters')
local ft = vim.bo[ctx.bufnr].filetype local ft = vim.bo[ctx.bufnr].filetype
local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers) 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 vim.tbl_isempty(lines) then
if config.silent ~= true then if config.silent ~= true then
print('No signature help available') print('No signature help available')

View File

@@ -102,7 +102,7 @@ end
local function split_lines(value) local function split_lines(value)
value = string.gsub(value, '\r\n?', '\n') value = string.gsub(value, '\r\n?', '\n')
return split(value, '\n', { plain = true }) return split(value, '\n', { plain = true, trimempty = true })
end end
local function create_window_without_focus() 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 -- wrap inside a code block for proper rendering
label = ('```%s\n%s\n```'):format(ft, label) label = ('```%s\n%s\n```'):format(ft, label)
end end
list_extend(contents, split(label, '\n', { plain = true })) list_extend(contents, split(label, '\n', { plain = true, trimempty = true }))
if signature.documentation then if signature.documentation then
-- if LSP returns plain string, we treat it as plaintext. This avoids -- if LSP returns plain string, we treat it as plaintext. This avoids
-- special characters like underscore or similar from being interpreted -- special characters like underscore or similar from being interpreted
@@ -1351,7 +1351,7 @@ function M.stylize_markdown(bufnr, contents, opts)
end end
-- Clean up -- Clean up
contents = M.trim_empty_lines(contents) contents = vim.split(table.concat(contents, '\n'), '\n', { trimempty = true })
local stripped = {} local stripped = {}
local highlights = {} local highlights = {}
@@ -1510,10 +1510,9 @@ end
--- ---
--- The following transformations are made: --- The following transformations are made:
--- ---
--- 1. Empty lines at the beginning or end of the content are removed --- 1. Carriage returns ('\r') and empty lines at the beginning and end are removed
--- 2. Carriage returns ('\r') are removed --- 2. Successive empty lines are collapsed into a single empty line
--- 3. Successive empty lines are collapsed into a single empty line --- 3. Thematic breaks are expanded to the given width
--- 4. Thematic breaks are expanded to the given width
--- ---
---@private ---@private
---@param contents string[] ---@param contents string[]
@@ -1527,16 +1526,13 @@ function M._normalize_markdown(contents, opts)
}) })
opts = opts or {} opts = opts or {}
-- 1. Empty lines at the beginning or end of the content are removed -- 1. Carriage returns are removed
contents = M.trim_empty_lines(contents) contents = vim.split(table.concat(contents, '\n'):gsub('\r', ''), '\n', { trimempty = true })
-- 2. Carriage returns are removed -- 2. Successive empty lines are collapsed into a single empty line
contents = vim.split(table.concat(contents, '\n'):gsub('\r', ''), '\n')
-- 3. Successive empty lines are collapsed into a single empty line
contents = collapse_blank_lines(contents) 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) local divider = string.rep('', opts.width or 80)
contents = replace_separators(contents, divider) contents = replace_separators(contents, divider)
@@ -1738,8 +1734,8 @@ function M.open_floating_preview(contents, syntax, opts)
vim.treesitter.start(floating_bufnr) vim.treesitter.start(floating_bufnr)
api.nvim_buf_set_lines(floating_bufnr, 0, -1, false, contents) api.nvim_buf_set_lines(floating_bufnr, 0, -1, false, contents)
else else
-- Clean up input: trim empty lines from the end, pad -- Clean up input: trim empty lines
contents = M.trim_empty_lines(contents) contents = vim.split(table.concat(contents, '\n'), '\n', { trimempty = true })
if syntax then if syntax then
vim.bo[floating_bufnr].syntax = syntax vim.bo[floating_bufnr].syntax = syntax
@@ -1969,6 +1965,7 @@ function M.symbols_to_items(symbols, bufnr)
end end
--- Removes empty lines from the beginning and end. --- Removes empty lines from the beginning and end.
---@deprecated use `vim.split()` with `trimempty` instead
---@param lines table list of lines to trim ---@param lines table list of lines to trim
---@return table trimmed list of lines ---@return table trimmed list of lines
function M.trim_empty_lines(lines) function M.trim_empty_lines(lines)