mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-30 22:59:22 +02:00
feat(lsp): bind formatexpr and omnifunc by default (#2865)
This commit is contained in:
parent
6ab3e8a739
commit
dec21bbab6
4 changed files with 21 additions and 5 deletions
|
@ -8,7 +8,7 @@ return {
|
||||||
---@usage timeout number timeout in ms for the format request (Default: 1000)
|
---@usage timeout number timeout in ms for the format request (Default: 1000)
|
||||||
timeout = 1000,
|
timeout = 1000,
|
||||||
---@usage filter func to select client
|
---@usage filter func to select client
|
||||||
filter = require("lvim.lsp.handlers").format_filter,
|
filter = require("lvim.lsp.utils").format_filter,
|
||||||
},
|
},
|
||||||
keys = {},
|
keys = {},
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,12 @@ return {
|
||||||
insert_mode = {},
|
insert_mode = {},
|
||||||
visual_mode = {},
|
visual_mode = {},
|
||||||
},
|
},
|
||||||
|
buffer_options = {
|
||||||
|
--- enable completion triggered by <c-x><c-o>
|
||||||
|
omnifunc = "v:lua.vim.lsp.omnifunc",
|
||||||
|
--- use gq for formatting
|
||||||
|
formatexpr = "v:lua.vim.lsp.formatexpr(#{timeout_ms:500})",
|
||||||
|
},
|
||||||
---@usage list of settings of nvim-lsp-installer
|
---@usage list of settings of nvim-lsp-installer
|
||||||
installer = {
|
installer = {
|
||||||
setup = {
|
setup = {
|
||||||
|
|
|
@ -3,6 +3,12 @@ local Log = require "lvim.core.log"
|
||||||
local utils = require "lvim.utils"
|
local utils = require "lvim.utils"
|
||||||
local autocmds = require "lvim.core.autocmds"
|
local autocmds = require "lvim.core.autocmds"
|
||||||
|
|
||||||
|
local function add_lsp_buffer_options(bufnr)
|
||||||
|
for k, v in pairs(lvim.lsp.buffer_options) do
|
||||||
|
vim.api.nvim_buf_set_option(bufnr, k, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function add_lsp_buffer_keybindings(bufnr)
|
local function add_lsp_buffer_keybindings(bufnr)
|
||||||
local mappings = {
|
local mappings = {
|
||||||
normal_mode = "n",
|
normal_mode = "n",
|
||||||
|
@ -67,6 +73,7 @@ function M.common_on_attach(client, bufnr)
|
||||||
lu.setup_codelens_refresh(client, bufnr)
|
lu.setup_codelens_refresh(client, bufnr)
|
||||||
end
|
end
|
||||||
add_lsp_buffer_keybindings(bufnr)
|
add_lsp_buffer_keybindings(bufnr)
|
||||||
|
add_lsp_buffer_options(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_common_opts()
|
function M.get_common_opts()
|
||||||
|
|
|
@ -132,18 +132,20 @@ end
|
||||||
---filter passed to vim.lsp.buf.format
|
---filter passed to vim.lsp.buf.format
|
||||||
---always selects null-ls if it's available and caches the value per buffer
|
---always selects null-ls if it's available and caches the value per buffer
|
||||||
---@param client table client attached to a buffer
|
---@param client table client attached to a buffer
|
||||||
---@return table chosen clients
|
---@return boolean if client matches
|
||||||
function M.format_filter(client)
|
function M.format_filter(client)
|
||||||
local filetype = vim.bo.filetype
|
local filetype = vim.bo.filetype
|
||||||
local n = require "null-ls"
|
local n = require "null-ls"
|
||||||
local s = require "null-ls.sources"
|
local s = require "null-ls.sources"
|
||||||
local method = n.methods.FORMATTING
|
local method = n.methods.FORMATTING
|
||||||
local avalable_sources = s.get_available(filetype, method)
|
local avalable_formatters = s.get_available(filetype, method)
|
||||||
|
|
||||||
if #avalable_sources > 0 then
|
if #avalable_formatters > 0 then
|
||||||
return client.name == "null-ls"
|
return client.name == "null-ls"
|
||||||
else
|
elseif client.supports_method "textDocument/formatting" then
|
||||||
return true
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -159,6 +161,7 @@ function M.format(opts)
|
||||||
|
|
||||||
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
---@type table|nil
|
||||||
local clients = vim.lsp.get_active_clients {
|
local clients = vim.lsp.get_active_clients {
|
||||||
id = opts.id,
|
id = opts.id,
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue