Browse Source

add null-ls

pull/174/head
nshen 3 years ago
parent
commit
01a1cb2fc0
  1. 2
      init.lua
  2. 70
      lua/lsp/null-ls.lua
  3. 1
      lua/plugins.lua

2
init.lua

@ -19,7 +19,9 @@ require("lsp.setup")
require("lsp.cmp") require("lsp.cmp")
require("lsp.ui") require("lsp.ui")
-- require("lsp.formatter") -- require("lsp.formatter")
require("lsp.null-ls")
----------------
-- require("utils.change-colorscheme") -- require("utils.change-colorscheme")
-- 输入法自动切换 -- 输入法自动切换

70
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 <buffer> lua vim.lsp.buf.formatting_sync()")
-- end
end,
})

1
lua/plugins.lua

@ -88,6 +88,7 @@ packer.startup({
-- use("blackCauldron7/surround.nvim") -- use("blackCauldron7/surround.nvim")
-- 代码格式化 -- 代码格式化
use("mhartington/formatter.nvim") use("mhartington/formatter.nvim")
use({ "jose-elias-alvarez/null-ls.nvim", requires = "nvim-lua/plenary.nvim" })
-- Lua 增强 -- Lua 增强
use("folke/lua-dev.nvim") use("folke/lua-dev.nvim")

Loading…
Cancel
Save