feat(lsp): trade efm and eslint for null-ls
This commit is contained in:
parent
c11986eaa5
commit
3aab287794
10 changed files with 67 additions and 128 deletions
|
@ -1,6 +1,8 @@
|
||||||
-- Override Cosmic configuration options
|
-- Override Cosmic configuration options
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
-- You can require null-ls if needed
|
||||||
|
-- local null_ls = require('null-ls')
|
||||||
|
|
||||||
local config = {}
|
local config = {}
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@ config.lsp = {
|
||||||
rust_analyzer = true,
|
rust_analyzer = true,
|
||||||
|
|
||||||
tsserver = {
|
tsserver = {
|
||||||
-- disable formatting
|
-- disable formatting (defaults to true)
|
||||||
format = false,
|
format = false,
|
||||||
-- OR add/override server options
|
-- OR add/override server options
|
||||||
opts = {
|
opts = {
|
||||||
|
@ -50,12 +52,12 @@ config.lsp = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
efm = {
|
-- See Cosmic defaults lsp/providers/null_ls.lua
|
||||||
-- specifc to efm, e.g. 'eslint', 'prettier', 'stylua'
|
null_ls = {}
|
||||||
disable_formatters = {'eslint'},
|
|
||||||
},
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- See Cosmic defaults lsp/providers/tsserver.lua
|
||||||
|
ts_utils = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -22,17 +22,13 @@ local default_config = {
|
||||||
},
|
},
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- enable, but disable formatting
|
sumneko_lua = {
|
||||||
eslint = {
|
format = false, -- disable formatting all together
|
||||||
format = false,
|
|
||||||
},
|
|
||||||
efm = {
|
|
||||||
format = true,
|
|
||||||
disable_formatters = { 'eslint' }, -- e.g. 'eslint', 'prettier', 'stylua'
|
|
||||||
},
|
},
|
||||||
tsserver = {
|
tsserver = {
|
||||||
format = false, -- disable formatting all together
|
format = false, -- disable formatting all together
|
||||||
},
|
},
|
||||||
|
null_ls = {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -48,7 +44,7 @@ function config.lsp.can_client_format(client_name)
|
||||||
return (config.lsp.servers[client_name].format == true)
|
return (config.lsp.servers[client_name].format == true)
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -19,6 +19,7 @@ map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
||||||
map('n', '<leader>ga', '<cmd>lua require("telescope.builtin").lsp_code_actions()<cr>')
|
map('n', '<leader>ga', '<cmd>lua require("telescope.builtin").lsp_code_actions()<cr>')
|
||||||
map('v', '<leader>ga', '<cmd>lua require("telescope.builtin").lsp_range_code_actions()<cr>')
|
map('v', '<leader>ga', '<cmd>lua require("telescope.builtin").lsp_range_code_actions()<cr>')
|
||||||
map('n', '<leader>gf', '<cmd>lua vim.lsp.buf.formatting()<cr>')
|
map('n', '<leader>gf', '<cmd>lua vim.lsp.buf.formatting()<cr>')
|
||||||
|
map('v', '<leader>gf', '<cmd>lua vim.lsp.buf.range_formatting()<cr>')
|
||||||
map('n', '<C-K>', '<cmd>lua require("lsp_signature").signature()<cr>')
|
map('n', '<C-K>', '<cmd>lua require("lsp_signature").signature()<cr>')
|
||||||
|
|
||||||
-- lsp workspace
|
-- lsp workspace
|
||||||
|
|
|
@ -49,7 +49,15 @@ M.flags = {
|
||||||
debounce_text_changes = 150,
|
debounce_text_changes = 150,
|
||||||
}
|
}
|
||||||
|
|
||||||
M.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
local function get_capabilities()
|
||||||
|
local ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
|
||||||
|
if not ok then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
return cmp_nvim_lsp.update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
|
end
|
||||||
|
|
||||||
|
M.capabilities = get_capabilities()
|
||||||
|
|
||||||
M.root_dir = function(fname)
|
M.root_dir = function(fname)
|
||||||
local util = require('lspconfig').util
|
local util = require('lspconfig').util
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
local util = require('lspconfig').util
|
|
||||||
local config = require('cosmic.config')
|
|
||||||
local formatters = {}
|
|
||||||
|
|
||||||
formatters.stylua = {
|
|
||||||
formatCommand = 'stylua -s --quote-style AutoPreferSingle --indent-type Spaces --indent-width 2 -',
|
|
||||||
formatStdin = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
formatters.eslint = {
|
|
||||||
lintCommand = 'eslint_d -f unix --stdin --stdin-filename ${INPUT}',
|
|
||||||
lintStdin = true,
|
|
||||||
lintFormats = { '%f:%l:%c: %m' },
|
|
||||||
lintIgnoreExitCode = true,
|
|
||||||
formatCommand = 'eslint_d --stdin --fix-to-stdout --stdin-filename=${INPUT}',
|
|
||||||
formatStdin = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
formatters.prettier = {
|
|
||||||
-- formatCommand = 'prettier --stdin-filepath ${INPUT}',
|
|
||||||
formatCommand = 'prettierd "${INPUT}"',
|
|
||||||
formatStdin = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
local filetype_defaults = {
|
|
||||||
'css',
|
|
||||||
'html',
|
|
||||||
'lua',
|
|
||||||
'javascript',
|
|
||||||
'javascriptreact',
|
|
||||||
'json',
|
|
||||||
'markdown',
|
|
||||||
'scss',
|
|
||||||
'typescript',
|
|
||||||
'typescriptreact',
|
|
||||||
'yaml',
|
|
||||||
}
|
|
||||||
|
|
||||||
formatters.defaults = {
|
|
||||||
eslint = {
|
|
||||||
'javascript',
|
|
||||||
'javascriptreact',
|
|
||||||
'json',
|
|
||||||
'typescriptreact',
|
|
||||||
'typescript',
|
|
||||||
},
|
|
||||||
prettier = {
|
|
||||||
'css',
|
|
||||||
'html',
|
|
||||||
'javascript',
|
|
||||||
'javascriptreact',
|
|
||||||
'json',
|
|
||||||
'typescriptreact',
|
|
||||||
'typescript',
|
|
||||||
'markdown',
|
|
||||||
'scss',
|
|
||||||
'yaml',
|
|
||||||
},
|
|
||||||
stylua = { 'lua' },
|
|
||||||
}
|
|
||||||
|
|
||||||
local languages = {}
|
|
||||||
for formatter, filetypes in pairs(formatters.defaults) do
|
|
||||||
-- disable specific formatters
|
|
||||||
if not vim.tbl_contains(config.lsp.servers.efm.disable_formatters, formatter) then
|
|
||||||
for _, filetype in pairs(filetypes) do
|
|
||||||
languages[filetype] = languages[filetype] or {}
|
|
||||||
table.insert(languages[filetype], formatters[formatter])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
init_options = { documentFormatting = true, codeAction = true },
|
|
||||||
root_dir = function(fname)
|
|
||||||
return util.root_pattern('.git')(fname)
|
|
||||||
or util.root_pattern('tsconfig.base.json')(fname)
|
|
||||||
or util.root_pattern('package.json')(fname)
|
|
||||||
or util.root_pattern('.eslintrc.js')(fname)
|
|
||||||
or util.root_pattern('tsconfig.json')(fname)
|
|
||||||
end,
|
|
||||||
filetypes = filetype_defaults,
|
|
||||||
settings = { languages = languages },
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
local util = require('lspconfig').util
|
|
||||||
|
|
||||||
return {
|
|
||||||
settings = {
|
|
||||||
packageManager = 'npm',
|
|
||||||
format = true,
|
|
||||||
},
|
|
||||||
root_dir = function(fname)
|
|
||||||
return util.root_pattern('.git')(fname)
|
|
||||||
or util.root_pattern('tsconfig.base.json')(fname)
|
|
||||||
or util.root_pattern('package.json')(fname)
|
|
||||||
or util.root_pattern('.eslintrc.js')(fname)
|
|
||||||
or util.root_pattern('tsconfig.json')(fname)
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -19,8 +19,8 @@ lsp_installer.settings({
|
||||||
|
|
||||||
-- initial default serverse
|
-- initial default serverse
|
||||||
local requested_servers = {
|
local requested_servers = {
|
||||||
'eslint',
|
-- 'eslint',
|
||||||
'efm',
|
-- 'efm',
|
||||||
'tsserver',
|
'tsserver',
|
||||||
'sumneko_lua',
|
'sumneko_lua',
|
||||||
'jsonls',
|
'jsonls',
|
||||||
|
@ -63,14 +63,10 @@ lsp_installer.on_server_ready(function(server)
|
||||||
-- set up default cosmic options
|
-- set up default cosmic options
|
||||||
if server.name == 'tsserver' then
|
if server.name == 'tsserver' then
|
||||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.tsserver'))
|
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.tsserver'))
|
||||||
elseif server.name == 'efm' then
|
|
||||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.efm'))
|
|
||||||
elseif server.name == 'jsonls' then
|
elseif server.name == 'jsonls' then
|
||||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.jsonls'))
|
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.jsonls'))
|
||||||
elseif server.name == 'sumneko_lua' then
|
elseif server.name == 'sumneko_lua' then
|
||||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.lua'))
|
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.lua'))
|
||||||
elseif server.name == 'eslint' then
|
|
||||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.eslint'))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- override options if user definds them
|
-- override options if user definds them
|
||||||
|
|
26
lua/cosmic/lsp/providers/null_ls.lua
Normal file
26
lua/cosmic/lsp/providers/null_ls.lua
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
local config = require('cosmic.config')
|
||||||
|
local on_attach = require('cosmic.lsp.providers.defaults').on_attach
|
||||||
|
local null_ls = require('null-ls')
|
||||||
|
|
||||||
|
null_ls.config(vim.tbl_deep_extend('force', {
|
||||||
|
-- you must define at least one source for the plugin to work
|
||||||
|
sources = {
|
||||||
|
null_ls.builtins.formatting.stylua.with({
|
||||||
|
args = {
|
||||||
|
'-s',
|
||||||
|
'--quote-style',
|
||||||
|
'AutoPreferSingle',
|
||||||
|
'--indent-type',
|
||||||
|
'Spaces',
|
||||||
|
'--indent-width',
|
||||||
|
'2',
|
||||||
|
'-',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
null_ls.builtins.code_actions.gitsigns,
|
||||||
|
},
|
||||||
|
}, config.lsp.servers.null_ls))
|
||||||
|
|
||||||
|
require('lspconfig')['null-ls'].setup({
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
|
@ -1,4 +1,5 @@
|
||||||
local default_on_attach = require('cosmic.lsp.providers.defaults').on_attach
|
local default_on_attach = require('cosmic.lsp.providers.defaults').on_attach
|
||||||
|
local config = require('cosmic.config')
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.on_attach(client, bufnr)
|
function M.on_attach(client, bufnr)
|
||||||
|
@ -7,7 +8,7 @@ function M.on_attach(client, bufnr)
|
||||||
local ts_utils = require('nvim-lsp-ts-utils')
|
local ts_utils = require('nvim-lsp-ts-utils')
|
||||||
|
|
||||||
-- defaults
|
-- defaults
|
||||||
ts_utils.setup({
|
ts_utils.setup(vim.tbl_deep_extend('force', {
|
||||||
debug = false,
|
debug = false,
|
||||||
disable_commands = false,
|
disable_commands = false,
|
||||||
enable_import_on_completion = true,
|
enable_import_on_completion = true,
|
||||||
|
@ -24,16 +25,16 @@ function M.on_attach(client, bufnr)
|
||||||
import_all_select_source = false,
|
import_all_select_source = false,
|
||||||
|
|
||||||
-- eslint
|
-- eslint
|
||||||
eslint_enable_code_actions = false,
|
eslint_enable_code_actions = true,
|
||||||
eslint_enable_disable_comments = false,
|
eslint_enable_disable_comments = true,
|
||||||
eslint_bin = 'eslint_d',
|
eslint_bin = 'eslint_d',
|
||||||
eslint_enable_diagnostics = false,
|
eslint_enable_diagnostics = true,
|
||||||
eslint_opts = {},
|
-- eslint_opts = {},
|
||||||
|
|
||||||
-- formatting
|
-- formatting
|
||||||
enable_formatting = false,
|
enable_formatting = true,
|
||||||
formatter = 'prettierd',
|
formatter = 'prettierd',
|
||||||
formatter_opts = {},
|
-- formatter_opts = {},
|
||||||
|
|
||||||
-- update imports on file move
|
-- update imports on file move
|
||||||
update_imports_on_move = true,
|
update_imports_on_move = true,
|
||||||
|
@ -43,7 +44,7 @@ function M.on_attach(client, bufnr)
|
||||||
-- filter diagnostics
|
-- filter diagnostics
|
||||||
filter_out_diagnostics_by_severity = {},
|
filter_out_diagnostics_by_severity = {},
|
||||||
filter_out_diagnostics_by_code = {},
|
filter_out_diagnostics_by_code = {},
|
||||||
})
|
}, config.lsp.ts_utils or {}))
|
||||||
|
|
||||||
-- required to fix code action ranges and filter diagnostics
|
-- required to fix code action ranges and filter diagnostics
|
||||||
ts_utils.setup_client(client)
|
ts_utils.setup_client(client)
|
||||||
|
|
|
@ -115,6 +115,14 @@ return packer.startup(function()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
use({
|
||||||
|
'jose-elias-alvarez/null-ls.nvim',
|
||||||
|
config = function()
|
||||||
|
require('cosmic.lsp.providers.null_ls')
|
||||||
|
end,
|
||||||
|
requires = { 'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig' },
|
||||||
|
})
|
||||||
|
|
||||||
use({
|
use({
|
||||||
'L3MON4D3/LuaSnip',
|
'L3MON4D3/LuaSnip',
|
||||||
config = function()
|
config = function()
|
||||||
|
|
Loading…
Add table
Reference in a new issue