Skip to content

Commit

Permalink
migrate: from efm to null-ls ( #500 #504 ) (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesChiuGit authored Feb 18, 2023
1 parent 7680acf commit 9323316
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 191 deletions.
33 changes: 33 additions & 0 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ settings["colorscheme"] = "catppuccin"
-- Available values are: `dark`, `light`.
settings["background"] = "dark"

-- Set the desired LSPs here.
-- check the below link for all the supported LSPs:
-- https://github.com/neovim/nvim-lspconfig/tree/master/lua/lspconfig/server_configurations
settings["lsp"] = {
"bashls",
"clangd",
"gopls",
"html",
"lua_ls",
"pyright",
}

-- Set the desired non-LSP sources here.
-- check the below link for all supported non-LSP sources
-- in `code_actions`, `completion`, `diagnostics`, `formatting`, `hover` folders:
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins
settings["null_ls"] = {
-- formatting
"black",
"clang_format",
"eslint_d",
"jq",
"markdownlint",
"prettierd",
"rustfmt",
"shfmt",
"stylua",

-- diagnostics
"shellcheck",
-- "markdownlint",
}

return settings
1 change: 0 additions & 1 deletion lua/modules/configs/completion/efm/formatters/clangfmt.lua

This file was deleted.

1 change: 0 additions & 1 deletion lua/modules/configs/completion/efm/formatters/rustfmt.lua

This file was deleted.

8 changes: 4 additions & 4 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function M.format_filter(clients)
local status_ok, formatting_supported = pcall(function()
return client.supports_method("textDocument/formatting")
end)
if status_ok and formatting_supported and client.name == "efm" then
return "efm"
if status_ok and formatting_supported and client.name == "null-ls" then
return "null-ls"
elseif client.name ~= "lua_ls" and client.name ~= "tsserver" and client.name ~= "clangd" then
return status_ok and formatting_supported and client.name
end
Expand Down Expand Up @@ -140,7 +140,7 @@ function M.format(opts)

if #clients == 0 then
vim.notify(
"[LSP] Format request failed, no matching language servers.",
"[LSP]Format request failed, no matching language servers.",
vim.log.levels.WARN,
{ title = "Formatting Failed!" }
)
Expand All @@ -165,7 +165,7 @@ function M.format(opts)
if result and result.result then
vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding)
vim.notify(
string.format("Format successfully with %s!", client.name),
string.format("[LSP]Format successfully with [%s]!", client.name),
vim.log.levels.INFO,
{ title = "LSP Format Success!" }
)
Expand Down
89 changes: 9 additions & 80 deletions lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
return function()
local formatting = require("completion.formatting")

local nvim_lsp = require("lspconfig")
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")
Expand Down Expand Up @@ -33,14 +31,9 @@ return function()
},
})
mason_lspconfig.setup({
ensure_installed = {
"bashls",
"clangd",
"efm",
"gopls",
"pyright",
"lua_ls",
},
-- NOTE: use the lsp names in nvim-lspconfig
-- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/lua/mason-lspconfig/mappings/server.lua
ensure_installed = require("core.settings").lsp,
})

local capabilities = vim.lsp.protocol.make_client_capabilities()
Expand Down Expand Up @@ -85,16 +78,18 @@ return function()
nvim_lsp.clangd.setup(final_opts)
end,

efm = function()
-- Do not setup efm
end,

gopls = function()
local _opts = require("completion.servers.gopls")
local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
nvim_lsp.gopls.setup(final_opts)
end,

html = function()
local _opts = require("completion.servers.html")
local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
nvim_lsp.html.setup(final_opts)
end,

jsonls = function()
local _opts = require("completion.servers.jsonls")
local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
Expand All @@ -107,70 +102,4 @@ return function()
nvim_lsp.lua_ls.setup(final_opts)
end,
})

if vim.fn.executable("html-languageserver") then
local _opts = require("completion.servers.html")
local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
nvim_lsp.html.setup(final_opts)
end

local efmls = require("efmls-configs")

-- Init `efm-langserver` here.

efmls.init({
on_attach = opts.on_attach,
capabilities = capabilities,
init_options = { documentFormatting = true, codeAction = true },
})

