add comments

This commit is contained in:
Matthew Leong 2023-01-06 13:18:49 -08:00
parent 3d4b00bb0b
commit 01a159dd6b
4 changed files with 17 additions and 40 deletions

View file

@ -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

View file

@ -1,11 +1,3 @@
require('cosmic.lsp.diagnostics')
require('cosmic.lsp.commands')
-- handled via noice
--[[ 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, ]]
--[[ }) ]]
-- LSP server initialization can be found in mason-lspconfig setup

View file

@ -16,15 +16,15 @@ function M.on_attach(client, bufnr)
-- set up :LspFormat for clients that are capable
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
-- collect filetype(s)
-- collect filetype(s) from user config
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
-- any filetype
else -- any filetype if none set
format_filetypes = '*'
end

View file

@ -1,5 +1,18 @@
local user_config = require('cosmic.core.user')
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()
local active_clients = vim.lsp.get_active_clients()
local client_names = {}