Remove nvim-lsp-config and manually add each lsp.
This commit is contained in:
12
lsp/drupal.lua
Normal file
12
lsp/drupal.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
return {
|
||||
cmd = {'drupal-lsp'},
|
||||
filetypes = {'php', 'module', 'inc', 'theme'},
|
||||
root_dir = function(bufnr, on_dir)
|
||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local cwd = assert(vim.uv.cwd())
|
||||
local root = vim.fs.root(fname, { 'composer.json', '.git' })
|
||||
|
||||
-- prefer cwd if root is a descendant
|
||||
on_dir(root and vim.fs.relpath(cwd, root) and cwd)
|
||||
end,
|
||||
}
|
||||
11
lsp/elixirls.lua
Normal file
11
lsp/elixirls.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
return {
|
||||
filetypes = { 'elixir', 'eelixir', 'heex', 'surface' },
|
||||
root_dir = function(bufnr, on_dir)
|
||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local matches = vim.fs.find({ 'mix.exs' }, { upward = true, limit = 2, path = fname })
|
||||
local child_or_root_path, maybe_umbrella_path = unpack(matches)
|
||||
local root_dir = vim.fs.dirname(maybe_umbrella_path or child_or_root_path)
|
||||
|
||||
on_dir(root_dir)
|
||||
end,
|
||||
}
|
||||
12
lsp/intelephense.lua
Normal file
12
lsp/intelephense.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
return {
|
||||
cmd = { 'intelephense', '--stdio' },
|
||||
filetypes = { 'php' },
|
||||
root_dir = function(bufnr, on_dir)
|
||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local cwd = assert(vim.uv.cwd())
|
||||
local root = vim.fs.root(fname, { 'composer.json', '.git' })
|
||||
|
||||
-- prefer cwd if root is a descendant
|
||||
on_dir(root and vim.fs.relpath(cwd, root) and cwd)
|
||||
end,
|
||||
}
|
||||
4
lsp/lexical.lua
Normal file
4
lsp/lexical.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
return {
|
||||
filetypes = { 'elixir', 'eelixir', 'heex', 'surface' },
|
||||
root_markers = { 'mix.exs', '.git' },
|
||||
}
|
||||
96
lsp/rust_analyzer.lua
Normal file
96
lsp/rust_analyzer.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
local function reload_workspace(bufnr)
|
||||
local clients = vim.lsp.get_clients { bufnr = bufnr, name = 'rust_analyzer' }
|
||||
for _, client in ipairs(clients) do
|
||||
vim.notify 'Reloading Cargo Workspace'
|
||||
client.request('rust-analyzer/reloadWorkspace', nil, function(err)
|
||||
if err then
|
||||
error(tostring(err))
|
||||
end
|
||||
vim.notify 'Cargo workspace reloaded'
|
||||
end, 0)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_library(fname)
|
||||
local user_home = vim.fs.normalize(vim.env.HOME)
|
||||
local cargo_home = os.getenv 'CARGO_HOME' or user_home .. '/.cargo'
|
||||
local registry = cargo_home .. '/registry/src'
|
||||
local git_registry = cargo_home .. '/git/checkouts'
|
||||
|
||||
local rustup_home = os.getenv 'RUSTUP_HOME' or user_home .. '/.rustup'
|
||||
local toolchains = rustup_home .. '/toolchains'
|
||||
|
||||
for _, item in ipairs { toolchains, registry, git_registry } do
|
||||
if vim.fs.relpath(item, fname) then
|
||||
local clients = vim.lsp.get_clients { name = 'rust_analyzer' }
|
||||
return #clients > 0 and clients[#clients].config.root_dir or nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
cmd = { 'rust-analyzer' },
|
||||
filetypes = { 'rust' },
|
||||
root_dir = function(bufnr, on_dir)
|
||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local reused_dir = is_library(fname)
|
||||
if reused_dir then
|
||||
on_dir(reused_dir)
|
||||
return
|
||||
end
|
||||
|
||||
local cargo_crate_dir = vim.fs.root(fname, { 'Cargo.toml' })
|
||||
local cargo_workspace_root
|
||||
|
||||
if cargo_crate_dir == nil then
|
||||
on_dir(
|
||||
vim.fs.root(fname, { 'rust-project.json' })
|
||||
or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
local cmd = {
|
||||
'cargo',
|
||||
'metadata',
|
||||
'--no-deps',
|
||||
'--format-version',
|
||||
'1',
|
||||
'--manifest-path',
|
||||
cargo_crate_dir .. '/Cargo.toml',
|
||||
}
|
||||
|
||||
vim.system(cmd, { text = true }, function(output)
|
||||
if output.code == 0 then
|
||||
if output.stdout then
|
||||
local result = vim.json.decode(output.stdout)
|
||||
if result['workspace_root'] then
|
||||
cargo_workspace_root = vim.fs.normalize(result['workspace_root'])
|
||||
end
|
||||
end
|
||||
|
||||
on_dir(cargo_workspace_root or cargo_crate_dir)
|
||||
else
|
||||
vim.schedule(function()
|
||||
vim.notify(('[rust_analyzer] cmd failed with code %d: %s\n%s'):format(output.code, cmd, output.stderr))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
capabilities = {
|
||||
experimental = {
|
||||
serverStatusNotification = true,
|
||||
},
|
||||
},
|
||||
before_init = function(init_params, config)
|
||||
-- See https://github.com/rust-lang/rust-analyzer/blob/eb5da56d839ae0a9e9f50774fa3eb78eb0964550/docs/dev/lsp-extensions.md?plain=1#L26
|
||||
if config.settings and config.settings['rust-analyzer'] then
|
||||
init_params.initializationOptions = config.settings['rust-analyzer']
|
||||
end
|
||||
end,
|
||||
on_attach = function()
|
||||
vim.api.nvim_buf_create_user_command(0, 'LspCargoReload', function()
|
||||
reload_workspace(0)
|
||||
end, { desc = 'Reload current cargo workspace' })
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user