-- Require `efmls-configs-nvim`'s config here

local vint = require("efmls-configs.linters.vint")
local eslint = require("efmls-configs.linters.eslint")
local flake8 = require("efmls-configs.linters.flake8")

local black = require("efmls-configs.formatters.black")
local stylua = require("efmls-configs.formatters.stylua")
local prettier = require("efmls-configs.formatters.prettier")
local shfmt = require("efmls-configs.formatters.shfmt")

-- Add your own config for formatter and linter here

-- local rustfmt = require("completion.efm.formatters.rustfmt")
local clangfmt = require("completion.efm.formatters.clangfmt")

-- Override default config here

flake8 = vim.tbl_extend("force", flake8, {
prefix = "flake8: max-line-length=160, ignore F403 and F405",
lintStdin = true,
lintIgnoreExitCode = true,
lintFormats = { "%f:%l:%c: %t%n%n%n %m" },
lintCommand = "flake8 --max-line-length 160 --extend-ignore F403,F405 --format '%(path)s:%(row)d:%(col)d: %(code)s %(code)s %(text)s' --stdin-display-name ${INPUT} -",
})

-- Setup formatter and linter for efmls here

efmls.setup({
vim = { formatter = vint },
lua = { formatter = stylua },
c = { formatter = clangfmt },
cpp = { formatter = clangfmt },
python = { formatter = black },
vue = { formatter = prettier },
typescript = { formatter = prettier, linter = eslint },
javascript = { formatter = prettier, linter = eslint },
typescriptreact = { formatter = prettier, linter = eslint },
javascriptreact = { formatter = prettier, linter = eslint },
yaml = { formatter = prettier },
html = { formatter = prettier },
css = { formatter = prettier },
scss = { formatter = prettier },
sh = { formatter = shfmt },
markdown = { formatter = prettier },
-- rust = {formatter = rustfmt},
})

formatting.configure_format_on_save()
end
32 changes: 0 additions & 32 deletions lua/modules/configs/completion/mason-tool-installer.lua

This file was deleted.

37 changes: 37 additions & 0 deletions lua/modules/configs/completion/null-ls.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
return function()
local null_ls = require("null-ls")
local mason_null_ls = require("mason-null-ls")
local btnf = null_ls.builtins.formatting
local btnd = null_ls.builtins.diagnostics
local null_reg = null_ls.register

null_ls.setup({
debug = false,
update_in_insert = false,
diagnostics_format = "[#{s} #{c}] #{m}",
})

mason_null_ls.setup({
ensure_installed = require("core.settings").null_ls,
automatic_installation = true,
automatic_setup = true,
})

-- NOTE: Users don't need to specify null-ls sources if using only default config.
-- "mason-null-ls" will auto-setup for users.
mason_null_ls.setup_handlers({
black = function()
null_reg(btnf.black.with({ extra_args = { "--fast" } }))
end,
markdownlint = function()
null_reg(btnf.markdownlint)
null_reg(btnd.markdownlint.with({ extra_args = { "--disable MD033" } }))
end,
-- example for changing diagnostics_format
-- shellcheck = function()
-- null_reg(btnd.shellcheck.with({ diagnostics_format = "#{m} [#{s} #{c}]" }))
-- end,
})

require("completion.formatting").configure_format_on_save()
end
15 changes: 9 additions & 6 deletions lua/modules/plugins/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ completion["neovim/nvim-lspconfig"] = {
event = { "BufReadPost", "BufAdd", "BufNewFile" },
config = require("completion.lsp"),
dependencies = {
{ "creativenull/efmls-configs-nvim" },
{ "ray-x/lsp_signature.nvim" },
{ "williamboman/mason.nvim" },
{ "williamboman/mason-lspconfig.nvim" },
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
config = require("completion.mason-tool-installer"),
},
{
"glepnir/lspsaga.nvim",
config = require("completion.lspsaga"),
},
{ "ray-x/lsp_signature.nvim" },
{
"jose-elias-alvarez/null-ls.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"jay-babu/mason-null-ls.nvim",
},
config = require("completion.null-ls"),
},
},
}
completion["hrsh7th/nvim-cmp"] = {
Expand Down
Loading

0 comments on commit 9323316

Please sign in to comment.