add lsp-file-operations

This commit is contained in:
2025-05-13 14:24:32 -05:00
parent 113d8e1f3d
commit f32ce9b67d
5 changed files with 106 additions and 63 deletions

View File

@@ -1,6 +1,6 @@
{
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
"CopilotChat.nvim": { "branch": "main", "commit": "4dce4d2fc185a935024511811139b68e91b2d2a8" },
"CopilotChat.nvim": { "branch": "main", "commit": "16d897fd43d07e3b54478ccdb2f8a16e4df4f45a" },
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
"LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" },
"auto-session": { "branch": "main", "commit": "00334ee24b9a05001ad50221c8daffbeedaa0842" },
@@ -22,7 +22,8 @@
"mason-nvim-dap.nvim": { "branch": "main", "commit": "4c2cdc69d69fe00c15ae8648f7e954d99e5de3ea" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "62f821a14e20f3f2ee358cd44d0b3d299a508e72" },
"mason.nvim": { "branch": "main", "commit": "7c7318e8bae7e3536ef6b9e86b9e38e74f2e125e" },
"neotest": { "branch": "master", "commit": "2d9011396c43fa1d40221e6b6c3be5eb001427a9" },
"neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" },
"neotest": { "branch": "master", "commit": "862afb2a2219d9ca565f67416fb7003cc0f22c4f" },
"neotest-go": { "branch": "main", "commit": "92950ad7be2ca02a41abca5c6600ff6ffaf5b5d6" },
"neotest-golang": { "branch": "main", "commit": "5d1fdb068914ac23593495e71ecf9b1fad309b45" },
"neotest-python": { "branch": "master", "commit": "a2861ab3c9a0bf75a56b11835c2bfc8270f5be7e" },
@@ -30,13 +31,14 @@
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
"nvim-dap": { "branch": "master", "commit": "8df427aeba0a06c6577dc3ab82de3076964e3b8d" },
"nvim-dap-go": { "branch": "main", "commit": "8763ced35b19c8dc526e04a70ab07c34e11ad064" },
"nvim-dap-python": { "branch": "master", "commit": "34282820bb713b9a5fdb120ae8dd85c2b3f49b51" },
"nvim-dap-ui": { "branch": "master", "commit": "73a26abf4941aa27da59820fd6b028ebcdbcf932" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "df66808cd78b5a97576bbaeee95ed5ca385a9750" },
"nvim-lint": { "branch": "master", "commit": "9dfb77ef6c5092a19502883c02dc5a02ec648729" },
"nvim-lsp-file-operations": { "branch": "master", "commit": "9744b738183a5adca0f916527922078a965515ed" },
"nvim-lspconfig": { "branch": "master", "commit": "61e5109c8cf24807e4ae29813a3a82b31821dd45" },
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
"nvim-tree.lua": { "branch": "master", "commit": "e7d1b7dadc62fe2eccc17d814354b0a5688621ce" },
"nvim-treesitter": { "branch": "master", "commit": "28d480e0624b259095e56f353ec911f9f2a0f404" },
"nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" },
"nvim-treesitter-refactor": { "branch": "master", "commit": "d8b74fa87afc6a1e97b18da23e762efb032dc270" },
"nvim-ts-autotag": { "branch": "main", "commit": "a1d526af391f6aebb25a8795cbc05351ed3620b5" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "1b212c2eee76d787bbea6aa5e92a2b534e7b4f8f" },

View File

