Remove nvim-lsp-config and manually add each lsp.

This commit is contained in:
calcu1on 2025-05-20 08:55:12 -04:00
parent 571341310a
commit bb66b8fa82
10 changed files with 162 additions and 106 deletions

View File

@ -21,6 +21,17 @@ vim.o.termguicolors = true
-- vim.cmd "let g:everforest_background = 'hard'"
vim.cmd.colorscheme('nordfox')
-- LSP --
vim.o.winborder = 'rounded'
vim.lsp.enable({'intelephense'})
vim.lsp.enable({'drupal-lsp'})
vim.lsp.enable({'rust_analyzer'})
vim.lsp.enable({'elixirls'})
vim.lsp.enable({'lexical'})
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
vim.keymap.set({ "n" }, "<leader>ca", vim.lsp.buf.code_action, {})
-- XDEBUG --
local dap = require('dap')
require('telescope').load_extension('dap')
@ -50,13 +61,6 @@ dap.configurations.php = {
}
}
-- vim.cmd [[
-- highlight Normal guibg=none
-- highlight NonText guibg=none
-- highlight Normal ctermbg=none
-- highlight NonText ctermbg=none
-- ]]
vim.fn.sign_define('DapBreakpoint',{ text ='🟥', texthl ='', linehl ='', numhl =''})
vim.fn.sign_define('DapStopped',{ text ='▶️', texthl ='', linehl ='', numhl =''})
vim.keymap.set('n', '<leader>?', function() dap.continue() end)
@ -72,17 +76,17 @@ vim.keymap.set('n', '<leader>db', function()
widgets.centered_float(widgets.scopes)
end)
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'
if not configs.drupal then
configs.drupal = {
default_config = {
cmd = {'drupal-lsp'},
filetypes = {'php', 'module', 'inc', 'theme'},
root_dir = function(fname)
return lspconfig.util.root_pattern('composer.json', '.git')(fname)
end
};
}
end
lspconfig.drupal.setup{ autostart = true }
-- local lspconfig = require 'lspconfig'
-- local configs = require 'lspconfig.configs'
-- if not configs.drupal then
-- configs.drupal = {
-- default_config = {
-- cmd = {'drupal-lsp'},
-- filetypes = {'php', 'module', 'inc', 'theme'},
-- root_dir = function(fname)
-- return lspconfig.util.root_pattern('composer.json', '.git')(fname)
-- end
-- };
-- }
-- end
-- lspconfig.drupal.setup{ autostart = true }

View File

@ -20,7 +20,6 @@
"nvim-dap": { "branch": "master", "commit": "8df427aeba0a06c6577dc3ab82de3076964e3b8d" },
"nvim-dap-ui": { "branch": "master", "commit": "73a26abf4941aa27da59820fd6b028ebcdbcf932" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "df66808cd78b5a97576bbaeee95ed5ca385a9750" },
"nvim-lspconfig": { "branch": "master", "commit": "ac1dfbe3b60e5e23a2cff90e3bd6a3bc88031a57" },
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
"nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" },
"nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" },

12
lsp/drupal.lua Normal file
View 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
View 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
View 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
View File

@ -0,0 +1,4 @@
return {
filetypes = { 'elixir', 'eelixir', 'heex', 'surface' },
root_markers = { 'mix.exs', '.git' },
}

96
lsp/rust_analyzer.lua Normal file
View 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,
}

View File

@ -33,10 +33,6 @@ vim.keymap.set("n", "<leader>tt", function()
job_id = vim.bo.channel
end)
vim.keymap.set("n", "<leader>build", function()
vim.fn.chansend(job_id, { "ls -lah<CR>" })
end)
-- General config
vim.cmd("set expandtab")
vim.cmd("set tabstop=2")
@ -45,12 +41,7 @@ vim.cmd("set shiftwidth=2")
vim.cmd("set syntax=on")
vim.cmd("set number")
vim.cmd("set nu")
-- vim.cmd("set relativenumber")
-- vim.cmd("set rnu")
-- vim.cmd("set number relativenumber")
-- vim.cmd("set nu rnu")
-- vim.cmd("set guicursor=n-v-c-i:block")
-- vim.cmd("set guicursor=a:blinkon100")
-- vim.cmd("set guicursor=n-v-c:block")
vim.api.nvim_set_option("clipboard","unnamed")
-- Command to turn off diagnostics, if crowding screen

View File

@ -9,27 +9,8 @@ return {
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup({
ensure_installed = { "lua_ls", "phpactor", "rust_analyzer" },
ensure_installed = { "lua_ls", "intelephense", "rust_analyzer", "elixirls" },
})
end,
},
{
"neovim/nvim-lspconfig",
config = function()
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup({
capabilities = capabilities,
})
lspconfig.phpactor.setup({
capabilities = capabilities,
})
lspconfig.rust_analyzer.setup({
capabilities = capabilities,
})
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
vim.keymap.set({ "n" }, "<leader>ca", vim.lsp.buf.code_action, {})
end,
},
}

View File

@ -1,54 +0,0 @@
local t_opts = {silent = true}
vim.keymap.set('t', '<C-n>', '<C-\\><C-N>', t_opts)
vim.keymap.set('t', '<C-h>', '<cmd>Danterm<CR>')
vim.keymap.set('n', '<leader>dt', '<cmd>Danterm<CR>')
local state = {
floating = {
buf = -1,
win = -1,
}
}
local function dan_term(opts)
opts = opts or {}
local width = opts.width or math.floor(vim.o.columns * 0.8)
local height = opts.height or math.floor(vim.o.lines * 0.8)
local screen_width = vim.o.columns
local screen_height = vim.o.lines
local col = math.floor((screen_width - width) / 2)
local row = math.floor((screen_height - height) / 2)
local buf = nil
if vim.api.nvim_buf_is_valid(opts.buf) then
buf = opts.buf
else
buf = vim.api.nvim_create_buf(false, true)
end
local win_config = {
relative = 'editor',
width = width,
height = height,
col = col,
row = row,
style = 'minimal',
border = 'rounded', -- optional, choose 'none', 'single', 'double', etc.
}
local win = vim.api.nvim_open_win(buf, true, win_config)
return { buf = buf, win = win }
end
vim.api.nvim_create_user_command("Danterm", function()
if not vim.api.nvim_win_is_valid(state.floating.win) then
state.floating = dan_term { buf = state.floating.buf }
if vim.bo[state.floating.buf].buftype ~= "terminal" then
vim.cmd.term()
vim.api.nvim_input("i")
end
else
vim.api.nvim_win_hide(state.floating.win)
end
end, {})