aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria José Solano <majosolano99@gmail.com>2024-08-27 11:16:33 -0700
committerGitHub <noreply@github.com>2024-08-27 13:16:33 -0500
commitdad55f5e763f3f2f436a2ae4f4bb1f6c6442bb45 (patch)
tree8938ae90cf0447771459a5a455e6fe0498b037db
parentf8e1ebd6f62662129fdb54574b305189e4a0b7af (diff)
downloadrneovim-dad55f5e763f3f2f436a2ae4f4bb1f6c6442bb45.tar.gz
rneovim-dad55f5e763f3f2f436a2ae4f4bb1f6c6442bb45.tar.bz2
rneovim-dad55f5e763f3f2f436a2ae4f4bb1f6c6442bb45.zip
feat(lsp): export diagnostic conversion functions (#30064)
-rw-r--r--runtime/doc/lsp.txt9
-rw-r--r--runtime/doc/news.txt2
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua5
3 files changed, 14 insertions, 2 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 05734c3ac1..c6664215c3 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -1486,6 +1486,15 @@ workspace_symbol({query}, {opts}) *vim.lsp.buf.workspace_symbol()*
==============================================================================
Lua module: vim.lsp.diagnostic *lsp-diagnostic*
+from({diagnostics}) *vim.lsp.diagnostic.from()*
+ Converts the input `vim.Diagnostic`s to LSP diagnostics.
+
+ Parameters: ~
+ • {diagnostics} (`vim.Diagnostic[]`)
+
+ Return: ~
+ (`lsp.Diagnostic[]`)
+
*vim.lsp.diagnostic.get_namespace()*
get_namespace({client_id}, {is_pull})
Get the diagnostic namespace associated with an LSP client
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 1d1e87fd0b..80511ccb87 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -68,6 +68,8 @@ LSP
• Add convert field in |vim.lsp.completion.BufferOpts| of
|vim.lsp.completion.enable()| an optional function used to customize the
transformation of an Lsp CompletionItem to |complete-items|.
+• |vim.lsp.diagnostic.from()| can be used to convert a list of
+ |vim.Diagnostic| objects into their LSP diagnostic representation.
LUA
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index ff52b40d60..c10312484b 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -153,9 +153,10 @@ local function tags_vim_to_lsp(diagnostic)
return tags
end
+--- Converts the input `vim.Diagnostic`s to LSP diagnostics.
--- @param diagnostics vim.Diagnostic[]
--- @return lsp.Diagnostic[]
-local function diagnostic_vim_to_lsp(diagnostics)
+function M.from(diagnostics)
---@param diagnostic vim.Diagnostic
---@return lsp.Diagnostic
return vim.tbl_map(function(diagnostic)
@@ -385,7 +386,7 @@ function M.get_line_diagnostics(bufnr, line_nr, opts, client_id)
diag_opts.lnum = line_nr or (api.nvim_win_get_cursor(0)[1] - 1)
- return diagnostic_vim_to_lsp(vim.diagnostic.get(bufnr, diag_opts))
+ return M.from(vim.diagnostic.get(bufnr, diag_opts))
end
--- Clear diagnostics from pull based clients