nshen
3 years ago
3 changed files with 73 additions and 0 deletions
@ -0,0 +1,70 @@ |
|||||
|
local status, null_ls = pcall(require, "null-ls") |
||||
|
if not status then |
||||
|
vim.notify("没有找到 null-ls") |
||||
|
return |
||||
|
end |
||||
|
|
||||
|
local formatting = null_ls.builtins.formatting |
||||
|
local diagnostics = null_ls.builtins.diagnostics |
||||
|
local code_actions = null_ls.builtins.code_actions |
||||
|
|
||||
|
null_ls.setup({ |
||||
|
debug = false, |
||||
|
sources = { |
||||
|
-- Formatting --------------------- |
||||
|
-- brew install shfmt |
||||
|
formatting.shfmt, |
||||
|
-- StyLua |
||||
|
formatting.stylua, |
||||
|
-- frontend |
||||
|
formatting.prettier.with({ -- 比默认少了 markdown |
||||
|
filetypes = { |
||||
|
"javascript", |
||||
|
"javascriptreact", |
||||
|
"typescript", |
||||
|
"typescriptreact", |
||||
|
"vue", |
||||
|
"css", |
||||
|
"scss", |
||||
|
"less", |
||||
|
"html", |
||||
|
"json", |
||||
|
"yaml", |
||||
|
"graphql", |
||||
|
}, |
||||
|
prefer_local = "node_modules/.bin", |
||||
|
}), |
||||
|
-- formatting.fixjson, |
||||
|
-- formatting.black.with({ extra_args = { "--fast" } }), |
||||
|
|
||||
|
-- Diagnostics --------------------- |
||||
|
diagnostics.eslint.with({ |
||||
|
prefer_local = "node_modules/.bin", |
||||
|
}), |
||||
|
code_actions.eslint.with({ |
||||
|
prefer_local = "node_modules/.bin", |
||||
|
}), |
||||
|
-- diagnostics.markdownlint, |
||||
|
-- markdownlint-cli2 |
||||
|
-- diagnostics.markdownlint.with({ |
||||
|
-- prefer_local = "node_modules/.bin", |
||||
|
-- command = "markdownlint-cli2", |
||||
|
-- args = { "$FILENAME", "#node_modules" }, |
||||
|
-- }), |
||||
|
-- |
||||
|
-- code actions --------------------- |
||||
|
code_actions.gitsigns, |
||||
|
code_actions.eslint, |
||||
|
-- code_actions.refactoring, |
||||
|
}, |
||||
|
-- #{m}: message |
||||
|
-- #{s}: source name (defaults to null-ls if not specified) |
||||
|
-- #{c}: code (if available) |
||||
|
diagnostics_format = "[#{s}] #{m}", |
||||
|
on_attach = function(client) |
||||
|
-- vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()']]) |
||||
|
-- if client.resolved_capabilities.document_formatting then |
||||
|
-- vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()") |
||||
|
-- end |
||||
|
end, |
||||
|
}) |
Loading…
Reference in new issue