nullls.lua (1911B)
1 local M = {} 2 3 local zsh_diag = function() 4 local null_ls = require('null-ls') 5 local h = require('null-ls.helpers') 6 return { 7 name = 'zsh check', 8 method = null_ls.methods.DIAGNOSTICS, 9 filetypes = {'zsh'}, 10 update_on_insert = true, 11 generator = null_ls.generator({ 12 command = 'zsh', 13 args = {'-n', '$FILENAME'}, 14 format = 'line', 15 check_exit_code = function(code) return code <= 1 end, 16 from_stderr = true, 17 to_stdin = true, 18 on_output = h.diagnostics.from_patterns({{pattern = [[%w+:(%d+): (.*)]], groups = {'row', 'message'}}}), 19 }), 20 } 21 end 22 23 M.setup = function() 24 local null_ls = require('null-ls') 25 local h = require('null-ls.helpers') 26 local builtins = null_ls.builtins 27 null_ls.setup({ 28 on_attach = function(client, bufnr) 29 if client.resolved_capabilities.document_formatting == true then 30 -- vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()') 31 vim.keymap.set('n', 'Q', vim.lsp.buf.formatting, {silent = true, buffer = bufnr, noremap = true}) 32 vim.keymap.set('v', 'Q', vim.lsp.buf.range_formatting, {silent = true, buffer = bufnr, noremap = true}) 33 end 34 end, 35 sources = { 36 -- formatting 37 builtins.formatting.prettier.with { 38 filetypes = {'html', 'yaml', 'markdown', 'css', 'scss'}, 39 args = h.range_formatting_args_factory({ 40 '--parser', 41 vim.api.nvim_buf_get_option(0, 'filetype'), 42 '--stdin-filepath', 43 '$FILENAME', 44 }, '--range-start', '--range-end'), 45 }, 46 -- builtins.formatting.lua_format, 47 -- builtins.formatting.clang_format, 48 builtins.formatting.shfmt.with { 49 filetypes = {'sh', 'zsh'}, 50 args = {'-i', vim.opt.shiftwidth:get(), '-filename', '$FILENAME'}, 51 }, 52 -- diagnostic 53 builtins.diagnostics.shellcheck, 54 zsh_diag(), 55 }, 56 }) 57 end 58 59 return M