diff --git a/lazy-lock.json b/lazy-lock.json index f1457a7..48c20d9 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -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", diff --git a/lua/cosmic/core/commands.lua b/lua/cosmic/core/commands.lua index 65cae6e..5d4c825 100644 --- a/lua/cosmic/core/commands.lua +++ b/lua/cosmic/core/commands.lua @@ -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() ]]) diff --git a/lua/cosmic/core/disabled.lua b/lua/cosmic/core/disabled.lua deleted file mode 100644 index a020426..0000000 --- a/lua/cosmic/core/disabled.lua +++ /dev/null @@ -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 diff --git a/lua/cosmic/core/init.lua b/lua/cosmic/core/init.lua index e7316bd..bc09c9f 100644 --- a/lua/cosmic/core/init.lua +++ b/lua/cosmic/core/init.lua @@ -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 diff --git a/lua/cosmic/core/pluginsInit.lua b/lua/cosmic/core/pluginsInit.lua index a3b0860..a77f48e 100644 --- a/lua/cosmic/core/pluginsInit.lua +++ b/lua/cosmic/core/pluginsInit.lua @@ -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', }, }, }, diff --git a/lua/cosmic/core/user.lua b/lua/cosmic/core/user.lua index 14ee6da..5c66de6 100644 --- a/lua/cosmic/core/user.lua +++ b/lua/cosmic/core/user.lua @@ -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 diff --git a/lua/cosmic/init.lua b/lua/cosmic/init.lua index 343d4a5..b94a217 100644 --- a/lua/cosmic/init.lua +++ b/lua/cosmic/init.lua @@ -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') diff --git a/lua/cosmic/lsp/commands.lua b/lua/cosmic/lsp/commands.lua index 3289756..ed43ebf 100644 --- a/lua/cosmic/lsp/commands.lua +++ b/lua/cosmic/lsp/commands.lua @@ -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, diff --git a/lua/cosmic/lsp/providers/defaults.lua b/lua/cosmic/lsp/providers/defaults.lua index badaaac..337e0cd 100644 --- a/lua/cosmic/lsp/providers/defaults.lua +++ b/lua/cosmic/lsp/providers/defaults.lua @@ -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 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) diff --git a/lua/cosmic/lsp/utils.lua b/lua/cosmic/lsp/utils.lua new file mode 100644 index 0000000..249efcf --- /dev/null +++ b/lua/cosmic/lsp/utils.lua @@ -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