@@ -2,20 +2,20 @@ return {
{
"mfussenegger/nvim-dap",
dependencies = {
"leoluz/nvim-dap-go",
"rcarriga/nvim-dap-ui",
"mfussenegger/nvim-dap-python",
"theHamsta/nvim-dap-virtual-text",
"nvim-neotest/nvim-nio",
"williamboman/mason.nvim",
},
config = function()
local dap = require("dap")
dap.adapters.dart = {
type = "executable",
command = "flutter",
args = { "debug_adapter" },
}
local ui = require("dapui")
require("dapui").setup()
require("dap-go").setup()
require("dap-python").setup("python")
require("nvim-dap-virtual-text").setup()
vim.keymap.set("n", "<leader>bb", dap.toggle_breakpoint, { desc = "Toggle breakpoint" })
@@ -41,12 +41,6 @@ return {
dap.listeners.before.launch.dapui_config = function()
ui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
ui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
ui.close()
end
end,
},
}

View File

@@ -0,0 +1,10 @@
return {
"antosha417/nvim-lsp-file-operations",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-tree.lua", -- must be loaded first
},
config = function()
require("lsp-file-operations").setup({ debug = false })
end,
}

View File

@@ -9,10 +9,14 @@ return {
config = function()
-- import lspconfig plugin
local lspconfig = require("lspconfig")
-- import mason_lspconfig plugin
local mason_lspconfig = require("mason-lspconfig")
lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, {
capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
require("lsp-file-operations").default_capabilities()
),
})
lspconfig.dartls.setup({})
-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require("cmp_nvim_lsp")
@@ -67,9 +71,11 @@ return {
end,
})
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()
local capabilities = vim.tbl_deep_extend(
"force",
cmp_nvim_lsp.default_capabilities(),
require("lsp-file-operations").default_capabilities()
)
local on_attach = function(client, bufnr)
-- Enable completion triggered by <C-x><C-o>
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
@@ -83,7 +89,7 @@ return {
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<leader>f", function()
vim.keymap.set("n", "<leader>fr", function()
vim.lsp.buf.format({ async = true })
end, opts)
@@ -110,48 +116,72 @@ return {
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
mason_lspconfig.setup_handlers({
-- default handler for installed servers
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["lua_ls"] = function()
-- configure lua server (with special settings)
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
"rust_analyzer",
"gopls",
},
handlers = {
function(server_name) -- default handler (optional)
require("lspconfig")[server_name].setup({
capabilities = capabilities,
})
end,
zls = function()
local lspconfig = require("lspconfig")
lspconfig.zls.setup({
root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"),
settings = {
zls = {
enable_inlay_hints = true,
enable_snippets = true,
warn_style = true,
},
},
},
})
end,
["gopls"] = function()
lspconfig.gopls.setup({
on_attach = on_attach,
capabilities = capabilities,
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = lspconfig.util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholder = true,
analyses = {
unusedparams = true,
})
vim.g.zig_fmt_parse_errors = 0
vim.g.zig_fmt_autosave = 0
end,
["lua_ls"] = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
format = {
enable = true,
-- Put format options here
-- NOTE: the value should be STRING!!
defaultConfig = {
indent_style = "space",
indent_size = "2",
},
},
},
},
},
})
end,
})
end,
["gopls"] = function()
lspconfig.gopls.setup({
on_attach = on_attach,
capabilities = capabilities,
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = lspconfig.util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholder = true,
analyses = {
unusedparams = true,
},
},
},
})
end,
},
})
end,
}

View File

@@ -3,13 +3,14 @@ return {
dependencies = {
"williamboman/mason-lspconfig.nvim",
"WhoIsSethDaniel/mason-tool-installer.nvim",
"mfussenegger/nvim-dap",
"jay-babu/mason-nvim-dap.nvim",
},
config = function()
-- import mason
local mason = require("mason")
-- import mason-lspconfig
local mason_lspconfig = require("mason-lspconfig")
local mason_tool_installer = require("mason-tool-installer")
-- enable mason and configure icons
@@ -23,7 +24,12 @@ return {
},
})
mason_lspconfig.setup({
require("mason-nvim-dap").setup({
ensure_installed = { "python", "delve", "dart" },
automatic_installation = true,
})
require("mason-lspconfig").setup({
ensure_installed = {
-- LSP server names only
"bashls", -- Bash
@@ -46,6 +52,7 @@ return {
"vimls", -- Vim
"lemminx", -- XML
"cmake", -- CMake
"zls", -- Zig
-- Add others you use!
},
automatic_installation = true,