add lsp-file-operations
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
10
lua/dkelly/plugins/lsp-file-operations.lua
Normal file
10
lua/dkelly/plugins/lsp-file-operations.lua
Normal 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,
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user