diff --git a/lazy-lock.json b/lazy-lock.json index e4e9e38..6bf62c8 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,46 +1,45 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, - "LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" }, - "SchemaStore.nvim": { "branch": "main", "commit": "4d798fd5b692c8fce77268aba8f6f926b0c9f835" }, - "auto-session": { "branch": "main", "commit": "29a8c77a0579636d5520aebd38bdbc2e6079f2f5" }, + "LuaSnip": { "branch": "master", "commit": "2b6860d15aaab01d3fb90859c0ba97f20ad7bc5f" }, + "SchemaStore.nvim": { "branch": "main", "commit": "9fb66cf7b633a55b1c1a7d401f60bff48e6b8cfb" }, + "auto-session": { "branch": "main", "commit": "af2219b9fa99c1d7ac409bd9eac094c459d3f52d" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, - "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "cosmic-ui": { "branch": "main", "commit": "c0b14531999f2bfef3d927c4dcd57a1a8fed5ee9" }, - "friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" }, - "gitsigns.nvim": { "branch": "main", "commit": "078041e9d060a386b0c9d3a8c7a7b019a35d3fb0" }, - "lazy.nvim": { "branch": "main", "commit": "83493db50a434a4c5c648faf41e2ead80f96e478" }, - "lualine.nvim": { "branch": "master", "commit": "af4c3cf17206810880d2a93562e0a4c0d901c684" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "82c7cb08ddb836ad938b2708e50085f12a8825d2" }, - "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, - "neodev.nvim": { "branch": "main", "commit": "84e0290f5600e8b89c0dfcafc864f45496a53400" }, - "noice.nvim": { "branch": "main", "commit": "bf67d70bd7265d075191e7812d8eb42b9791f737" }, - "none-ls-extras.nvim": { "branch": "main", "commit": "c226aca7a506dd4325fb96188bffe804d24bbf18" }, + "friendly-snippets": { "branch": "main", "commit": "e11b09bf10706bb74e16e4c3d11b2274d62e687f" }, + "gitsigns.nvim": { "branch": "main", "commit": "379a5a915aea3e9ba0d4a778e8478584ac0f9011" }, + "lazy.nvim": { "branch": "main", "commit": "0fc34a0cf5f5f6f998a0897119a7d846b47eaa9d" }, + "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "a4caa0d083aab56f6cd5acf2d42331b74614a585" }, + "mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" }, + "neodev.nvim": { "branch": "main", "commit": "02893eeb9d6e8503817bd52385e111cba9a90500" }, + "noice.nvim": { "branch": "main", "commit": "29c7f030b0920e2f17263a9ab8742cde144b9140" }, + "none-ls-extras.nvim": { "branch": "main", "commit": "336e84b9e43c0effb735b08798ffac382920053b" }, "none-ls-shellcheck.nvim": { "branch": "main", "commit": "0f84461241e76e376a95fb7391deac82dc3efdbf" }, - "none-ls.nvim": { "branch": "main", "commit": "72e25ed4162474ef5d666525853f8a42bffd97c5" }, - "nui.nvim": { "branch": "main", "commit": "cbd2668414331c10039278f558630ed19b93e69b" }, - "nvim-autopairs": { "branch": "master", "commit": "797260ff31e8bdd9db0f0c352659a35aba335b0b" }, - "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, - "nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" }, - "nvim-lspconfig": { "branch": "master", "commit": "eb012f03bb3b4aca9e875d146008b923d0e07e65" }, - "nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" }, - "nvim-tree.lua": { "branch": "master", "commit": "f7c09bd72e50e1795bd3afb9e2a2b157b4bfb3c3" }, - "nvim-treesitter": { "branch": "master", "commit": "567a76780cd4f982dae1ec57e3dad6174bef3680" }, + "none-ls.nvim": { "branch": "main", "commit": "8691504118b252d64fc5023a104aedd100ab754a" }, + "nui.nvim": { "branch": "main", "commit": "322978c734866996274467de084a95e4f9b5e0b1" }, + "nvim-autopairs": { "branch": "master", "commit": "c15de7e7981f1111642e7e53799e1211d4606cb9" }, + "nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, + "nvim-lspconfig": { "branch": "master", "commit": "d1ab6b6051976b04948e127b0f302a465b1394d6" }, + "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, + "nvim-tree.lua": { "branch": "master", "commit": "26632f496e7e3c0450d8ecff88f49068cecc8bda" }, + "nvim-treesitter": { "branch": "master", "commit": "49e4e2b4b62360677568c47b6467f31c809b391c" }, "nvim-treesitter-refactor": { "branch": "master", "commit": "65ad2eca822dfaec2a3603119ec3cc8826a7859e" }, - "nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "7ab799a9792f7cf3883cf28c6a00ad431f3d382a" }, - "nvim-web-devicons": { "branch": "master", "commit": "cb0c967c9723a76ccb1be0cc3a9a10e577d2f6ec" }, + "nvim-ts-autotag": { "branch": "main", "commit": "6eb4120a1aadef07ac312f1c4bc6456712220007" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" }, + "nvim-web-devicons": { "branch": "master", "commit": "b77921fdc44833c994fdb389d658ccbce5490c16" }, "nx.nvim": { "branch": "main", "commit": "f8a3a21b3d540889401a40d1f2803083794c0372" }, - "plenary.nvim": { "branch": "master", "commit": "f7adfc4b3f4f91aab6caebf42b3682945fbc35be" }, + "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, - "telescope.nvim": { "branch": "master", "commit": "c816406bd50ade6ec754474f08974154487d417c" }, - "todo-comments.nvim": { "branch": "main", "commit": "833d8dd8b07eeda37a09e99460f72a02616935cb" }, - "tokyonight.nvim": { "branch": "main", "commit": "c025baf23b62f044eff1f4ef561c45de636f0e32" }, - "typescript-tools.nvim": { "branch": "master", "commit": "c43d9580c3ff5999a1eabca849f807ab33787ea7" }, - "vim-floaterm": { "branch": "master", "commit": "c0535d758004bcce016839e318cbbe802b92c469" }, - "vim-fugitive": { "branch": "master", "commit": "8d4e8d45385c63a0bf735fe1164772116bf0da0d" }, - "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" } + "telescope.nvim": { "branch": "master", "commit": "dfa230be84a044e7f546a6c2b0a403c739732b86" }, + "todo-comments.nvim": { "branch": "main", "commit": "70a93ce66083699571adc361166504b03cc39c2b" }, + "tokyonight.nvim": { "branch": "main", "commit": "7e5ef71a103e7de5fe6c05f5d6ab97d1640f08cf" }, + "vim-floaterm": { "branch": "master", "commit": "4e28c8dd0271e10a5f55142fb6fe9b1599ee6160" }, + "vim-fugitive": { "branch": "master", "commit": "4f59455d2388e113bd510e85b310d15b9228ca0d" }, + "which-key.nvim": { "branch": "main", "commit": "4b7167f8fb2dba3d01980735e3509e172c024c29" } } \ No newline at end of file diff --git a/lua/cosmic/core/user.lua b/lua/cosmic/core/user.lua index ca80b12..9d5f081 100644 --- a/lua/cosmic/core/user.lua +++ b/lua/cosmic/core/user.lua @@ -9,15 +9,7 @@ local default_config = { border = 'rounded', disable_builtin_plugins = {}, add_plugins = {}, - plugins = { - lsp_lines = { - -- additional flag only for CosmicNvim - -- true - loads plugin and is enabled at start - -- false - loads plugin but is not enabled at start - -- you may use ld to toggle - enable_on_start = false, - }, - }, + plugins = {}, lsp = { inlay_hint = false, format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',} diff --git a/lua/cosmic/lsp/diagnostics/config.lua b/lua/cosmic/lsp/diagnostics/config.lua deleted file mode 100644 index 783769f..0000000 --- a/lua/cosmic/lsp/diagnostics/config.lua +++ /dev/null @@ -1,50 +0,0 @@ -local u = require('cosmic.utils') -local icons = require('cosmic.utils.icons') -local user_config = require('cosmic.core.user') - -local function format_diagnostic(diagnostic) - local icon = icons.error - if diagnostic.severity == vim.diagnostic.severity.WARN then - icon = icons.warn - elseif diagnostic.severity == vim.diagnostic.severity.INFO then - icon = icons.info - elseif diagnostic.severity == vim.diagnostic.severity.HINT then - icon = icons.hint - end - - local message = string.format('%s %s', icon, diagnostic.message) - if diagnostic.code and diagnostic.source then - message = string.format('%s [%s][%s] %s', icon, diagnostic.source, diagnostic.code, diagnostic.message) - elseif diagnostic.code or diagnostic.source then - message = string.format('%s [%s] %s', icon, diagnostic.code or diagnostic.source, diagnostic.message) - end - - return message .. ' ' -end - -local config = u.merge({ - underline = true, - signs = true, - update_in_insert = false, - severity_sort = true, - float = { - border = user_config.border, - focusable = false, - header = { icons.debug .. ' Diagnostics:', 'DiagnosticInfo' }, - scope = 'line', - suffix = '', - source = false, - format = format_diagnostic, - }, - virtual_text = { - prefix = '', - spacing = 2, - source = false, - severity = { - min = vim.diagnostic.severity.HINT, - }, - format = format_diagnostic, - }, -}, user_config.diagnostic or {}) - -return config diff --git a/lua/cosmic/lsp/diagnostics/init.lua b/lua/cosmic/lsp/diagnostics/init.lua index ee71c88..9f58b34 100644 --- a/lua/cosmic/lsp/diagnostics/init.lua +++ b/lua/cosmic/lsp/diagnostics/init.lua @@ -1,19 +1,64 @@ +local u = require('cosmic.utils') local icons = require('cosmic.utils.icons') -local config = require('cosmic.lsp.diagnostics.config') +local user_config = require('cosmic.core.user') --- set up LSP signs -local signs = { - Error = icons.error .. ' ', - Warn = icons.warn .. ' ', - Hint = icons.hint .. ' ', - Info = icons.info .. ' ', -} +local function format_diagnostic(diagnostic) + local icon = icons.error + if diagnostic.severity == vim.diagnostic.severity.WARN then + icon = icons.warn + elseif diagnostic.severity == vim.diagnostic.severity.INFO then + icon = icons.info + elseif diagnostic.severity == vim.diagnostic.severity.HINT then + icon = icons.hint + end --- Set up diagnostic signs -for type, icon in pairs(signs) do - local hl = 'DiagnosticSign' .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' }) + local message = string.format('%s %s', icon, diagnostic.message) + if diagnostic.code and diagnostic.source then + message = string.format('%s [%s][%s] %s', icon, diagnostic.source, diagnostic.code, diagnostic.message) + elseif diagnostic.code or diagnostic.source then + message = string.format('%s [%s] %s', icon, diagnostic.code or diagnostic.source, diagnostic.message) + end + + return message .. ' ' end +local config = u.merge({ + underline = true, + update_in_insert = false, + severity_sort = true, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = icons.error .. ' ', + [vim.diagnostic.severity.HINT] = icons.hint .. ' ', + [vim.diagnostic.severity.INFO] = icons.info .. ' ', + [vim.diagnostic.severity.WARN] = icons.warn .. ' ', + }, + numhl = { + [vim.diagnostic.severity.ERROR] = 'ErrorMsg', + [vim.diagnostic.severity.HINT] = 'DiagnosticsSignHint', + [vim.diagnostic.severity.INFO] = 'DiagnosticsSignInfo', + [vim.diagnostic.severity.WARN] = 'WarningMsg', + }, + }, + float = { + border = user_config.border, + focusable = false, + header = { icons.debug .. ' Diagnostics:', 'DiagnosticInfo' }, + scope = 'line', + suffix = '', + source = false, + format = format_diagnostic, + }, + virtual_text = { + prefix = '', + spacing = 2, + source = false, + severity = { + min = vim.diagnostic.severity.HINT, + }, + format = format_diagnostic, + }, +}, user_config.diagnostic or {}) + -- set up diagnostics vim.diagnostic.config(config) diff --git a/lua/cosmic/lsp/providers/defaults.lua b/lua/cosmic/lsp/providers/defaults.lua index 1955f19..09590b3 100644 --- a/lua/cosmic/lsp/providers/defaults.lua +++ b/lua/cosmic/lsp/providers/defaults.lua @@ -21,7 +21,9 @@ function M.on_attach(client, bufnr) if client.supports_method('textDocument/formatting') then -- set up :LspFormat for clients that are capable - vim.cmd(string.format("command! -nargs=? LspFormat lua require('cosmic.utils.lsp').format(%s, )", bufnr)) + vim.cmd( + string.format("command! -nargs=? LspFormat lua require('cosmic.utils.lsp').force_format(%s, )", bufnr) + ) -- set up auto format on save if user_config.lsp.format_on_save then @@ -29,7 +31,7 @@ function M.on_attach(client, bufnr) -- collect filetype(s) from user config local filetype_patterns = {} local filetype_allowed = false - if vim.tbl_islist(user_config.lsp.format_on_save) then + if vim.islist(user_config.lsp.format_on_save) then filetype_patterns = user_config.lsp.format_on_save else -- any filetype if none set filetype_allowed = true @@ -75,11 +77,4 @@ M.capabilities = u.merge(capabilities, { }, }) -M.root_dir = function(fname) - local util = require('lspconfig').util - return util.root_pattern('.git', 'tsconfig.base.json', 'tsconfig.json', 'package.json', '.eslint.js', '.eslint.json')( - fname - ) -end - return M diff --git a/lua/cosmic/lsp/providers/eslint.lua b/lua/cosmic/lsp/providers/eslint.lua index b8b1c79..bc6be17 100644 --- a/lua/cosmic/lsp/providers/eslint.lua +++ b/lua/cosmic/lsp/providers/eslint.lua @@ -7,4 +7,13 @@ return { command = 'EslintFixAll', }) end, + + settings = { + -- helps eslint find the eslintrc when it's placed in a subfolder instead of the cwd root + workingDirectories = { mode = 'auto' }, + -- allows to use flat config format + --[[ experimental = { ]] + --[[ useFlatConfig = true, ]] + --[[ }, ]] + }, } diff --git a/lua/cosmic/lsp/providers/tsserver.lua b/lua/cosmic/lsp/providers/tsserver.lua index 167b819..4f0628f 100644 --- a/lua/cosmic/lsp/providers/tsserver.lua +++ b/lua/cosmic/lsp/providers/tsserver.lua @@ -5,4 +5,17 @@ function M.on_attach(client, bufnr) default_on_attach(client, bufnr) end +M.root_dir = function(fname) + local util = require('lspconfig').util + return util.root_pattern( + '.git', + 'tsconfig.base.json', + 'tsconfig.json', + 'package.json', + '.eslint.js', + '.eslint.json', + 'eslint.config.js' + )(fname) +end + return M diff --git a/lua/cosmic/plugins/null-ls/init.lua b/lua/cosmic/plugins/null-ls/init.lua index 310866b..d4f0c9f 100644 --- a/lua/cosmic/plugins/null-ls/init.lua +++ b/lua/cosmic/plugins/null-ls/init.lua @@ -25,9 +25,6 @@ return { config_opts.sources = u.merge_list({ null_ls.builtins.code_actions.gitsigns, null_ls.builtins.diagnostics.markdownlint, - require('none-ls.diagnostics.eslint_d'), - require('none-ls.formatting.eslint_d'), - require('none-ls.code_actions.eslint_d'), null_ls.builtins.formatting.prettierd.with({ env = { PRETTIERD_LOCAL_PRETTIER_ONLY = 1, @@ -40,6 +37,6 @@ return { null_ls.setup(u.merge(defaults, config_opts)) end, - event = 'BufReadPre', + event = 'VeryLazy', enabled = not vim.tbl_contains(user_config.disable_builtin_plugins, 'null_ls'), } diff --git a/lua/cosmic/utils/lsp.lua b/lua/cosmic/utils/lsp.lua index 145ef02..f925ed6 100644 --- a/lua/cosmic/utils/lsp.lua +++ b/lua/cosmic/utils/lsp.lua @@ -28,6 +28,20 @@ function M.toggle_format_on_save() vim.notify(string.format('Format on save disabled: %s', M.format_disabled_override)) end +function M.force_format(bufnr, timeout) + if timeout == '' or timeout == nil then + timeout = user_config.lsp.format_timeout + else + timeout = timeout * 1000 + end + local filter = can_client_format + vim.lsp.buf.format({ + timeout_ms = timeout, + filter = filter, + bufnr = bufnr or 0, + }) +end + -- format current buffer w/user settings function M.format(bufnr, timeout) if timeout == '' or timeout == nil then