fix some lsp stuff for quick fix support

This commit is contained in:
kossLAN 2025-01-25 01:10:20 -05:00
parent 7804ae3939
commit f3f07ab618
Signed by: kossLAN
SSH key fingerprint: SHA256:bdV0x+wdQHGJ6LgmstH3KV8OpWY+OOFmJcPcB0wQPV8
5 changed files with 39 additions and 7 deletions

View file

@ -1,6 +1,6 @@
-- Exit if the language server isn't available -- Exit if the language server isn't available
if vim.fn.executable('clangd') ~= 1 then if vim.fn.executable('clangd') ~= 1 then
return return
end end
local root_files = { local root_files = {
@ -8,9 +8,12 @@ local root_files = {
'src', 'src',
} }
local lsp = require('user.lsp')
vim.lsp.start { vim.lsp.start {
name = 'clangd', name = 'clangd',
cmd = { 'clangd' }, cmd = { 'clangd' },
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
capabilities = require('user.lsp').make_client_capabilities(), capabilities = lsp.make_client_capabilities(),
on_attach = lsp.on_attach,
} }

View file

@ -8,6 +8,8 @@ local root_files = {
'Main.java', 'Main.java',
} }
local lsp = require('user.lsp')
-- Tab Width -- Tab Width
vim.bo.tabstop = 4 vim.bo.tabstop = 4
vim.bo.shiftwidth = 4 vim.bo.shiftwidth = 4
@ -17,7 +19,8 @@ vim.lsp.start {
name = 'jdtls', name = 'jdtls',
cmd = { 'jdtls' }, cmd = { 'jdtls' },
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
capabilities = require('user.lsp').make_client_capabilities(), capabilities = lsp.make_client_capabilities(),
on_attach = lsp.on_attach,
settings = { settings = {
java = { java = {
format = { format = {

View file

@ -8,9 +8,12 @@ local root_files = {
'.git', '.git',
} }
local lsp = require('user.lsp')
vim.lsp.start { vim.lsp.start {
name = 'nixd', name = 'nixd',
cmd = { 'nixd' }, cmd = { 'nixd' },
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
capabilities = require('user.lsp').make_client_capabilities(), capabilities = lsp.make_client_capabilities(),
on_attach = lsp.on_attach,
} }

View file

@ -20,4 +20,30 @@ function M.make_client_capabilities()
return capabilities return capabilities
end end
---Setup LSP keymaps for the current buffer
---@param bufnr number Buffer number
function M.setup_keymaps(bufnr)
-- Create a shorthand for mapping keys
local opts = { noremap = true, silent = true, buffer = bufnr }
-- Code actions
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
-- Quick fix
vim.keymap.set('n', '<leader>qf', vim.lsp.buf.code_action, opts)
-- Apply first available code action
vim.keymap.set('n', '<leader>af', function()
vim.lsp.buf.code_action {
filter = function(action)
return action.isPreferred
end,
apply = true,
}
end, opts)
end
-- Attach keymaps when LSP client attaches to a buffer
function M.on_attach(client, bufnr)
M.setup_keymaps(bufnr)
end
return M return M

View file

@ -57,9 +57,6 @@ vim.api.nvim_set_keymap(
{ noremap = true, silent = true, desc = 'debugger [r]epl' } { noremap = true, silent = true, desc = 'debugger [r]epl' }
) )
-- LSP Fix
vim.keymap.set('n', '<leader>f', vim.lsp.buf.code_action, { noremap = true, silent = true, desc = 'Code Action' })
-- Window Resizing -- Window Resizing
vim.keymap.set('n', '<C-Left>', '<cmd>vertical resize -2<CR>', { noremap = true, silent = true }) vim.keymap.set('n', '<C-Left>', '<cmd>vertical resize -2<CR>', { noremap = true, silent = true })
vim.keymap.set('n', '<C-Right>', '<cmd>vertical resize +2<CR>', { noremap = true, silent = true }) vim.keymap.set('n', '<C-Right>', '<cmd>vertical resize +2<CR>', { noremap = true, silent = true })