feat(lsp): allow overriding options for vim.lsp.buf.format. Fixes #51
This commit is contained in:
@ -18,7 +18,7 @@ function M.format()
|
|||||||
local ft = vim.bo[buf].filetype
|
local ft = vim.bo[buf].filetype
|
||||||
local have_nls = #require("null-ls.sources").get_available(ft, "NULL_LS_FORMATTING") > 0
|
local have_nls = #require("null-ls.sources").get_available(ft, "NULL_LS_FORMATTING") > 0
|
||||||
|
|
||||||
vim.lsp.buf.format({
|
vim.lsp.buf.format(vim.tbl_deep_extend("force", {
|
||||||
bufnr = buf,
|
bufnr = buf,
|
||||||
filter = function(client)
|
filter = function(client)
|
||||||
if have_nls then
|
if have_nls then
|
||||||
@ -26,7 +26,7 @@ function M.format()
|
|||||||
end
|
end
|
||||||
return client.name ~= "null-ls"
|
return client.name ~= "null-ls"
|
||||||
end,
|
end,
|
||||||
})
|
}, require("lazyvim.util").opts("nvim-lspconfig").format or {}))
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.on_attach(client, buf)
|
function M.on_attach(client, buf)
|
||||||
|
@ -12,12 +12,20 @@ return {
|
|||||||
},
|
},
|
||||||
---@class PluginLspOpts
|
---@class PluginLspOpts
|
||||||
opts = {
|
opts = {
|
||||||
|
-- options for vim.diagnostic.config()
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
underline = true,
|
underline = true,
|
||||||
update_in_insert = false,
|
update_in_insert = false,
|
||||||
virtual_text = { spacing = 4, prefix = "●" },
|
virtual_text = { spacing = 4, prefix = "●" },
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
},
|
},
|
||||||
|
-- options for vim.lsp.buf.format
|
||||||
|
-- `bufnr` and `filter` is handled by the LazyVim formatter,
|
||||||
|
-- but can be also overriden when specified
|
||||||
|
format = {
|
||||||
|
formatting_options = nil,
|
||||||
|
timeout = nil,
|
||||||
|
},
|
||||||
---@type lspconfig.options
|
---@type lspconfig.options
|
||||||
servers = {
|
servers = {
|
||||||
jsonls = {},
|
jsonls = {},
|
||||||
|
@ -20,6 +20,16 @@ function M.has(plugin)
|
|||||||
return require("lazy.core.config").plugins[plugin] ~= nil
|
return require("lazy.core.config").plugins[plugin] ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
function M.opts(name)
|
||||||
|
local plugin = require("lazy.core.config").plugins[name]
|
||||||
|
if not plugin then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
local Plugin = require("lazy.core.plugin")
|
||||||
|
return Plugin.values(plugin, "opts", false)
|
||||||
|
end
|
||||||
|
|
||||||
-- returns the root directory based on:
|
-- returns the root directory based on:
|
||||||
-- * lsp workspace folders
|
-- * lsp workspace folders
|
||||||
-- * lsp root_dir
|
-- * lsp root_dir
|
||||||
|
Reference in New Issue
Block a user