feat(lsp): clean up commands and formatting
This commit is contained in:
parent
0295f75c07
commit
40eef214f3
10 changed files with 98 additions and 72 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Comment.nvim": {
|
||||
"branch": "master",
|
||||
"commit": "7bb563ff2d811a63b207e9de63e3e9c0877cb6d5"
|
||||
"commit": "ab00bcf5aa979c53f2f40dc2655c03e24f4ef50f"
|
||||
},
|
||||
"LuaSnip": {
|
||||
"branch": "master",
|
||||
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"SchemaStore.nvim": {
|
||||
"branch": "main",
|
||||
"commit": "eee175f655e6775e1750a81b89a7471f9dbe8b0e"
|
||||
"commit": "c55c35929dd4e670af7ab6e2e197a4687baa2076"
|
||||
},
|
||||
"auto-session": {
|
||||
"branch": "main",
|
||||
|
@ -29,7 +29,7 @@
|
|||
},
|
||||
"cmp-nvim-lua": {
|
||||
"branch": "main",
|
||||
"commit": "d276254e7198ab7d00f117e88e223b4bd8c02d21"
|
||||
"commit": "f3491638d123cfd2c8048aefaf66d246ff250ca6"
|
||||
},
|
||||
"cmp-path": {
|
||||
"branch": "main",
|
||||
|
@ -53,7 +53,7 @@
|
|||
},
|
||||
"lazy.nvim": {
|
||||
"branch": "main",
|
||||
"commit": "c59c05c7a80693fda369ccab572f8eaca50a1b4f"
|
||||
"commit": "4f76b431f73c912a7021bc17384533fbad96fba7"
|
||||
},
|
||||
"lsp_lines.nvim": {
|
||||
"branch": "main",
|
||||
|
@ -61,15 +61,15 @@
|
|||
},
|
||||
"lualine.nvim": {
|
||||
"branch": "master",
|
||||
"commit": "32a7382a75a52e8ad05f4cec7eeb8bbfbe80d461"
|
||||
"commit": "d8c392dd75778d6258da4e7c55522e94ac389732"
|
||||
},
|
||||
"mason-lspconfig.nvim": {
|
||||
"branch": "main",
|
||||
"commit": "aa25b4153d2f2636c3b3a8c8360349d2b29e7ae3"
|
||||
"commit": "33a198bc5ee0215ae8ab3f61781b29103cf4ca5a"
|
||||
},
|
||||
"mason.nvim": {
|
||||
"branch": "main",
|
||||
"commit": "b71538a5f02fd9a6047a900310d2834acec5a508"
|
||||
"commit": "73831cbe979fb3b385ed8e61626d16d9306a1f06"
|
||||
},
|
||||
"noice.nvim": {
|
||||
"branch": "main",
|
||||
|
@ -81,7 +81,7 @@
|
|||
},
|
||||
"null-ls.nvim": {
|
||||
"branch": "main",
|
||||
"commit": "fdcd809b432c665e9b202309c93c18416d7c4628"
|
||||
"commit": "6830a1ed04f89e6d556cb6bcc200433173004307"
|
||||
},
|
||||
"nvim-autopairs": {
|
||||
"branch": "master",
|
||||
|
@ -89,7 +89,7 @@
|
|||
},
|
||||
"nvim-cmp": {
|
||||
"branch": "main",
|
||||
"commit": "c49ad26e894e137e401b1d294948c46327877eaf"
|
||||
"commit": "11a95792a5be0f5a40bab5fc5b670e5b1399a939"
|
||||
},
|
||||
"nvim-colorizer.lua": {
|
||||
"branch": "master",
|
||||
|
@ -113,7 +113,7 @@
|
|||
},
|
||||
"nvim-treesitter": {
|
||||
"branch": "master",
|
||||
"commit": "b1569394614804aaad4e994731161f253ff61bcc"
|
||||
"commit": "68e8181dbcf29330716d380e5669f2cd838eadb5"
|
||||
},
|
||||
"nvim-treesitter-refactor": {
|
||||
"branch": "master",
|
||||
|
@ -133,7 +133,7 @@
|
|||
},
|
||||
"plenary.nvim": {
|
||||
"branch": "master",
|
||||
"commit": "bb444796dc5746d969f0718913a31c8075741e36"
|
||||
"commit": "95fb27dfcf6330ac482a99545d7440ac6729851b"
|
||||
},
|
||||
"popup.nvim": {
|
||||
"branch": "master",
|
||||
|
@ -145,7 +145,7 @@
|
|||
},
|
||||
"telescope.nvim": {
|
||||
"branch": "master",
|
||||
"commit": "a606bd10c79ec5989c76c49cc6f736e88b63f0da"
|
||||
"commit": "18fc02b499b368287e3aa267ec0b0d22afc0f19b"
|
||||
},
|
||||
"todo-comments.nvim": {
|
||||
"branch": "main",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
local augroup_name = 'CosmicNvim'
|
||||
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd('VimResized', {
|
||||
command = 'tabdo wincmd =',
|
||||
group = group,
|
||||
|
@ -7,5 +8,4 @@ vim.api.nvim_create_autocmd('VimResized', {
|
|||
|
||||
vim.cmd([[
|
||||
command! CosmicUpdate lua require('cosmic.utils.cosmic').update()
|
||||
command! LspFormat lua vim.lsp.buf.format()
|
||||
]])
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
local disabled_built_ins = {
|
||||
'netrw',
|
||||
'netrwPlugin',
|
||||
'netrwSettings',
|
||||
'netrwFileHandlers',
|
||||
'gzip',
|
||||
'zip',
|
||||
'zipPlugin',
|
||||
'tar',
|
||||
'tarPlugin',
|
||||
'getscript',
|
||||
'getscriptPlugin',
|
||||
'vimball',
|
||||
'vimballPlugin',
|
||||
'2html_plugin',
|
||||
'logipat',
|
||||
'rrhelper',
|
||||
'spellfile_plugin',
|
||||
'matchit',
|
||||
}
|
||||
|
||||
for _, plugin in pairs(disabled_built_ins) do
|
||||
vim.g['loaded_' .. plugin] = 1
|
||||
end
|
|
@ -1,10 +1,10 @@
|
|||
local cosmic_modules = {
|
||||
'cosmic.core.disabled',
|
||||
'cosmic.core.editor',
|
||||
'cosmic.core.pluginsInit',
|
||||
'cosmic.lsp',
|
||||
'cosmic.core.editor',
|
||||
'cosmic.core.commands',
|
||||
'cosmic.core.mappings',
|
||||
'cosmic.lsp',
|
||||
-- user editor settings
|
||||
'cosmic.config.editor',
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ vim.opt.runtimepath:prepend(lazypath)
|
|||
|
||||
for _, mod in ipairs(cosmic_modules) do
|
||||
local ok, err = pcall(require, mod)
|
||||
-- cosmic.config files may or may not be present
|
||||
if not ok and not mod:find('cosmic.config') then
|
||||
error(('Error loading %s...\n\n%s'):format(mod, err))
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
local u = require('cosmic.utils.cosmic')
|
||||
local user_config = require('cosmic.core.user')
|
||||
|
||||
require('lazy').setup('cosmic.plugins', {
|
||||
lockfile = u.get_install_dir() .. '/lazy-lock.json', -- lockfile generated after running update.
|
||||
lockfile = u.get_install_dir() .. '/lazy-lock.json',
|
||||
defaults = { lazy = true },
|
||||
ui = {
|
||||
border = user_config.border,
|
||||
|
@ -10,14 +11,24 @@ require('lazy').setup('cosmic.plugins', {
|
|||
performance = {
|
||||
rtp = {
|
||||
disabled_plugins = {
|
||||
'gzip',
|
||||
'matchit',
|
||||
'matchparen',
|
||||
'netrw',
|
||||
'netrwPlugin',
|
||||
'tarPlugin',
|
||||
'tohtml',
|
||||
'tutor',
|
||||
'netrwSettings',
|
||||
'netrwFileHandlers',
|
||||
'gzip',
|
||||
'zip',
|
||||
'zipPlugin',
|
||||
'tar',
|
||||
'tarPlugin',
|
||||
'getscript',
|
||||
'getscriptPlugin',
|
||||
'vimball',
|
||||
'vimballPlugin',
|
||||
'2html_plugin',
|
||||
'logipat',
|
||||
'rrhelper',
|
||||
'spellfile_plugin',
|
||||
'matchit',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -58,15 +58,22 @@ local default_config = {
|
|||
|
||||
local u = require('cosmic.utils')
|
||||
local config = u.merge(default_config, user_config)
|
||||
local user_servers = vim.tbl_keys(config.lsp.servers)
|
||||
|
||||
function config.lsp.can_client_format(client_name)
|
||||
if config.lsp.servers[client_name] == true then
|
||||
function config.lsp.can_client_format(client)
|
||||
-- formatting enabled by default if server=true
|
||||
if config.lsp.servers[client.name] == true then
|
||||
return true
|
||||
end
|
||||
|
||||
if vim.tbl_contains(user_servers, client_name) and config.lsp.servers[client_name] then
|
||||
return (config.lsp.servers[client_name].format == true)
|
||||
-- check config server settings
|
||||
if config.lsp.servers[client.name] then
|
||||
-- default to true if no format flag on server settings is set
|
||||
if config.lsp.servers[client.name].format == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
-- check format flag on server settings
|
||||
return (config.lsp.servers[client.name].format == true)
|
||||
end
|
||||
|
||||
return true
|
||||
|
|
|
@ -1,10 +1 @@
|
|||
local mods = {
|
||||
'cosmic.core',
|
||||
}
|
||||
|
||||
for _, mod in ipairs(mods) do
|
||||
local ok, err = pcall(require, mod)
|
||||
if not ok and not mod:find('cosmic.core.user') then
|
||||
error(('Error loading %s...\n\n%s'):format(mod, err))
|
||||
end
|
||||
end
|
||||
require('cosmic.core')
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
local augroup_name = 'CosmicNvimLspFormat'
|
||||
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
|
||||
local config = require('cosmic.core.user')
|
||||
local user_config = require('cosmic.core.user')
|
||||
|
||||
if config.lsp.format_on_save then
|
||||
if user_config.lsp.format_on_save then
|
||||
local format_filetypes = ''
|
||||
if vim.tbl_islist(config.lsp.format_on_save) then
|
||||
for _, ft in pairs(config.lsp.format_on_save) do
|
||||
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
|
||||
|
@ -15,10 +15,10 @@ if config.lsp.format_on_save then
|
|||
vim.api.nvim_create_autocmd(string.format('BufWritePre %s', format_filetypes), {
|
||||
callback = function()
|
||||
vim.lsp.buf.format({
|
||||
timeout_ms = config.lsp.format_timeout,
|
||||
timeout_ms = user_config.lsp.format_timeout,
|
||||
-- check user config to see if we can format on save
|
||||
filter = function(client)
|
||||
return config.lsp.can_client_format(client.name)
|
||||
return user_config.lsp.can_client_format(client.name)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
local M = {}
|
||||
local augroup_name = 'CosmicNvimLspFormat'
|
||||
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
|
||||
local user_config = require('cosmic.core.user')
|
||||
|
||||
function M.on_attach(client, bufnr)
|
||||
local function buf_set_option(...)
|
||||
|
@ -9,13 +12,35 @@ function M.on_attach(client, bufnr)
|
|||
-- Enable completion triggered by <c-x><c-o>
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
if client.server_capabilities.documentFormattingProvider then
|
||||
-- set up :LspFormat for clients that are capable
|
||||
vim.cmd(string.format("command! LspFormat lua require('cosmic.lsp.utils').format(%s)", bufnr))
|
||||
|
||||
if user_config.lsp.format_on_save then
|
||||
-- collect filetype(s)
|
||||
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
|
||||
format_filetypes = '*'
|
||||
end
|
||||
|
||||
-- autocommand for format on save with specified filetype(s)
|
||||
vim.api.nvim_create_autocmd(string.format('BufWritePre %s', format_filetypes), {
|
||||
callback = function()
|
||||
require('cosmic.lsp.utils').format(bufnr)
|
||||
end,
|
||||
group = group,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
require('cosmic.lsp.mappings').init(client, bufnr)
|
||||
end
|
||||
|
||||
M.flags = {
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
|
||||
M.capabilities = capabilities
|
||||
|
||||
M.root_dir = function(fname)
|
||||
|
|
15
lua/cosmic/lsp/utils.lua
Normal file
15
lua/cosmic/lsp/utils.lua
Normal file
|
@ -0,0 +1,15 @@
|
|||
local user_config = require('cosmic.core.user')
|
||||
local M = {}
|
||||
|
||||
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
|
||||
|
||||
return M
|
Loading…
Add table
Reference in a new issue