~gpanders/dotfiles

f9dc228895c7645f62bd304ad256035d46630887 — Gregory Anders 2 months ago aa7f35c
nvim: replace ale with nvim-lint
5 files changed, 34 insertions(+), 68 deletions(-)

D .config/nvim/after/plugin/ale.vim
D .config/nvim/plugin/ale.vim
A .config/nvim/plugin/lint.vim
M .config/nvim/plugin/lspconfig.vim
M .config/nvim/plugin/packer.vim
D .config/nvim/after/plugin/ale.vim => .config/nvim/after/plugin/ale.vim +0 -65
@@ 1,65 0,0 @@
if !get(g:, 'loaded_ale')
    finish
endif

" Prevent LSP diagnostics from displaying when LSP is attached
function! s:on_lsp_attach()
    lua vim.lsp.diagnostic.display = function() end
    autocmd BufWrite <buffer> ++once call s:on_buf_write()
endfunction

" Display diagnostics after writing the buffer
function! s:on_buf_write()
lua <<
local ale_diagnostic_severity_map = {
    [vim.lsp.protocol.DiagnosticSeverity.Error] = 'E',
    [vim.lsp.protocol.DiagnosticSeverity.Warning] = 'W',
    [vim.lsp.protocol.DiagnosticSeverity.Information] = 'I',
    [vim.lsp.protocol.DiagnosticSeverity.Hint] = 'I',
}

vim.lsp.diagnostic.clear = function(bufnr, client_id, ...)
    local client = vim.lsp.get_client_by_id(client_id)
    vim.api.nvim_call_function('ale#other_source#ShowResults', { bufnr, client.name, {} })
end

vim.lsp.diagnostic.display = function(diagnostics, bufnr, client_id, ...)
    vim.lsp.diagnostic.clear(bufnr, client_id, ...)

    local client = vim.lsp.get_client_by_id(client_id)
    local items = {}
    for _, item in ipairs(diagnostics) do
        table.insert(items, {
            text = item.message,
            filename = vim.api.nvim_buf_get_name(bufnr),
            lnum = item.range.start.line + 1,
            end_lnum = item.range['end'].line,
            col = item.range.start.character + 1,
            end_col = item.range['end'].character,
            type = ale_diagnostic_severity_map[item.severity],
        })
    end

    if not vim.tbl_isempty(items) then
        vim.api.nvim_call_function('ale#other_source#ShowResults', {
            bufnr,
            client.name,
            items
        })
    end
end

local bufnr = vim.api.nvim_get_current_buf()
vim.lsp.for_each_buffer_client(bufnr, function(client)
    local diagnostics = vim.lsp.diagnostic.get(bufnr, client.id)
    vim.lsp.diagnostic.display(diagnostics, bufnr, client.id)
end)
.
endfunction

autocmd User LspAttached ++once call s:on_lsp_attach()

let g:ale_virtualtext_cursor = 1
let g:ale_floating_preview = 1

nnoremap gh <Cmd>ALEDetail<CR>

D .config/nvim/plugin/ale.vim => .config/nvim/plugin/ale.vim +0 -2
@@ 1,2 0,0 @@
let g:ale_disable_lsp = 1
let g:ale_lint_on_enter = 0

A .config/nvim/plugin/lint.vim => .config/nvim/plugin/lint.vim +22 -0
@@ 0,0 1,22 @@
function! s:load()
lua <<
local ok, lint = pcall(require, "lint")
if not ok then
    return
end

lint.linters_by_ft = {
    ["sh"] = { "shellcheck" },
    ["vim"] = { "vint" },
    ["lua"] = { "luacheck" },
    ["nix"] = { "nix" },
}

vim.cmd("autocmd! lint BufWritePost * lua require('lint').try_lint()")
.
endfunction

augroup lint
    autocmd!
    autocmd BufWritePre * ++once call s:load()
augroup END

M .config/nvim/plugin/lspconfig.vim => .config/nvim/plugin/lspconfig.vim +11 -0
@@ 54,4 54,15 @@ endfunction
augroup load_lspconfig
    autocmd!
    autocmd FileType go,c,cpp,rust,python ++once call s:load()
    autocmd User LspDiagnosticsChanged lua vim.lsp.diagnostic.set_loclist({ open_loclist = false })
augroup END

hi link LspDiagnosticsDefaultError ErrorMsg
hi link LspDiagnosticsDefaultWarning WarningMsg
hi link LspDiagnosticsDefaultInformation Question
hi link LspDiagnosticsDefaultHint NonText

hi LspDiagnosticsSignError ctermfg=1 ctermbg=10
hi LspDiagnosticsSignWarning ctermfg=3 ctermbg=10
hi LspDiagnosticsSignInformation ctermfg=4 ctermbg=10
hi LspDiagnosticsSignHint ctermfg=7 ctermbg=10

M .config/nvim/plugin/packer.vim => .config/nvim/plugin/packer.vim +1 -1
@@ 38,7 38,7 @@ require("packer").startup(function(use)

    use "lewis6991/gitsigns.nvim"

    use "dense-analysis/ale"
    use "mfussenegger/nvim-lint"

    use "ludovicchabant/vim-gutentags"