diff options
Diffstat (limited to 'store/config/nvim')
-rw-r--r-- | store/config/nvim/init.lua | 2 | ||||
-rw-r--r-- | store/config/nvim/lazy-lock.json | 11 | ||||
-rw-r--r-- | store/config/nvim/lua/plugins.lua | 1 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/init.lua | 2 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/lsp.lua | 47 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/plugins/conform.lua | 18 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/plugins/init.lua | 1 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/plugins/lint.lua | 80 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/win.lua | 1 |
9 files changed, 86 insertions, 77 deletions
diff --git a/store/config/nvim/init.lua b/store/config/nvim/init.lua index d038019..ac6961a 100644 --- a/store/config/nvim/init.lua +++ b/store/config/nvim/init.lua @@ -1,3 +1,5 @@ +vim.crupest = {} + local lazy_path = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.uv.fs_stat(lazy_path) then vim.fn.system({ diff --git a/store/config/nvim/lazy-lock.json b/store/config/nvim/lazy-lock.json index f323937..4f6c2b5 100644 --- a/store/config/nvim/lazy-lock.json +++ b/store/config/nvim/lazy-lock.json @@ -3,16 +3,15 @@ "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, - "conform.nvim": { "branch": "master", "commit": "0e93e0d12d2f7ebdea9e3e444dfaff0050cefbe6" }, - "gitsigns.nvim": { "branch": "main", "commit": "d0f90ef51d4be86b824b012ec52ed715b5622e51" }, + "gitsigns.nvim": { "branch": "main", "commit": "731b581428ec6c1ccb451b95190ebbc6d7006db7" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" }, + "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, "neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" }, - "nui.nvim": { "branch": "main", "commit": "7cd18e73cfbd70e1546931b7268b3eebaeff9391" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-autopairs": { "branch": "master", "commit": "4d74e75913832866aa7de35e4202463ddf6efd1b" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, - "nvim-lint": { "branch": "master", "commit": "cc26ae6a620298bb3f33b0e0681f99a10ae57781" }, - "nvim-lspconfig": { "branch": "master", "commit": "a182334ba933e58240c2c45e6ae2d9c7ae313e00" }, + "nvim-lint": { "branch": "master", "commit": "2b0039b8be9583704591a13129c600891ac2c596" }, + "nvim-lspconfig": { "branch": "master", "commit": "7ad4a11cc5742774877c529fcfb2702f7caf75e4" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, diff --git a/store/config/nvim/lua/plugins.lua b/store/config/nvim/lua/plugins.lua index 8458575..85de362 100644 --- a/store/config/nvim/lua/plugins.lua +++ b/store/config/nvim/lua/plugins.lua @@ -37,5 +37,4 @@ return { { "hrsh7th/cmp-path" }, { "windwp/nvim-autopairs" }, { "mfussenegger/nvim-lint" }, - { 'stevearc/conform.nvim' } } diff --git a/store/config/nvim/lua/setup/init.lua b/store/config/nvim/lua/setup/init.lua index ec8c8d4..bbce01c 100644 --- a/store/config/nvim/lua/setup/init.lua +++ b/store/config/nvim/lua/setup/init.lua @@ -1,5 +1,3 @@ --- spellchecker: words termguicolors - local function close_float() local wins = vim.api.nvim_list_wins() for _, v in ipairs(wins) do diff --git a/store/config/nvim/lua/setup/lsp.lua b/store/config/nvim/lua/setup/lsp.lua index a11ad34..4216f1c 100644 --- a/store/config/nvim/lua/setup/lsp.lua +++ b/store/config/nvim/lua/setup/lsp.lua @@ -1,5 +1,3 @@ --- spellchecker: words denols luals - vim.lsp.config("*", { capabilities = vim.tbl_extend("force", vim.lsp.protocol.make_client_capabilities(), @@ -24,15 +22,23 @@ local function setup_clangd() vim.lsp.config("clangd", { cmd = { clangd } }) - vim.api.nvim_create_autocmd('LspAttach', { + vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) if client_name_is(ev, "clangd") then - vim.keymap.set('n', 'grs', "<cmd>ClangdSwitchSourceHeader<cr>", { + vim.keymap.set("n", "grs", "<cmd>ClangdSwitchSourceHeader<cr>", { buffer = ev.buf }) end end }) + + vim.api.nvim_create_autocmd("LspDetach", { + callback = function(ev) + if client_name_is(ev, "clangd") then + vim.keymap.del("n", "grs", { buffer = ev.buf }) + end + end + }) end local function setup_lua_ls() @@ -57,6 +63,11 @@ local function setup_lua_ls() }) end +function vim.crupest.no_range_format() + print("Lsp doesn't support range formatting. Use gqa to format the whole document.") + return 0 +end + local function setup_denols() vim.lsp.config("denols", { root_dir = function(bufnr, on_dir) @@ -69,10 +80,22 @@ local function setup_denols() end, }) - vim.api.nvim_create_autocmd('LspAttach', { + vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) if client_name_is(ev, "denols") then - vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + vim.api.nvim_set_option_value( + "formatexpr", + "v:lua.vim.crupest.no_range_format()", + { buf = ev.buf } + ) + end + end + }) + + vim.api.nvim_create_autocmd("LspDetach", { + callback = function(ev) + if client_name_is(ev, "denols") then + vim.api.nvim_set_option_value("formatexpr", "", { buf = ev.buf }) end end }) @@ -80,6 +103,18 @@ end local function setup() + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(ev) + vim.keymap.set("n", "gqa", vim.lsp.buf.format, { buffer = ev.buf }) + end + }) + + vim.api.nvim_create_autocmd("LspDetach", { + callback = function(ev) + vim.keymap.del("n", "gqa", { buffer = ev.buf }) + end + }) + setup_clangd() setup_lua_ls() setup_denols() diff --git a/store/config/nvim/lua/setup/plugins/conform.lua b/store/config/nvim/lua/setup/plugins/conform.lua deleted file mode 100644 index e14c3f9..0000000 --- a/store/config/nvim/lua/setup/plugins/conform.lua +++ /dev/null @@ -1,18 +0,0 @@ -local function setup() - require("conform").setup({ - formatters_by_ft = { - javascript = { "prettierd", "prettier", stop_after_first = true }, - typescript = { "prettierd", "prettier", stop_after_first = true }, - javascriptreact = { "prettierd", "prettier", stop_after_first = true }, - typescriptreact = { "prettierd", "prettier", stop_after_first = true }, - markdown = { "prettierd", "prettier", stop_after_first = true }, - }, - default_format_opts = { - lsp_format = "fallback", - }, - }) -end - -return { - setup = setup -} diff --git a/store/config/nvim/lua/setup/plugins/init.lua b/store/config/nvim/lua/setup/plugins/init.lua index 88eca4f..8f1346b 100644 --- a/store/config/nvim/lua/setup/plugins/init.lua +++ b/store/config/nvim/lua/setup/plugins/init.lua @@ -15,7 +15,6 @@ local function setup() require("setup.plugins.tree-sitter").setup() require("setup.plugins.lint").setup() - require("setup.plugins.conform").setup() require("setup.plugins.cmp").setup() require("nvim-autopairs").setup {} end diff --git a/store/config/nvim/lua/setup/plugins/lint.lua b/store/config/nvim/lua/setup/plugins/lint.lua index 928841d..d03f539 100644 --- a/store/config/nvim/lua/setup/plugins/lint.lua +++ b/store/config/nvim/lua/setup/plugins/lint.lua @@ -1,4 +1,6 @@ -local lint = require("lint") +--- spellchecker: ignore markdownlintrc + +---@alias CruLinter { name: string, config_patterns: string[], filetypes: string[] | nil, fast: boolean } local cspell = { name = "cspell", @@ -31,15 +33,30 @@ local markdownlint = { fast = true, } -local linters = { cspell, markdownlint } - -local linter_names = vim.tbl_map(function(l) return l.name end, linters) +local linters = { cspell = cspell, markdownlint = markdownlint } -local function cru_lint(linter, opt) - opt = opt or {} +---@param linter CruLinter +---@param buf integer +---@return string | nil +local function find_config(linter, buf) + local files = vim.fs.find(linter.config_patterns, { + path = vim.api.nvim_buf_get_name(buf), upward = true }) + if #files ~= 0 then + return files[1]; + end + return nil +end - local buf = opt.buf or 0 +vim.list_extend(require("lint.linters.markdownlint").args, { + "--config", + function() + return find_config(markdownlint, 0); + end +}) +---@param linter CruLinter +---@param buf integer +function vim.crupest.lint(linter, buf) if linter.filetypes then local filetype = vim.api.nvim_get_option_value("filetype", { buf = buf }) if not vim.list_contains(linter.filetypes, filetype) then @@ -47,50 +64,29 @@ local function cru_lint(linter, opt) end end - if 0 ~= #vim.fs.find(linter.config_patterns, { - path = vim.api.nvim_buf_get_name(opt.buf), upward = true }) then - lint.try_lint(linter.name) + if find_config(linter, buf) then + require("lint").try_lint(linter.name) end end -local function cru_lint_one(name, opt) - for _, linter in ipairs(linters) do - if linter.name == name then - cru_lint(linter, opt) - return - end - end - vim.notify("No linter named " .. name .. " is configured.", vim.log.levels.ERROR, {}) -end - -local function cru_lint_all(opt, fast) - for _, linter in ipairs(linters) do +function vim.crupest.lint_all(buf, fast) + for _, linter in pairs(linters) do if not fast or linter.fast then - cru_lint(linter, opt) + vim.crupest.lint(linter, buf) end end end -local function cru_lint_all_fast(opt) - local buf = opt.buf - if vim.api.nvim_get_option_value("buftype", { buf = buf }) == "" then - cru_lint_all(opt, true) - end -end - local function setup() - vim.api.nvim_create_autocmd({ "BufReadPost", "InsertLeave", "TextChanged" }, { callback = cru_lint_all_fast }) - - local function cru_lint_cmd(opt) - if #opt.args == 0 then - cru_lint_all(opt, false) - else - cru_lint_one(opt.args, opt) - end - end - - vim.api.nvim_create_user_command("CruLint", cru_lint_cmd, - { nargs = '?', complete = function() return linter_names end }) + vim.api.nvim_create_autocmd( + { "BufReadPost", "InsertLeave", "TextChanged" }, + { + callback = function(opt) + if vim.api.nvim_get_option_value("buftype", { buf = opt.buf }) == "" then + vim.crupest.lint_all(opt.buf, true) + end + end + }) end return { diff --git a/store/config/nvim/lua/setup/win.lua b/store/config/nvim/lua/setup/win.lua index 90e168a..9aa979d 100644 --- a/store/config/nvim/lua/setup/win.lua +++ b/store/config/nvim/lua/setup/win.lua @@ -1,4 +1,3 @@ --- spellchecker: words pwsh -- spellchecker: ignore shellcmdflag shellredir shellpipe shellquote shellxquote local function setup() vim.cmd([[ |