diff --git a/lazy-lock.json b/lazy-lock.json index 2b6d44b..f2c2328 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -10,6 +10,7 @@ "cmp-rg": { "branch": "master", "commit": "677a7874ee8f1afc648c2e7d63a97bc21a7663c5" }, "cmp-under-comparator": { "branch": "master", "commit": "6857f10272c3cfe930cece2afa2406e1385bfef8" }, "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, + "conform.nvim": { "branch": "master", "commit": "4a4c92715b174b847ba0fcdccf9dfea71c8ed33e" }, "friendly-snippets": { "branch": "main", "commit": "ebf6d6e83494cdd88a54a429340256f4dbb6a052" }, "git-conflict.nvim": { "branch": "main", "commit": "896261933afe2fddf6fb043d9cd4d88301b151a9" }, "gitsigns.nvim": { "branch": "main", "commit": "bce4576a9047085a528c479a7fe1e2f6b787b6c1" }, diff --git a/lua/custom/autocommands.lua b/lua/custom/autocommands.lua index 518203b..46092cd 100644 --- a/lua/custom/autocommands.lua +++ b/lua/custom/autocommands.lua @@ -13,6 +13,7 @@ vim.api.nvim_create_autocmd({ 'InsertLeave', 'WinEnter' }, { end end, }) + vim.api.nvim_create_autocmd({ 'InsertEnter', 'WinLeave' }, { callback = function() local cl = vim.wo.cursorline @@ -32,12 +33,6 @@ vim.api.nvim_create_autocmd({ 'FileType' }, { end, }) --- Trim buffer whitespaces -vim.api.nvim_create_autocmd({ 'BufWritePre' }, { - pattern = '*', - command = 'TrimTrailingWhitespace', -}) - -- Check if we need to reload the file when it changed vim.api.nvim_create_autocmd({ 'FocusGained', 'TermClose', 'TermLeave' }, { command = 'checktime' }) diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index bd99e50..5391b95 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -14,23 +14,23 @@ local sources = { --- code actions b.code_actions.eslint, b.code_actions.gitrebase, - b.code_actions.refactoring, + -- b.code_actions.refactoring, b.code_actions.shellcheck, require('typescript.extensions.null-ls.code-actions'), --- diagnostics b.diagnostics.gitlint, - b.diagnostics.markdownlint, + -- b.diagnostics.markdownlint, b.diagnostics.php, - b.diagnostics.shellcheck.with({ diagnostics_format = '#{m} [#{c}]' }), + -- b.diagnostics.shellcheck.with({ diagnostics_format = '#{m} [#{c}]' }), b.diagnostics.todo_comments, - b.diagnostics.trail_space, + -- b.diagnostics.trail_space, b.diagnostics.tsc, b.diagnostics.zsh, --- formatting b.formatting.blade_formatter, - b.formatting.eslint_d, + -- b.formatting.eslint_d, b.formatting.fixjson, b.formatting.goimports, b.formatting.phpcsfixer.with({ @@ -63,13 +63,13 @@ local sources = { return not utils.root_has_file('.php-cs-fixer.php') end, }), - b.formatting.prettier.with({ + --[[ b.formatting.prettier.with({ disabled_filetypes = { 'typescript', 'typescriptreact', 'markdown' }, }), b.formatting.rustfmt, b.formatting.shfmt, b.formatting.sqlfmt, - with_root_file(b.formatting.stylua, 'stylua.toml'), + with_root_file(b.formatting.stylua, 'stylua.toml'), ]] } local M = { diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 0000000..ea1b5fa --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,31 @@ +return { + 'stevearc/conform.nvim', + opts = { + formatters_by_ft = { + javascript = { { 'eslint_d', 'eslint', 'prettier_d', 'prettier' } }, + json = { 'jq' }, + lua = { 'stylua' }, + markdown = { 'markdownlint' }, + rust = { 'rustfmt' }, + sh = { 'shfmt', 'shellcheck' }, + sql = { 'sql_formtter' }, + typescript = { { 'eslint_d', 'eslint' } }, + typescriptreact = { { 'eslint_d', 'eslint' } }, + _ = { 'trim_whitespace', 'squeeze_blanks', 'trim_newlines' }, + }, + }, + format_on_save = { + timeout_ms = 1000, + lsp_fallback = true, + }, + config = function(_, opts) + require('conform').setup(opts) + + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*', + callback = function(args) + require('conform').format({ bufnr = args.buf }) + end, + }) + end, +} diff --git a/lua/utils.lua b/lua/utils.lua index 800182c..8e5b5ca 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -14,52 +14,6 @@ local get_map_options = function(custom_options) return options end --- (see :h command-preview or https://github.com/neovim/neovim/commit/7380ebfc17723662f6fe1e38372f54b3d67fe082) -local function trim_space(opts, preview_ns, preview_buf) - local line1 = opts.line1 - local line2 = opts.line2 - local buf = vim.api.nvim_get_current_buf() - local lines = vim.api.nvim_buf_get_lines(buf, line1 - 1, line2, true) - local new_lines = {} - local preview_buf_line = 0 - for i, line in ipairs(lines) do - local startidx, endidx = string.find(line, '%s+$') - if startidx ~= nil then - -- Highlight the match if in command preview mode - if preview_ns ~= nil then - api.nvim_buf_add_highlight(buf, preview_ns, 'Substitute', line1 + i - 2, startidx - 1, endidx) - -- Add lines and highlight to the preview buffer - -- if inccommand=split - if preview_buf ~= nil then - local prefix = string.format('|%d| ', line1 + i - 1) - api.nvim_buf_set_lines(preview_buf, preview_buf_line, preview_buf_line, true, { prefix .. line }) - api.nvim_buf_add_highlight( - preview_buf, - preview_ns, - 'Substitute', - preview_buf_line, - #prefix + startidx - 1, - #prefix + endidx - ) - preview_buf_line = preview_buf_line + 1 - end - end - end - if not preview_ns then - new_lines[#new_lines + 1] = string.gsub(line, '%s+$', '') - end - end - -- Don't make any changes to the buffer if previewing - if not preview_ns then - api.nvim_buf_set_lines(buf, line1 - 1, line2, true, new_lines) - end - -- When called as a preview callback, return the value of the - -- preview type - if preview_ns ~= nil then - return 2 - end -end - local M = {} M.map = function(mode, target, source, opts) @@ -148,9 +102,6 @@ M.get_cwd = function() return uv.cwd end -M.trim_trailing_whitespace = - M.command('TrimTrailingWhitespace', trim_space, { nargs = '?', range = '%', addr = 'lines', preview = trim_space }) - ---@param level number|nil ---@param msg string ---@param title string