From 8c2205c39ce67699e7fa4742564cf140c75920d0 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Sun, 12 Feb 2023 22:26:21 +0800 Subject: [PATCH 01/24] migrate: from `efm` to `null-ls` --- lua/modules/configs/completion/lsp.lua | 41 +--------- .../completion/mason-tool-installer.lua | 23 ++++-- lua/modules/configs/completion/null-ls.lua | 81 +++++++++++++++++++ lua/modules/plugins/completion.lua | 8 +- 4 files changed, 106 insertions(+), 47 deletions(-) create mode 100644 lua/modules/configs/completion/null-ls.lua diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index b7a3de119..aab882dff 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -1,5 +1,5 @@ return function() - local formatting = require("completion.formatting") + -- local formatting = require("completion.formatting") local nvim_lsp = require("lspconfig") local mason = require("mason") @@ -36,7 +36,6 @@ return function() ensure_installed = { "bashls", "clangd", - "efm", "gopls", "pyright", "sumneko_lua", @@ -85,10 +84,6 @@ return function() nvim_lsp.clangd.setup(final_opts) end, - efm = function() - -- Do not setup efm - end, - gopls = function() local _opts = require("completion.servers.gopls") local final_opts = vim.tbl_deep_extend("keep", _opts, opts) @@ -140,37 +135,5 @@ return function() -- local rustfmt = require("completion.efm.formatters.rustfmt") local clangfmt = require("completion.efm.formatters.clangfmt") - -- Override default config here - - flake8 = vim.tbl_extend("force", flake8, { - prefix = "flake8: max-line-length=160, ignore F403 and F405", - lintStdin = true, - lintIgnoreExitCode = true, - lintFormats = { "%f:%l:%c: %t%n%n%n %m" }, - lintCommand = "flake8 --max-line-length 160 --extend-ignore F403,F405 --format '%(path)s:%(row)d:%(col)d: %(code)s %(code)s %(text)s' --stdin-display-name ${INPUT} -", - }) - - -- Setup formatter and linter for efmls here - - efmls.setup({ - vim = { formatter = vint }, - lua = { formatter = stylua }, - c = { formatter = clangfmt }, - cpp = { formatter = clangfmt }, - python = { formatter = black }, - vue = { formatter = prettier }, - typescript = { formatter = prettier, linter = eslint }, - javascript = { formatter = prettier, linter = eslint }, - typescriptreact = { formatter = prettier, linter = eslint }, - javascriptreact = { formatter = prettier, linter = eslint }, - yaml = { formatter = prettier }, - html = { formatter = prettier }, - css = { formatter = prettier }, - scss = { formatter = prettier }, - sh = { formatter = shfmt }, - markdown = { formatter = prettier }, - -- rust = {formatter = rustfmt}, - }) - - formatting.configure_format_on_save() + -- formatting.configure_format_on_save() end diff --git a/lua/modules/configs/completion/mason-tool-installer.lua b/lua/modules/configs/completion/mason-tool-installer.lua index 37cbe657d..f856f2456 100644 --- a/lua/modules/configs/completion/mason-tool-installer.lua +++ b/lua/modules/configs/completion/mason-tool-installer.lua @@ -6,16 +6,27 @@ return function() -- you can turn off/on auto_update per tool -- "editorconfig-checker", - "stylua", + -- LSP + "bash-language-server", -- nvim-lspconfig: bashls + "clangd", + "gopls", + "html-lsp", -- nvim-lspconfig: html + "json-lsp", -- nvim-lspconfig: jsonls + "lua-language-server", -- nvim-lspconfig: lua_ls + "pyright", + -- formatter "black", - - "prettier", - - "shellcheck", + "clang-format", + "eslint_d", + "markdownlint", + "prettierd", + "rustfmt", "shfmt", + "stylua", - -- "vint", + -- diagnostics + "shellcheck", }, -- if set to true this will check each tool for updates. If updates diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua new file mode 100644 index 000000000..f89edf717 --- /dev/null +++ b/lua/modules/configs/completion/null-ls.lua @@ -0,0 +1,81 @@ +return function() + local null_ls = require("null-ls") + local disabled_worksapces = require("core.settings").format_disabled_dirs + local format_on_save = require("core.settings").format_on_save + + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins + local b = null_ls.builtins + + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + + local with_diagnostics_code = function(builtin) + return builtin.with({ + diagnostics_format = "#{m} [#{c}]", + }) + end + + local sources = { + -- formatting + + b.formatting.black.with({ extra_args = { "--fast" } }), + b.formatting.prettierd.with({ + extra_filetypes = { "toml" }, + extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" }, + }), + b.formatting.shfmt, + b.formatting.stylua, + b.formatting.markdownlint, + b.formatting.clang_format, + b.formatting.rustfmt, + b.formatting.eslint_d, + + -- diagnostics + with_diagnostics_code(b.diagnostics.shellcheck), + b.diagnostics.markdownlint.with({ + extra_args = { "--disable MD033" }, + }), + } + + null_ls.setup({ + debug = false, + update_in_insert = false, + diagnostics_format = "[#{c}] #{m} (#{s})", + sources = sources, + on_attach = function(client, bufnr) + local cwd = vim.fn.getcwd() + for i = 1, #disabled_worksapces do + if cwd.find(cwd, disabled_worksapces[i]) ~= nil then + return + end + end + if client.supports_method("textDocument/formatting") and format_on_save then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ + bufnr = bufnr, + name = "null-ls", + -- filter = function() + -- return client.name == "null-ls" + -- end, + }) + vim.notify( + string.format("Format successfully with [%s]!", client.name), + vim.log.levels.INFO, + { title = "LspFormat" } + ) + end, + }) + end + end, + }) + + -- NOTE: if you want to use local executables. + -- local sources = { + -- null_ls.builtins.formatting.prettier.with({ + -- command = "/path/to/prettier", + -- }), + -- } +end diff --git a/lua/modules/plugins/completion.lua b/lua/modules/plugins/completion.lua index a3cf64238..4e441aaba 100644 --- a/lua/modules/plugins/completion.lua +++ b/lua/modules/plugins/completion.lua @@ -5,7 +5,7 @@ completion["neovim/nvim-lspconfig"] = { event = { "BufReadPost", "BufAdd", "BufNewFile" }, config = require("completion.lsp"), dependencies = { - { "creativenull/efmls-configs-nvim" }, + { "ray-x/lsp_signature.nvim" }, { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" }, { @@ -16,7 +16,11 @@ completion["neovim/nvim-lspconfig"] = { "glepnir/lspsaga.nvim", config = require("completion.lspsaga"), }, - { "ray-x/lsp_signature.nvim" }, + { + "jose-elias-alvarez/null-ls.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + config = require("completion.null-ls"), + }, }, } completion["hrsh7th/nvim-cmp"] = { From 6de17c3945979168e0c99522768a516ece8815a6 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Sun, 12 Feb 2023 22:40:01 +0800 Subject: [PATCH 02/24] sync: use `nvim_buf_set_keymap` for filetype --- lua/core/event.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/core/event.lua b/lua/core/event.lua index 36fff75e6..8cac55ae6 100644 --- a/lua/core/event.lua +++ b/lua/core/event.lua @@ -47,7 +47,7 @@ vim.api.nvim_create_autocmd("FileType", { }, callback = function(event) vim.bo[event.buf].buflisted = false - vim.api.nvim_set_keymap("n", "q", "close", { buffer = event.buf, silent = true }) + vim.api.nvim_buf_set_keymap(event.buf, "n", "q", "close", { silent = true }) end, }) From 85cd6fc6a4a1248d2a02ac04be4ec10cbaabe5b3 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Sun, 12 Feb 2023 22:40:19 +0800 Subject: [PATCH 03/24] clean up --- lua/modules/configs/completion/lsp.lua | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index aab882dff..2bbbf2693 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -109,31 +109,31 @@ return function() nvim_lsp.html.setup(final_opts) end - local efmls = require("efmls-configs") + -- local efmls = require("efmls-configs") -- Init `efm-langserver` here. - efmls.init({ - on_attach = opts.on_attach, - capabilities = capabilities, - init_options = { documentFormatting = true, codeAction = true }, - }) + -- efmls.init({ + -- on_attach = opts.on_attach, + -- capabilities = capabilities, + -- init_options = { documentFormatting = true, codeAction = true }, + --}) -- Require `efmls-configs-nvim`'s config here - local vint = require("efmls-configs.linters.vint") - local eslint = require("efmls-configs.linters.eslint") - local flake8 = require("efmls-configs.linters.flake8") + --local vint = require("efmls-configs.linters.vint") + --local eslint = require("efmls-configs.linters.eslint") + --local flake8 = require("efmls-configs.linters.flake8") - local black = require("efmls-configs.formatters.black") - local stylua = require("efmls-configs.formatters.stylua") - local prettier = require("efmls-configs.formatters.prettier") - local shfmt = require("efmls-configs.formatters.shfmt") + --local black = require("efmls-configs.formatters.black") + --local stylua = require("efmls-configs.formatters.stylua") + --local prettier = require("efmls-configs.formatters.prettier") + --local shfmt = require("efmls-configs.formatters.shfmt") -- Add your own config for formatter and linter here -- local rustfmt = require("completion.efm.formatters.rustfmt") - local clangfmt = require("completion.efm.formatters.clangfmt") + --local clangfmt = require("completion.efm.formatters.clangfmt") -- formatting.configure_format_on_save() end From d5b6137043e6ff617e71a06315475d235954864a Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 08:59:27 +0800 Subject: [PATCH 04/24] sync: rename `sumneko_lua` to `lua_ls` --- lua/modules/configs/completion/lsp.lua | 9 +++++---- .../completion/servers/{sumneko_lua.lua => lua_ls.lua} | 0 2 files changed, 5 insertions(+), 4 deletions(-) rename lua/modules/configs/completion/servers/{sumneko_lua.lua => lua_ls.lua} (100%) diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index 2bbbf2693..85bcc6400 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -37,8 +37,9 @@ return function() "bashls", "clangd", "gopls", + "html", + "lua_ls", "pyright", - "sumneko_lua", }, }) @@ -96,10 +97,10 @@ return function() nvim_lsp.jsonls.setup(final_opts) end, - sumneko_lua = function() - local _opts = require("completion.servers.sumneko_lua") + lua_ls = function() + local _opts = require("completion.servers.lua_ls") local final_opts = vim.tbl_deep_extend("keep", _opts, opts) - nvim_lsp.sumneko_lua.setup(final_opts) + nvim_lsp.lua_ls.setup(final_opts) end, }) diff --git a/lua/modules/configs/completion/servers/sumneko_lua.lua b/lua/modules/configs/completion/servers/lua_ls.lua similarity index 100% rename from lua/modules/configs/completion/servers/sumneko_lua.lua rename to lua/modules/configs/completion/servers/lua_ls.lua From 4e8e9ea4dae812ebc05c5aca872f8f5f6f3a1cb5 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 08:59:40 +0800 Subject: [PATCH 05/24] clean up --- lua/modules/configs/completion/mason-tool-installer.lua | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lua/modules/configs/completion/mason-tool-installer.lua b/lua/modules/configs/completion/mason-tool-installer.lua index f856f2456..d1420475a 100644 --- a/lua/modules/configs/completion/mason-tool-installer.lua +++ b/lua/modules/configs/completion/mason-tool-installer.lua @@ -6,15 +6,6 @@ return function() -- you can turn off/on auto_update per tool -- "editorconfig-checker", - -- LSP - "bash-language-server", -- nvim-lspconfig: bashls - "clangd", - "gopls", - "html-lsp", -- nvim-lspconfig: html - "json-lsp", -- nvim-lspconfig: jsonls - "lua-language-server", -- nvim-lspconfig: lua_ls - "pyright", - -- formatter "black", "clang-format", From dbd6a9d5cd8261f505c219626e6c560eb782e898 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 10:23:25 +0800 Subject: [PATCH 06/24] chore: move `html_ls` to `mason_lspconfig.setup` --- lua/modules/configs/completion/lsp.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index 85bcc6400..fad7ebb48 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -33,6 +33,7 @@ return function() }, }) mason_lspconfig.setup({ + -- NOTE: use the lsp names in nvim-lspconfig ensure_installed = { "bashls", "clangd", @@ -91,6 +92,12 @@ return function() nvim_lsp.gopls.setup(final_opts) end, + html = function() + local _opts = require("completion.servers.html") + local final_opts = vim.tbl_deep_extend("keep", _opts, opts) + nvim_lsp.html.setup(final_opts) + end, + jsonls = function() local _opts = require("completion.servers.jsonls") local final_opts = vim.tbl_deep_extend("keep", _opts, opts) @@ -104,12 +111,6 @@ return function() end, }) - if vim.fn.executable("html-languageserver") then - local _opts = require("completion.servers.html") - local final_opts = vim.tbl_deep_extend("keep", _opts, opts) - nvim_lsp.html.setup(final_opts) - end - -- local efmls = require("efmls-configs") -- Init `efm-langserver` here. From 12db5af9bca6261052ce423d495500a0d268f3c0 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 10:23:50 +0800 Subject: [PATCH 07/24] chore: move formatter argss to `null-ls.lua` --- lua/modules/configs/completion/efm/formatters/clangfmt.lua | 1 - lua/modules/configs/completion/efm/formatters/rustfmt.lua | 1 - lua/modules/configs/completion/null-ls.lua | 5 +++-- 3 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 lua/modules/configs/completion/efm/formatters/clangfmt.lua delete mode 100644 lua/modules/configs/completion/efm/formatters/rustfmt.lua diff --git a/lua/modules/configs/completion/efm/formatters/clangfmt.lua b/lua/modules/configs/completion/efm/formatters/clangfmt.lua deleted file mode 100644 index 53548aa3c..000000000 --- a/lua/modules/configs/completion/efm/formatters/clangfmt.lua +++ /dev/null @@ -1 +0,0 @@ -return { formatCommand = "clang-format -style='{BasedOnStyle: LLVM, IndentWidth: 4}'", formatStdin = true } diff --git a/lua/modules/configs/completion/efm/formatters/rustfmt.lua b/lua/modules/configs/completion/efm/formatters/rustfmt.lua deleted file mode 100644 index c988fed74..000000000 --- a/lua/modules/configs/completion/efm/formatters/rustfmt.lua +++ /dev/null @@ -1 +0,0 @@ -return { formatCommand = "rustfmt", formatStdin = true } diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index f89edf717..b791e2f87 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -19,13 +19,14 @@ return function() b.formatting.black.with({ extra_args = { "--fast" } }), b.formatting.prettierd.with({ - extra_filetypes = { "toml" }, extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" }, }), b.formatting.shfmt, b.formatting.stylua, b.formatting.markdownlint, - b.formatting.clang_format, + b.formatting.clang_format.with({ + command = "clang-format -style='{BasedOnStyle: LLVM, IndentWidth: 4}'", + }), b.formatting.rustfmt, b.formatting.eslint_d, From e3a8ea9dbda413ff6d5e7212cae274a0274758ff Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 10:28:47 +0800 Subject: [PATCH 08/24] sync(lua_ls): disable server-side formatting, use null-ls instead --- lua/modules/configs/completion/servers/lua_ls.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/modules/configs/completion/servers/lua_ls.lua b/lua/modules/configs/completion/servers/lua_ls.lua index 2becee53c..6d630f75c 100644 --- a/lua/modules/configs/completion/servers/lua_ls.lua +++ b/lua/modules/configs/completion/servers/lua_ls.lua @@ -14,6 +14,7 @@ return { maxPreload = 100000, preloadFileSize = 10000, }, + format = { enable = false }, telemetry = { enable = false }, -- Do not override treesitter lua highlighting with sumneko lua highlighting semantic = { enable = false }, From 1b9d180fb66c72be59f37f922f92aad9be1a9c61 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 10:29:27 +0800 Subject: [PATCH 09/24] clean up --- lua/modules/configs/completion/formatting.lua | 182 ------------------ lua/modules/configs/completion/lsp.lua | 30 --- 2 files changed, 212 deletions(-) delete mode 100644 lua/modules/configs/completion/formatting.lua diff --git a/lua/modules/configs/completion/formatting.lua b/lua/modules/configs/completion/formatting.lua deleted file mode 100644 index ca73f4eec..000000000 --- a/lua/modules/configs/completion/formatting.lua +++ /dev/null @@ -1,182 +0,0 @@ -local M = {} - -local settings = require("core.settings") -local disabled_workspaces = settings.format_disabled_dirs -local format_on_save = settings.format_on_save - -vim.api.nvim_create_user_command("FormatToggle", function() - M.toggle_format_on_save() -end, {}) - -local block_list = {} -vim.api.nvim_create_user_command("FormatterToggle", function(opts) - if block_list[opts.args] == nil then - vim.notify( - string.format("[LSP]Formatter for [%s] has been recorded in list and disabled.", opts.args), - vim.log.levels.WARN, - { title = "LSP Formatter Warning!" } - ) - block_list[opts.args] = true - else - block_list[opts.args] = not block_list[opts.args] - vim.notify( - string.format( - "[LSP]Formatter for [%s] has been %s.", - opts.args, - not block_list[opts.args] and "enabled" or "disabled" - ), - not block_list[opts.args] and vim.log.levels.INFO or vim.log.levels.WARN, - { title = string.format("LSP Formatter %s", not block_list[opts.args] and "Info" or "Warning") } - ) - end -end, { - nargs = 1, - complete = function() - return { - "markdown", - "vim", - "lua", - "c", - "cpp", - "python", - "vue", - "typescript", - "javascript", - "yaml", - "html", - "css", - "scss", - "sh", - "rust", - } - end, -}) - -function M.enable_format_on_save(is_configured) - local opts = { pattern = "*", timeout = 1000 } - vim.api.nvim_create_augroup("format_on_save", {}) - vim.api.nvim_create_autocmd("BufWritePre", { - group = "format_on_save", - pattern = opts.pattern, - callback = function() - require("completion.formatting").format({ timeout_ms = opts.timeout, filter = M.format_filter }) - end, - }) - if not is_configured then - vim.notify( - "Successfully enabled format-on-save", - vim.log.levels.INFO, - { title = "Settings modification success!" } - ) - end -end - -function M.disable_format_on_save() - pcall(vim.api.nvim_del_augroup_by_name, "format_on_save") - if format_on_save then - vim.notify("Disabled format-on-save", vim.log.levels.INFO, { title = "Settings modification success!" }) - end -end - -function M.configure_format_on_save() - if format_on_save then - M.enable_format_on_save(true) - else - M.disable_format_on_save() - end -end - -function M.toggle_format_on_save() - local status = pcall(vim.api.nvim_get_autocmds, { - group = "format_on_save", - event = "BufWritePre", - }) - if not status then - M.enable_format_on_save(false) - else - M.disable_format_on_save() - end -end - -function M.format_filter(clients) - return vim.tbl_filter(function(client) - local status_ok, formatting_supported = pcall(function() - return client.supports_method("textDocument/formatting") - end) - if status_ok and formatting_supported and client.name == "efm" then - return "efm" - elseif client.name ~= "sumneko_lua" and client.name ~= "tsserver" and client.name ~= "clangd" then - return status_ok and formatting_supported and client.name - end - end, clients) -end - -function M.format(opts) - local cwd = vim.fn.getcwd() - for i = 1, #disabled_workspaces do - if cwd.find(cwd, disabled_workspaces[i]) ~= nil then - return - end - end - - local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() - local clients = vim.lsp.buf_get_clients(bufnr) - - if opts.filter then - clients = opts.filter(clients) - elseif opts.id then - clients = vim.tbl_filter(function(client) - return client.id == opts.id - end, clients) - elseif opts.name then - clients = vim.tbl_filter(function(client) - return client.name == opts.name - end, clients) - end - - clients = vim.tbl_filter(function(client) - return client.supports_method("textDocument/formatting") - end, clients) - - if #clients == 0 then - vim.notify( - "[LSP] Format request failed, no matching language servers.", - vim.log.levels.WARN, - { title = "Formatting Failed!" } - ) - end - - local timeout_ms = opts.timeout_ms - for _, client in pairs(clients) do - if block_list[vim.bo.filetype] == true then - vim.notify( - string.format( - "[LSP][%s] formatter for [%s] has been disabled. This file was not processed.", - client.name, - vim.bo.filetype - ), - vim.log.levels.WARN, - { title = "LSP Formatter Warning!" } - ) - return - end - local params = vim.lsp.util.make_formatting_params(opts.formatting_options) - local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, bufnr) - if result and result.result then - vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding) - vim.notify( - string.format("Format successfully with %s!", client.name), - vim.log.levels.INFO, - { title = "LSP Format Success!" } - ) - elseif err then - vim.notify( - string.format("[LSP][%s] %s", client.name, err), - vim.log.levels.ERROR, - { title = "LSP Format Error!" } - ) - end - end -end - -return M diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index fad7ebb48..45a6d8b2c 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -1,6 +1,4 @@ return function() - -- local formatting = require("completion.formatting") - local nvim_lsp = require("lspconfig") local mason = require("mason") local mason_lspconfig = require("mason-lspconfig") @@ -110,32 +108,4 @@ return function() nvim_lsp.lua_ls.setup(final_opts) end, }) - - -- local efmls = require("efmls-configs") - - -- Init `efm-langserver` here. - - -- efmls.init({ - -- on_attach = opts.on_attach, - -- capabilities = capabilities, - -- init_options = { documentFormatting = true, codeAction = true }, - --}) - - -- Require `efmls-configs-nvim`'s config here - - --local vint = require("efmls-configs.linters.vint") - --local eslint = require("efmls-configs.linters.eslint") - --local flake8 = require("efmls-configs.linters.flake8") - - --local black = require("efmls-configs.formatters.black") - --local stylua = require("efmls-configs.formatters.stylua") - --local prettier = require("efmls-configs.formatters.prettier") - --local shfmt = require("efmls-configs.formatters.shfmt") - - -- Add your own config for formatter and linter here - - -- local rustfmt = require("completion.efm.formatters.rustfmt") - --local clangfmt = require("completion.efm.formatters.clangfmt") - - -- formatting.configure_format_on_save() end From 35881efbbfa3f8a2aa6061c7cb8b79a6625cc4b7 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 10:35:54 +0800 Subject: [PATCH 10/24] feat(mason-tool-installer): add notify after mason installation finished --- .../configs/completion/mason-tool-installer.lua | 10 ++++++++++ lua/modules/configs/completion/null-ls.lua | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lua/modules/configs/completion/mason-tool-installer.lua b/lua/modules/configs/completion/mason-tool-installer.lua index d1420475a..cd97088fa 100644 --- a/lua/modules/configs/completion/mason-tool-installer.lua +++ b/lua/modules/configs/completion/mason-tool-installer.lua @@ -31,4 +31,14 @@ return function() -- Default: true run_on_start = true, }) + + vim.api.nvim_create_autocmd("User", { + pattern = "MasonToolsUpdateCompleted", + callback = function() + vim.schedule(function() + print("mason-tool-installer has finished") + vim.notify("mason-tool-installer has finished!", vim.log.levels.INFO, { title = "MasonToolsInstaller" }) + end) + end, + }) end diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index b791e2f87..5aba3aafa 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -16,7 +16,6 @@ return function() local sources = { -- formatting - b.formatting.black.with({ extra_args = { "--fast" } }), b.formatting.prettierd.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" }, @@ -58,9 +57,6 @@ return function() vim.lsp.buf.format({ bufnr = bufnr, name = "null-ls", - -- filter = function() - -- return client.name == "null-ls" - -- end, }) vim.notify( string.format("Format successfully with [%s]!", client.name), @@ -72,11 +68,4 @@ return function() end end, }) - - -- NOTE: if you want to use local executables. - -- local sources = { - -- null_ls.builtins.formatting.prettier.with({ - -- command = "/path/to/prettier", - -- }), - -- } end From 4b4ac0451066709dc8be52907670cfb846fe33b6 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 10:39:31 +0800 Subject: [PATCH 11/24] chore(mason-tool-installer): set `run_on_start` to false --- lua/modules/configs/completion/mason-tool-installer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/modules/configs/completion/mason-tool-installer.lua b/lua/modules/configs/completion/mason-tool-installer.lua index cd97088fa..5ff754b6a 100644 --- a/lua/modules/configs/completion/mason-tool-installer.lua +++ b/lua/modules/configs/completion/mason-tool-installer.lua @@ -29,7 +29,7 @@ return function() -- will happen on startup. You can use `:MasonToolsUpdate` to install -- tools and check for updates. -- Default: true - run_on_start = true, + run_on_start = false, }) vim.api.nvim_create_autocmd("User", { From 438168f2e4368a8215227369ac62a8363579aee8 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Mon, 13 Feb 2023 12:54:00 +0800 Subject: [PATCH 12/24] chore(mason-lspconfig): add mason-lspconfig mapping list url --- lua/modules/configs/completion/lsp.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index 45a6d8b2c..0a3983b08 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -32,6 +32,7 @@ return function() }) mason_lspconfig.setup({ -- NOTE: use the lsp names in nvim-lspconfig + -- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/lua/mason-lspconfig/mappings/server.lua ensure_installed = { "bashls", "clangd", From 7d7881b08d0b21c3eb26a029f90e68c3cfadb49b Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Tue, 14 Feb 2023 11:39:31 +0800 Subject: [PATCH 13/24] chore: remove unnecessary part for `prettierd` --- lua/modules/configs/completion/null-ls.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index 5aba3aafa..c9eaed8ff 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -17,9 +17,7 @@ return function() local sources = { -- formatting b.formatting.black.with({ extra_args = { "--fast" } }), - b.formatting.prettierd.with({ - extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" }, - }), + b.formatting.prettierd, b.formatting.shfmt, b.formatting.stylua, b.formatting.markdownlint, From 76e93aa6fc49b0dbb5489a3f1920229c575922af Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Tue, 14 Feb 2023 14:49:52 +0800 Subject: [PATCH 14/24] migrate: from `mason-tool-installer` to `mason-null-ls` --- .../completion/mason-tool-installer.lua | 44 ------------------- lua/modules/configs/completion/null-ls.lua | 30 ++++++++----- lua/modules/plugins/completion.lua | 9 ++-- 3 files changed, 22 insertions(+), 61 deletions(-) delete mode 100644 lua/modules/configs/completion/mason-tool-installer.lua diff --git a/lua/modules/configs/completion/mason-tool-installer.lua b/lua/modules/configs/completion/mason-tool-installer.lua deleted file mode 100644 index 5ff754b6a..000000000 --- a/lua/modules/configs/completion/mason-tool-installer.lua +++ /dev/null @@ -1,44 +0,0 @@ -return function() - require("mason-tool-installer").setup({ - -- a list of all tools you want to ensure are installed upon - -- start; they should be the names Mason uses for each tool - ensure_installed = { - -- you can turn off/on auto_update per tool - -- "editorconfig-checker", - - -- formatter - "black", - "clang-format", - "eslint_d", - "markdownlint", - "prettierd", - "rustfmt", - "shfmt", - "stylua", - - -- diagnostics - "shellcheck", - }, - - -- if set to true this will check each tool for updates. If updates - -- are available the tool will be updated. - -- Default: false - auto_update = false, - - -- automatically install / update on startup. If set to false nothing - -- will happen on startup. You can use `:MasonToolsUpdate` to install - -- tools and check for updates. - -- Default: true - run_on_start = false, - }) - - vim.api.nvim_create_autocmd("User", { - pattern = "MasonToolsUpdateCompleted", - callback = function() - vim.schedule(function() - print("mason-tool-installer has finished") - vim.notify("mason-tool-installer has finished!", vim.log.levels.INFO, { title = "MasonToolsInstaller" }) - end) - end, - }) -end diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index c9eaed8ff..c6b0add1c 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -4,7 +4,7 @@ return function() local format_on_save = require("core.settings").format_on_save -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins - local b = null_ls.builtins + local btn = null_ls.builtins local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) @@ -16,20 +16,20 @@ return function() local sources = { -- formatting - b.formatting.black.with({ extra_args = { "--fast" } }), - b.formatting.prettierd, - b.formatting.shfmt, - b.formatting.stylua, - b.formatting.markdownlint, - b.formatting.clang_format.with({ - command = "clang-format -style='{BasedOnStyle: LLVM, IndentWidth: 4}'", + btn.formatting.black.with({ extra_args = { "--fast" } }), + btn.formatting.prettierd, + btn.formatting.shfmt, + btn.formatting.stylua, + btn.formatting.markdownlint, + btn.formatting.clang_format.with({ + command = "clang-format -style='{btnasedOnStyle: LLVM, IndentWidth: 4}'", }), - b.formatting.rustfmt, - b.formatting.eslint_d, + btn.formatting.rustfmt, + btn.formatting.eslint_d, -- diagnostics - with_diagnostics_code(b.diagnostics.shellcheck), - b.diagnostics.markdownlint.with({ + with_diagnostics_code(btn.diagnostics.shellcheck), + btn.diagnostics.markdownlint.with({ extra_args = { "--disable MD033" }, }), } @@ -66,4 +66,10 @@ return function() end end, }) + + require("mason-null-ls").setup({ + ensure_installed = nil, + automatic_installation = true, + automatic_setup = false, + }) end diff --git a/lua/modules/plugins/completion.lua b/lua/modules/plugins/completion.lua index 4e441aaba..8d885c29c 100644 --- a/lua/modules/plugins/completion.lua +++ b/lua/modules/plugins/completion.lua @@ -8,17 +8,16 @@ completion["neovim/nvim-lspconfig"] = { { "ray-x/lsp_signature.nvim" }, { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" }, - { - "WhoIsSethDaniel/mason-tool-installer.nvim", - config = require("completion.mason-tool-installer"), - }, { "glepnir/lspsaga.nvim", config = require("completion.lspsaga"), }, { "jose-elias-alvarez/null-ls.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, + dependencies = { + "nvim-lua/plenary.nvim", + "jay-babu/mason-null-ls.nvim", + }, config = require("completion.null-ls"), }, }, From 590b9f5bca703bac42820d302d42bfb7f775a70e Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Tue, 14 Feb 2023 14:54:17 +0800 Subject: [PATCH 15/24] feat: add `jq` for json formatting --- lua/modules/configs/completion/null-ls.lua | 15 ++-- snips/package.json | 75 +++++++++++++++---- snips/snippets/c.json | 18 ++--- snips/snippets/cpp.json | 85 ++++++++++------------ 4 files changed, 117 insertions(+), 76 deletions(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index c6b0add1c..e4bd9e02d 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -17,21 +17,18 @@ return function() local sources = { -- formatting btn.formatting.black.with({ extra_args = { "--fast" } }), + btn.formatting.clang_format.with({ command = "clang-format -style='{btnasedOnStyle: LLVM, IndentWidth: 4}'" }), + btn.formatting.eslint_d, + btn.formatting.jq, + btn.formatting.markdownlint, btn.formatting.prettierd, + btn.formatting.rustfmt, btn.formatting.shfmt, btn.formatting.stylua, - btn.formatting.markdownlint, - btn.formatting.clang_format.with({ - command = "clang-format -style='{btnasedOnStyle: LLVM, IndentWidth: 4}'", - }), - btn.formatting.rustfmt, - btn.formatting.eslint_d, -- diagnostics with_diagnostics_code(btn.diagnostics.shellcheck), - btn.diagnostics.markdownlint.with({ - extra_args = { "--disable MD033" }, - }), + btn.diagnostics.markdownlint.with({ extra_args = { "--disable MD033" } }), } null_ls.setup({ diff --git a/snips/package.json b/snips/package.json index 8ff8b639d..d3aa9d84d 100644 --- a/snips/package.json +++ b/snips/package.json @@ -6,7 +6,13 @@ "contributes": { "snippets": [ { - "language": ["plaintext", "markdown", "tex", "html", "global"], + "language": [ + "plaintext", + "markdown", + "tex", + "html", + "global" + ], "path": "./snippets/global.json" }, { @@ -18,11 +24,17 @@ "path": "./snippets/cpp.json" }, { - "language": ["csharp", "cs"], + "language": [ + "csharp", + "cs" + ], "path": "./snippets/csharp.json" }, { - "language": ["gitcommit", "NeogitCommitMessage"], + "language": [ + "gitcommit", + "NeogitCommitMessage" + ], "path": "./snippets/gitcommit.json" }, { @@ -106,15 +118,25 @@ "path": "./snippets/sql.json" }, { - "language": ["shellscript", "shell", "sh"], + "language": [ + "shellscript", + "shell", + "sh" + ], "path": "./snippets/shell.json" }, { - "language": ["markdown", "rmd"], + "language": [ + "markdown", + "rmd" + ], "path": "./snippets/markdown.json" }, { - "language": ["plaintex", "tex"], + "language": [ + "plaintex", + "tex" + ], "path": "./snippets/latex.json" }, { @@ -122,19 +144,37 @@ "path": "./snippets/java.json" }, { - "language": ["html", "jade", "pug", "eruby"], + "language": [ + "html", + "jade", + "pug", + "eruby" + ], "path": "./snippets/html.json" }, { - "language": ["css", "scss", "sass", "less", "stylus"], + "language": [ + "css", + "scss", + "sass", + "less", + "stylus" + ], "path": "./snippets/css.json" }, { - "language": ["javascript", "javascriptreact", "vue"], + "language": [ + "javascript", + "javascriptreact", + "vue" + ], "path": "./snippets/javascript/javascript.json" }, { - "language": ["typescript", "typescriptreact"], + "language": [ + "typescript", + "typescriptreact" + ], "path": "./snippets/javascript/typescript.json" }, { @@ -230,11 +270,17 @@ "path": "./snippets/kotlin.json" }, { - "language": ["plaintex", "tex"], + "language": [ + "plaintex", + "tex" + ], "path": "./snippets/latex/latex-snippets.json" }, { - "language": ["plaintex", "tex"], + "language": [ + "plaintex", + "tex" + ], "path": "./snippets/latex/vscode-latex-snippets.json" }, { @@ -242,7 +288,10 @@ "path": "./snippets/frameworks/twig.json" }, { - "language": ["r", "rmd"], + "language": [ + "r", + "rmd" + ], "path": "./snippets/r.json" }, { diff --git a/snips/snippets/c.json b/snips/snippets/c.json index dd51607ed..450d9d9a0 100644 --- a/snips/snippets/c.json +++ b/snips/snippets/c.json @@ -1,11 +1,11 @@ { - "fori": { - "prefix": "fori", - "body": [ - "for (${1:int} ${2:i} = ${3:0}; $2 < ${4:length}; ++$2) {", - "\t$0", - "}" - ], - "description": "Code snippet for 'fori' loop" - } + "fori": { + "prefix": "fori", + "body": [ + "for (${1:int} ${2:i} = ${3:0}; $2 < ${4:length}; ++$2) {", + "\t$0", + "}" + ], + "description": "Code snippet for 'fori' loop" + } } diff --git a/snips/snippets/cpp.json b/snips/snippets/cpp.json index 0752da374..10b6681c3 100644 --- a/snips/snippets/cpp.json +++ b/snips/snippets/cpp.json @@ -1,47 +1,42 @@ { - "solu": { - "prefix": "solu", - "body": [ - "class Solution", - "{", - "public:", - "\t$1 $2($3) {", - "\t\t$4", - "\t}", - "};" - ], - "description": "leetcode class Solution template" - }, - "lc": { - "prefix": "lc", - "body": [ - "#include ", - "", - "using namespace std;", - "", - "class Solution", - "{", - "public:", - "\t$1 $2($3) {", - "\t\t$4", - "\t}", - "};", - "", - "int main(int argc, char *argv[]) {", - "\tSolution s;", - "\treturn 0;", - "}" - ], - "description": "leetcode template" - }, - "hdef": { - "prefix": "hdef", - "body": [ - "#ifndef $1", - "#define $1", - "", - "#endif // $1" - ], - "description": "header file definitions" - } + "solu": { + "prefix": "solu", + "body": [ + "class Solution", + "{", + "public:", + "\t$1 $2($3) {", + "\t\t$4", + "\t}", + "};" + ], + "description": "leetcode class Solution template" + }, + "lc": { + "prefix": "lc", + "body": [ + "#include ", + "", + "using namespace std;", + "", + "class Solution", + "{", + "public:", + "\t$1 $2($3) {", + "\t\t$4", + "\t}", + "};", + "", + "int main(int argc, char *argv[]) {", + "\tSolution s;", + "\treturn 0;", + "}" + ], + "description": "leetcode template" + }, + "hdef": { + "prefix": "hdef", + "body": ["#ifndef $1", "#define $1", "", "#endif // $1"], + "description": "header file definitions" + } } From 156893afc95fd2379840aefd4d57da5b6db75096 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Tue, 14 Feb 2023 15:05:57 +0800 Subject: [PATCH 16/24] clean up --- lua/modules/configs/completion/null-ls.lua | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index e4bd9e02d..87890048b 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -1,19 +1,11 @@ return function() local null_ls = require("null-ls") + local btn = null_ls.builtins -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins local disabled_worksapces = require("core.settings").format_disabled_dirs local format_on_save = require("core.settings").format_on_save - -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins - local btn = null_ls.builtins - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - local with_diagnostics_code = function(builtin) - return builtin.with({ - diagnostics_format = "#{m} [#{c}]", - }) - end - local sources = { -- formatting btn.formatting.black.with({ extra_args = { "--fast" } }), @@ -27,7 +19,7 @@ return function() btn.formatting.stylua, -- diagnostics - with_diagnostics_code(btn.diagnostics.shellcheck), + btn.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#{c}]" }), btn.diagnostics.markdownlint.with({ extra_args = { "--disable MD033" } }), } From 2c0185df1843116be2e0a34a8809e8cedf872854 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Tue, 14 Feb 2023 15:34:30 +0800 Subject: [PATCH 17/24] sync: add/replace plugins ( #514 ) --- lua/modules/configs/completion/autopairs.lua | 27 -------------------- lua/modules/configs/completion/cmp.lua | 2 ++ lua/modules/configs/completion/codeium.lua | 3 +++ lua/modules/configs/editor/autoclose.lua | 22 ++++++++++++++++ lua/modules/configs/tool/imselect.lua | 17 ------------ lua/modules/configs/ui/paint.lua | 20 +++++++++++++++ lua/modules/plugins/completion.lua | 13 +++++++--- lua/modules/plugins/editor.lua | 5 ++++ lua/modules/plugins/tool.lua | 5 ++-- lua/modules/plugins/ui.lua | 5 ++++ 10 files changed, 69 insertions(+), 50 deletions(-) delete mode 100644 lua/modules/configs/completion/autopairs.lua create mode 100644 lua/modules/configs/completion/codeium.lua create mode 100644 lua/modules/configs/editor/autoclose.lua delete mode 100644 lua/modules/configs/tool/imselect.lua create mode 100644 lua/modules/configs/ui/paint.lua diff --git a/lua/modules/configs/completion/autopairs.lua b/lua/modules/configs/completion/autopairs.lua deleted file mode 100644 index 85255a693..000000000 --- a/lua/modules/configs/completion/autopairs.lua +++ /dev/null @@ -1,27 +0,0 @@ -return function() - require("nvim-autopairs").setup({}) - - -- If you want insert `(` after select function or method item - local cmp_autopairs = require("nvim-autopairs.completion.cmp") - local cmp = require("cmp") - local handlers = require("nvim-autopairs.completion.handlers") - cmp.event:on( - "confirm_done", - cmp_autopairs.on_confirm_done({ - filetypes = { - -- "*" is an alias to all filetypes - ["*"] = { - ["("] = { - kind = { - cmp.lsp.CompletionItemKind.Function, - cmp.lsp.CompletionItemKind.Method, - }, - handler = handlers["*"], - }, - }, - -- Disable for tex - tex = false, - }, - }) - ) -end diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index b5ebe3b39..6a7a914df 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -123,12 +123,14 @@ return function() { name = "nvim_lua" }, { name = "luasnip" }, { name = "path" }, + { name = "treesitter" }, { name = "spell" }, { name = "tmux" }, { name = "orgmode" }, { name = "buffer" }, { name = "latex_symbols" }, { name = "copilot" }, + -- { name = "codeium" }, -- { name = "cmp_tabnine" }, }, }) diff --git a/lua/modules/configs/completion/codeium.lua b/lua/modules/configs/completion/codeium.lua new file mode 100644 index 000000000..40bbd04fe --- /dev/null +++ b/lua/modules/configs/completion/codeium.lua @@ -0,0 +1,3 @@ +return function() + require("codeium").setup({}) +end diff --git a/lua/modules/configs/editor/autoclose.lua b/lua/modules/configs/editor/autoclose.lua new file mode 100644 index 000000000..f40d72a5e --- /dev/null +++ b/lua/modules/configs/editor/autoclose.lua @@ -0,0 +1,22 @@ +return function() + require("autoclose").setup({ + keys = { + ["("] = { escape = false, close = true, pair = "()" }, + ["["] = { escape = false, close = true, pair = "[]" }, + ["{"] = { escape = false, close = true, pair = "{}" }, + + [">"] = { escape = true, close = false, pair = "<>" }, + [")"] = { escape = true, close = false, pair = "()" }, + ["]"] = { escape = true, close = false, pair = "[]" }, + ["}"] = { escape = true, close = false, pair = "{}" }, + + ['"'] = { escape = true, close = true, pair = '""' }, + ["'"] = { escape = true, close = true, pair = "''" }, + ["`"] = { escape = true, close = true, pair = "``" }, + }, + options = { + disabled_filetypes = nil, + disable_when_touch = false, + }, + }) +end diff --git a/lua/modules/configs/tool/imselect.lua b/lua/modules/configs/tool/imselect.lua deleted file mode 100644 index a61028389..000000000 --- a/lua/modules/configs/tool/imselect.lua +++ /dev/null @@ -1,17 +0,0 @@ --- fcitx5 need a manual config -return function() - if vim.fn.executable("fcitx5-remote") == 1 then - vim.api.nvim_cmd({ - [[ let g:im_select_get_im_cmd = ["fcitx5-remote"] ]], - [[ let g:im_select_default = '1' ]], - [[ let g:ImSelectSetImCmd = { - \ key -> - \ key == 1 ? ['fcitx5-remote', '-c'] : - \ key == 2 ? ['fcitx5-remote', '-o'] : - \ key == 0 ? ['fcitx5-remote', '-c'] : - \ execute("throw 'invalid im key'") - \ } - ]], - }, { true, true, true }) - end -end diff --git a/lua/modules/configs/ui/paint.lua b/lua/modules/configs/ui/paint.lua new file mode 100644 index 000000000..1fda36cb1 --- /dev/null +++ b/lua/modules/configs/ui/paint.lua @@ -0,0 +1,20 @@ +return function() + require("paint").setup({ + ---type PaintHighlight[] + highlights = { + { + -- filter can be a table of buffer options that should match, + -- or a function called with buf as param that should return true. + -- The example below will paint @something in comments with Constant + filter = { filetype = "lua" }, + pattern = "%s*%-%-%-%s*(@%w+)", + hl = "Constant", + }, + { + filter = { filetype = "python" }, + pattern = "%s*(%w+:)", + hl = "Constant", + }, + }, + }) +end diff --git a/lua/modules/plugins/completion.lua b/lua/modules/plugins/completion.lua index 8d885c29c..642d8830a 100644 --- a/lua/modules/plugins/completion.lua +++ b/lua/modules/plugins/completion.lua @@ -42,11 +42,16 @@ completion["hrsh7th/nvim-cmp"] = { { "f3fora/cmp-spell" }, { "hrsh7th/cmp-buffer" }, { "kdheepak/cmp-latex-symbols" }, - { - "windwp/nvim-autopairs", - config = require("completion.autopairs"), - }, + { "ray-x/cmp-treesitter" }, -- { "tzachar/cmp-tabnine", build = "./install.sh", config = require("completion.tabnine") }, + -- { + -- "jcdickinson/codeium.nvim", + -- dependencies = { + -- "nvim-lua/plenary.nvim", + -- "MunifTanjim/nui.nvim", + -- }, + -- config = require("completion.codeium"), + -- }, }, } completion["zbirenbaum/copilot.lua"] = { diff --git a/lua/modules/plugins/editor.lua b/lua/modules/plugins/editor.lua index b514bbff4..bbba26665 100644 --- a/lua/modules/plugins/editor.lua +++ b/lua/modules/plugins/editor.lua @@ -10,6 +10,11 @@ editor["rmagatti/auto-session"] = { cmd = { "SaveSession", "RestoreSession", "DeleteSession" }, config = require("editor.auto-session"), } +editor["m4xshen/autoclose.nvim"] = { + lazy = true, + event = "InsertEnter", + config = require("editor.autoclose"), +} editor["max397574/better-escape.nvim"] = { lazy = true, event = { "CursorHold", "CursorHoldI" }, diff --git a/lua/modules/plugins/tool.lua b/lua/modules/plugins/tool.lua index aae4b65a9..6c9082d31 100644 --- a/lua/modules/plugins/tool.lua +++ b/lua/modules/plugins/tool.lua @@ -11,10 +11,11 @@ tool["folke/which-key.nvim"] = { config = require("tool.which-key"), } -- only for fcitx5 user who uses non-English language during coding --- tool["brglng/vim-im-select"] = { +-- tool["pysan3/fcitx5.nvim"] = { -- lazy = true, -- event = "BufReadPost", --- config = require("tool.imselect"), +-- cond = vim.fn.executable("fcitx5-remote") == 1, +-- config = require("tool.fcitx5"), -- } tool["nvim-tree/nvim-tree.lua"] = { lazy = true, diff --git a/lua/modules/plugins/ui.lua b/lua/modules/plugins/ui.lua index 37e3ece0e..d0bf2e939 100644 --- a/lua/modules/plugins/ui.lua +++ b/lua/modules/plugins/ui.lua @@ -58,6 +58,11 @@ ui["rcarriga/nvim-notify"] = { event = "VeryLazy", config = require("ui.notify"), } +ui["folke/paint.nvim"] = { + lazy = true, + event = "BufReadPost", + config = require("ui.paint"), +} ui["dstein64/nvim-scrollview"] = { lazy = true, event = "BufReadPost", From 67e98be5e9ab2215124b1d4e6f0ff3c3105d49b8 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Thu, 16 Feb 2023 14:19:51 +0800 Subject: [PATCH 18/24] chore(clang-format): remove extra args --- lua/modules/configs/completion/null-ls.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index 87890048b..1f6cc959a 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -9,7 +9,7 @@ return function() local sources = { -- formatting btn.formatting.black.with({ extra_args = { "--fast" } }), - btn.formatting.clang_format.with({ command = "clang-format -style='{btnasedOnStyle: LLVM, IndentWidth: 4}'" }), + btn.formatting.clang_format, btn.formatting.eslint_d, btn.formatting.jq, btn.formatting.markdownlint, From ef974bfe7330686d90290ba7aa444cf836bebe05 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Thu, 16 Feb 2023 23:08:10 +0800 Subject: [PATCH 19/24] revert: add `formatting.lua` back --- lua/modules/configs/completion/formatting.lua | 182 ++++++++++++++++++ lua/modules/configs/completion/null-ls.lua | 34 +--- 2 files changed, 186 insertions(+), 30 deletions(-) create mode 100644 lua/modules/configs/completion/formatting.lua diff --git a/lua/modules/configs/completion/formatting.lua b/lua/modules/configs/completion/formatting.lua new file mode 100644 index 000000000..62432547e --- /dev/null +++ b/lua/modules/configs/completion/formatting.lua @@ -0,0 +1,182 @@ +local M = {} + +local settings = require("core.settings") +local disabled_workspaces = settings.format_disabled_dirs +local format_on_save = settings.format_on_save + +vim.api.nvim_create_user_command("FormatToggle", function() + M.toggle_format_on_save() +end, {}) + +local block_list = {} +vim.api.nvim_create_user_command("FormatterToggle", function(opts) + if block_list[opts.args] == nil then + vim.notify( + string.format("[LSP]Formatter for [%s] has been recorded in list and disabled.", opts.args), + vim.log.levels.WARN, + { title = "LSP Formatter Warning!" } + ) + block_list[opts.args] = true + else + block_list[opts.args] = not block_list[opts.args] + vim.notify( + string.format( + "[LSP]Formatter for [%s] has been %s.", + opts.args, + not block_list[opts.args] and "enabled" or "disabled" + ), + not block_list[opts.args] and vim.log.levels.INFO or vim.log.levels.WARN, + { title = string.format("LSP Formatter %s", not block_list[opts.args] and "Info" or "Warning") } + ) + end +end, { + nargs = 1, + complete = function() + return { + "markdown", + "vim", + "lua", + "c", + "cpp", + "python", + "vue", + "typescript", + "javascript", + "yaml", + "html", + "css", + "scss", + "sh", + "rust", + } + end, +}) + +function M.enable_format_on_save(is_configured) + local opts = { pattern = "*", timeout = 1000 } + vim.api.nvim_create_augroup("format_on_save", {}) + vim.api.nvim_create_autocmd("BufWritePre", { + group = "format_on_save", + pattern = opts.pattern, + callback = function() + require("completion.formatting").format({ timeout_ms = opts.timeout, filter = M.format_filter }) + end, + }) + if not is_configured then + vim.notify( + "Successfully enabled format-on-save", + vim.log.levels.INFO, + { title = "Settings modification success!" } + ) + end +end + +function M.disable_format_on_save() + pcall(vim.api.nvim_del_augroup_by_name, "format_on_save") + if format_on_save then + vim.notify("Disabled format-on-save", vim.log.levels.INFO, { title = "Settings modification success!" }) + end +end + +function M.configure_format_on_save() + if format_on_save then + M.enable_format_on_save(true) + else + M.disable_format_on_save() + end +end + +function M.toggle_format_on_save() + local status = pcall(vim.api.nvim_get_autocmds, { + group = "format_on_save", + event = "BufWritePre", + }) + if not status then + M.enable_format_on_save(false) + else + M.disable_format_on_save() + end +end + +function M.format_filter(clients) + return vim.tbl_filter(function(client) + local status_ok, formatting_supported = pcall(function() + return client.supports_method("textDocument/formatting") + end) + if status_ok and formatting_supported and client.name == "null-ls" then + return "null-ls" + elseif client.name ~= "lua_ls" and client.name ~= "tsserver" and client.name ~= "clangd" then + return status_ok and formatting_supported and client.name + end + end, clients) +end + +function M.format(opts) + local cwd = vim.fn.getcwd() + for i = 1, #disabled_workspaces do + if cwd.find(cwd, disabled_workspaces[i]) ~= nil then + return + end + end + + local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() + local clients = vim.lsp.buf_get_clients(bufnr) + + if opts.filter then + clients = opts.filter(clients) + elseif opts.id then + clients = vim.tbl_filter(function(client) + return client.id == opts.id + end, clients) + elseif opts.name then + clients = vim.tbl_filter(function(client) + return client.name == opts.name + end, clients) + end + + clients = vim.tbl_filter(function(client) + return client.supports_method("textDocument/formatting") + end, clients) + + if #clients == 0 then + vim.notify( + "[LSP]Format request failed, no matching language servers.", + vim.log.levels.WARN, + { title = "Formatting Failed!" } + ) + end + + local timeout_ms = opts.timeout_ms + for _, client in pairs(clients) do + if block_list[vim.bo.filetype] == true then + vim.notify( + string.format( + "[LSP][%s] formatter for [%s] has been disabled. This file was not processed.", + client.name, + vim.bo.filetype + ), + vim.log.levels.WARN, + { title = "LSP Formatter Warning!" } + ) + return + end + local params = vim.lsp.util.make_formatting_params(opts.formatting_options) + local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, bufnr) + if result and result.result then + vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding) + vim.notify( + string.format("[LSP]Format successfully with [%s]!", client.name), + vim.log.levels.INFO, + { title = "LSP Format Success!" } + ) + elseif err then + vim.notify( + string.format("[LSP][%s] %s", client.name, err), + vim.log.levels.ERROR, + { title = "LSP Format Error!" } + ) + end + end +end + +return M diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index 1f6cc959a..9956fa57d 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -1,10 +1,8 @@ return function() + local formatting = require("completion.formatting") + local null_ls = require("null-ls") local btn = null_ls.builtins -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins - local disabled_worksapces = require("core.settings").format_disabled_dirs - local format_on_save = require("core.settings").format_on_save - - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) local sources = { -- formatting @@ -28,32 +26,6 @@ return function() update_in_insert = false, diagnostics_format = "[#{c}] #{m} (#{s})", sources = sources, - on_attach = function(client, bufnr) - local cwd = vim.fn.getcwd() - for i = 1, #disabled_worksapces do - if cwd.find(cwd, disabled_worksapces[i]) ~= nil then - return - end - end - if client.supports_method("textDocument/formatting") and format_on_save then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format({ - bufnr = bufnr, - name = "null-ls", - }) - vim.notify( - string.format("Format successfully with [%s]!", client.name), - vim.log.levels.INFO, - { title = "LspFormat" } - ) - end, - }) - end - end, }) require("mason-null-ls").setup({ @@ -61,4 +33,6 @@ return function() automatic_installation = true, automatic_setup = false, }) + + formatting.configure_format_on_save() end From 2ff5d9655f8fbede7e6745e5765c575b70c058c4 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Fri, 17 Feb 2023 00:56:00 +0800 Subject: [PATCH 20/24] refactor: move `lsp` and `null-ls` sources to `core/settings.lua` --- lua/core/settings.lua | 33 ++++++++++++++ lua/modules/configs/completion/lsp.lua | 9 +--- lua/modules/configs/completion/null-ls.lua | 53 ++++++++++------------ 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/lua/core/settings.lua b/lua/core/settings.lua index 9ee9bfb7f..64dae1f3f 100644 --- a/lua/core/settings.lua +++ b/lua/core/settings.lua @@ -32,4 +32,37 @@ settings["colorscheme"] = "catppuccin" -- Available values are: `dark`, `light`. settings["background"] = "dark" +-- Set the desired LSPs here. +-- check the below link for all the supported LSPs: +-- https://github.com/neovim/nvim-lspconfig/tree/master/lua/lspconfig/server_configurations +settings["lsp"] = { + "bashls", + "clangd", + "gopls", + "html", + "lua_ls", + "pyright", +} + +-- Set the desired non-LSP sources here. +-- check the below link for all supported non-LSP sources +-- in `code_actions`, `completion`, `diagnostics`, `formatting`, `hover` folders: +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins +settings["null_ls"] = { + -- formatting + "black", + "clang_format", + "eslint_d", + "jq", + "markdownlint", + "prettierd", + "rustfmt", + "shfmt", + "stylua", + + -- diagnostics + "shellcheck", + -- "markdownlint", +} + return settings diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index 0a3983b08..67d94ee79 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -33,14 +33,7 @@ return function() mason_lspconfig.setup({ -- NOTE: use the lsp names in nvim-lspconfig -- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/lua/mason-lspconfig/mappings/server.lua - ensure_installed = { - "bashls", - "clangd", - "gopls", - "html", - "lua_ls", - "pyright", - }, + ensure_installed = require("core.settings").lsp, }) local capabilities = vim.lsp.protocol.make_client_capabilities() diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index 9956fa57d..5ff9693b5 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -1,38 +1,35 @@ return function() - local formatting = require("completion.formatting") + local btn = require("null-ls").builtins - local null_ls = require("null-ls") - local btn = null_ls.builtins -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins - - local sources = { - -- formatting - btn.formatting.black.with({ extra_args = { "--fast" } }), - btn.formatting.clang_format, - btn.formatting.eslint_d, - btn.formatting.jq, - btn.formatting.markdownlint, - btn.formatting.prettierd, - btn.formatting.rustfmt, - btn.formatting.shfmt, - btn.formatting.stylua, - - -- diagnostics - btn.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#{c}]" }), - btn.diagnostics.markdownlint.with({ extra_args = { "--disable MD033" } }), - } + require("mason-null-ls").setup({ + ensure_installed = require("core.settings").null_ls, + automatic_installation = true, + automatic_setup = true, + }) - null_ls.setup({ + require("null-ls").setup({ debug = false, update_in_insert = false, diagnostics_format = "[#{c}] #{m} (#{s})", - sources = sources, - }) + sources = { + -- formatting + btn.formatting.black.with({ extra_args = { "--fast" } }), + btn.formatting.clang_format, + btn.formatting.eslint_d, + btn.formatting.jq, + btn.formatting.markdownlint, + btn.formatting.prettierd, + btn.formatting.rustfmt, + btn.formatting.shfmt, + btn.formatting.stylua, - require("mason-null-ls").setup({ - ensure_installed = nil, - automatic_installation = true, - automatic_setup = false, + -- diagnostics + btn.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#{c}]" }), + btn.diagnostics.markdownlint.with({ extra_args = { "--disable MD033" } }), + }, }) - formatting.configure_format_on_save() + require("mason-null-ls").setup_handlers() + + require("completion.formatting").configure_format_on_save() end From 961f8a615559c33ff8ccfbfe3b748aaee566a792 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Fri, 17 Feb 2023 08:51:19 +0800 Subject: [PATCH 21/24] chore(mason-null-ls): use auto-`setup_handlers` for default config --- lua/modules/configs/completion/null-ls.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index 5ff9693b5..16700d662 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -11,17 +11,12 @@ return function() debug = false, update_in_insert = false, diagnostics_format = "[#{c}] #{m} (#{s})", + -- NOTE: Users don't need to specify null-ls sources if using only default config. + -- "mason-null-ls" will auto-setup for users. sources = { -- formatting btn.formatting.black.with({ extra_args = { "--fast" } }), - btn.formatting.clang_format, - btn.formatting.eslint_d, - btn.formatting.jq, btn.formatting.markdownlint, - btn.formatting.prettierd, - btn.formatting.rustfmt, - btn.formatting.shfmt, - btn.formatting.stylua, -- diagnostics btn.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#{c}]" }), From 930d3ca1f686d6fd608d68492a31adf79baadfbf Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Fri, 17 Feb 2023 09:59:49 +0800 Subject: [PATCH 22/24] perf: use only `mason-null-ls` to setup sources to prevent overwrite. --- lua/modules/configs/completion/null-ls.lua | 44 ++++++++++++---------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index 16700d662..e38055cae 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -1,30 +1,36 @@ return function() - local btn = require("null-ls").builtins + local null_ls = require("null-ls") + local mason_null_ls = require("mason-null-ls") + local btnf = null_ls.builtins.formatting + local btnd = null_ls.builtins.diagnostics + local null_reg = null_ls.register - require("mason-null-ls").setup({ - ensure_installed = require("core.settings").null_ls, - automatic_installation = true, - automatic_setup = true, - }) - - require("null-ls").setup({ + null_ls.setup({ debug = false, update_in_insert = false, diagnostics_format = "[#{c}] #{m} (#{s})", - -- NOTE: Users don't need to specify null-ls sources if using only default config. - -- "mason-null-ls" will auto-setup for users. - sources = { - -- formatting - btn.formatting.black.with({ extra_args = { "--fast" } }), - btn.formatting.markdownlint, + }) - -- diagnostics - btn.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#{c}]" }), - btn.diagnostics.markdownlint.with({ extra_args = { "--disable MD033" } }), - }, + mason_null_ls.setup({ + ensure_installed = require("core.settings").null_ls, + automatic_installation = true, + automatic_setup = true, }) - require("mason-null-ls").setup_handlers() + -- NOTE: Users don't need to specify null-ls sources if using only default config. + -- "mason-null-ls" will auto-setup for users. + mason_null_ls.setup_handlers({ + black = function() + null_reg(btnf.black.with({ extra_args = { "--fast" } })) + end, + markdownlint = function() + null_reg(btnf.markdownlint) + null_reg(btnd.markdownlint.with({ extra_args = { "--disable MD033" } })) + end, + shellcheck = function() + null_reg(btnd.shellcheck.with({ diagnostics_format = "#{m} [#(c)]" })) + end, + }) require("completion.formatting").configure_format_on_save() end From 867422b8260ba1703582096ff0ef6a6962c20baa Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Fri, 17 Feb 2023 11:48:11 +0800 Subject: [PATCH 23/24] chore(null-ls): better diagnostics_format --- lua/modules/configs/completion/null-ls.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index e38055cae..b55afe5a6 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -8,7 +8,7 @@ return function() null_ls.setup({ debug = false, update_in_insert = false, - diagnostics_format = "[#{c}] #{m} (#{s})", + diagnostics_format = "[#{s} #{c}] #{m}", }) mason_null_ls.setup({ @@ -27,9 +27,10 @@ return function() null_reg(btnf.markdownlint) null_reg(btnd.markdownlint.with({ extra_args = { "--disable MD033" } })) end, - shellcheck = function() - null_reg(btnd.shellcheck.with({ diagnostics_format = "#{m} [#(c)]" })) - end, + -- example for changing the diagnostics_format + -- shellcheck = function() + -- null_reg(btnd.shellcheck.with({ diagnostics_format = "#{m} [#{s} #{c}]" })) + -- end, }) require("completion.formatting").configure_format_on_save() From 8fbf3c32b998092b2e3a1f390e9d19336ce3d379 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Fri, 17 Feb 2023 11:50:26 +0800 Subject: [PATCH 24/24] typo --- lua/modules/configs/completion/null-ls.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/modules/configs/completion/null-ls.lua b/lua/modules/configs/completion/null-ls.lua index b55afe5a6..dddb18642 100644 --- a/lua/modules/configs/completion/null-ls.lua +++ b/lua/modules/configs/completion/null-ls.lua @@ -27,7 +27,7 @@ return function() null_reg(btnf.markdownlint) null_reg(btnd.markdownlint.with({ extra_args = { "--disable MD033" } })) end, - -- example for changing the diagnostics_format + -- example for changing diagnostics_format -- shellcheck = function() -- null_reg(btnd.shellcheck.with({ diagnostics_format = "#{m} [#{s} #{c}]" })) -- end,