add comments
This commit is contained in:
parent
3d4b00bb0b
commit
01a159dd6b
4 changed files with 17 additions and 40 deletions
|
@ -1,28 +0,0 @@
|
||||||
local augroup_name = 'CosmicNvimLspFormat'
|
|
||||||
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
|
|
||||||
local user_config = require('cosmic.core.user')
|
|
||||||
|
|
||||||
if user_config.lsp.format_on_save then
|
|
||||||
local format_filetypes = ''
|
|
||||||
if vim.tbl_islist(user_config.lsp.format_on_save) then
|
|
||||||
for _, ft in pairs(user_config.lsp.format_on_save) do
|
|
||||||
format_filetypes = format_filetypes .. '*' .. ft
|
|
||||||
end
|
|
||||||
else
|
|
||||||
format_filetypes = '*'
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd(string.format('BufWritePre %s', format_filetypes), {
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.format({
|
|
||||||
timeout_ms = user_config.lsp.format_timeout,
|
|
||||||
-- check user config to see if we can format on save
|
|
||||||
filter = function(client)
|
|
||||||
return user_config.lsp.can_client_format(client.name)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
group = group,
|
|
||||||
nested = true,
|
|
||||||
})
|
|
||||||
end
|
|
|
@ -1,11 +1,3 @@
|
||||||
require('cosmic.lsp.diagnostics')
|
require('cosmic.lsp.diagnostics')
|
||||||
require('cosmic.lsp.commands')
|
|
||||||
|
|
||||||
-- handled via noice
|
-- LSP server initialization can be found in mason-lspconfig setup
|
||||||
--[[ vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { ]]
|
|
||||||
--[[ border = user_config.border, ]]
|
|
||||||
--[[ }) ]]
|
|
||||||
--[[]]
|
|
||||||
--[[ vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { ]]
|
|
||||||
--[[ border = user_config.border, ]]
|
|
||||||
--[[ }) ]]
|
|
||||||
|
|
|
@ -16,15 +16,15 @@ function M.on_attach(client, bufnr)
|
||||||
-- set up :LspFormat for clients that are capable
|
-- set up :LspFormat for clients that are capable
|
||||||
vim.cmd(string.format("command! LspFormat lua require('cosmic.utils.lsp').format(%s)", bufnr))
|
vim.cmd(string.format("command! LspFormat lua require('cosmic.utils.lsp').format(%s)", bufnr))
|
||||||
|
|
||||||
|
-- set up auto format on save
|
||||||
if user_config.lsp.format_on_save then
|
if user_config.lsp.format_on_save then
|
||||||
-- collect filetype(s)
|
-- collect filetype(s) from user config
|
||||||
local format_filetypes = ''
|
local format_filetypes = ''
|
||||||
if vim.tbl_islist(user_config.lsp.format_on_save) then
|
if vim.tbl_islist(user_config.lsp.format_on_save) then
|
||||||
for _, ft in pairs(user_config.lsp.format_on_save) do
|
for _, ft in pairs(user_config.lsp.format_on_save) do
|
||||||
format_filetypes = format_filetypes .. '*' .. ft
|
format_filetypes = format_filetypes .. '*' .. ft
|
||||||
end
|
end
|
||||||
else
|
else -- any filetype if none set
|
||||||
-- any filetype
|
|
||||||
format_filetypes = '*'
|
format_filetypes = '*'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,18 @@
|
||||||
|
local user_config = require('cosmic.core.user')
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
-- format current buffer w/user settings
|
||||||
|
function M.format(bufnr)
|
||||||
|
vim.lsp.buf.format({
|
||||||
|
timeout_ms = user_config.lsp.format_timeout,
|
||||||
|
-- check user config to see if we can format on save
|
||||||
|
filter = function(client)
|
||||||
|
return user_config.lsp.can_client_format(client)
|
||||||
|
end,
|
||||||
|
bufnr = bufnr or 0,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function M.get_active_lsp_client_names()
|
function M.get_active_lsp_client_names()
|
||||||
local active_clients = vim.lsp.get_active_clients()
|
local active_clients = vim.lsp.get_active_clients()
|
||||||
local client_names = {}
|
local client_names = {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue