From 01a1cb2fc06e0a05ffd915ff3959439959f03d99 Mon Sep 17 00:00:00 2001 From: nshen Date: Thu, 7 Apr 2022 17:33:27 +0800 Subject: [PATCH] add null-ls --- init.lua | 2 ++ lua/lsp/null-ls.lua | 70 +++++++++++++++++++++++++++++++++++++++++++++ lua/plugins.lua | 1 + 3 files changed, 73 insertions(+) create mode 100644 lua/lsp/null-ls.lua diff --git a/init.lua b/init.lua index 7111a74..b34453d 100644 --- a/init.lua +++ b/init.lua @@ -19,7 +19,9 @@ require("lsp.setup") require("lsp.cmp") require("lsp.ui") -- require("lsp.formatter") +require("lsp.null-ls") +---------------- -- require("utils.change-colorscheme") -- 输入法自动切换 diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua new file mode 100644 index 0000000..3ea2e28 --- /dev/null +++ b/lua/lsp/null-ls.lua @@ -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 lua vim.lsp.buf.formatting_sync()") + -- end + end, +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 7c98e7a..15b9bff 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -88,6 +88,7 @@ packer.startup({ -- use("blackCauldron7/surround.nvim") -- 代码格式化 use("mhartington/formatter.nvim") + use({ "jose-elias-alvarez/null-ls.nvim", requires = "nvim-lua/plenary.nvim" }) -- Lua 增强 use("folke/lua-dev.nvim")