lsp: unconditionally load setup
This commit is contained in:
parent
5076180f27
commit
6d72a4c713
1 changed files with 93 additions and 119 deletions
212
init.lua
212
init.lua
|
|
@ -282,135 +282,109 @@ cmp.setup({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
---- LSP ----
|
---- LSP ----
|
||||||
vim.g.lsp_loaded = false
|
vim.cmd("packadd nvim-lspconfig")
|
||||||
vim.api.nvim_create_autocmd({ "FileType" }, {
|
vim.cmd("packadd lsp_lines.nvim")
|
||||||
pattern = {
|
-- vim.cmd("packadd lsp-timeout.nvim")
|
||||||
"c",
|
|
||||||
"cpp",
|
|
||||||
"dot",
|
|
||||||
"go",
|
|
||||||
"javascript",
|
|
||||||
"json",
|
|
||||||
"latex",
|
|
||||||
"lua",
|
|
||||||
"python",
|
|
||||||
"rust",
|
|
||||||
"terraform",
|
|
||||||
"tex",
|
|
||||||
"toml",
|
|
||||||
"typescript",
|
|
||||||
"typst",
|
|
||||||
},
|
|
||||||
callback = function()
|
|
||||||
if vim.g.lsp_loaded == true then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
vim.g.lsp_loaded = true
|
|
||||||
vim.cmd("packadd nvim-lspconfig")
|
|
||||||
vim.cmd("packadd lsp_lines.nvim")
|
|
||||||
-- vim.cmd("packadd lsp-timeout.nvim")
|
|
||||||
|
|
||||||
local lsp = require("lspconfig")
|
local lsp = require("lspconfig")
|
||||||
-- Use an on_attach function to only map the following keys
|
-- Use an on_attach function to only map the following keys
|
||||||
-- after the language server attaches to the current buffer
|
-- after the language server attaches to the current buffer
|
||||||
local on_lsp_attach = function(_client, _bufnr)
|
local on_lsp_attach = function(_client, _bufnr)
|
||||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration)
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration)
|
||||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition)
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition)
|
||||||
vim.keymap.set("n", "K", vim.lsp.buf.hover)
|
vim.keymap.set("n", "K", vim.lsp.buf.hover)
|
||||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation)
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation)
|
||||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help)
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help)
|
||||||
vim.keymap.set("n", "<Leader>D", vim.lsp.buf.type_definition)
|
vim.keymap.set("n", "<Leader>D", vim.lsp.buf.type_definition)
|
||||||
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename)
|
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename)
|
||||||
vim.keymap.set("n", "<Leader>ca", vim.lsp.buf.code_action)
|
vim.keymap.set("n", "<Leader>ca", vim.lsp.buf.code_action)
|
||||||
vim.keymap.set("n", "gr", vim.lsp.buf.references)
|
vim.keymap.set("n", "gr", vim.lsp.buf.references)
|
||||||
vim.keymap.set("n", "<Leader>e", vim.diagnostic.open_float)
|
vim.keymap.set("n", "<Leader>e", vim.diagnostic.open_float)
|
||||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
|
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
|
||||||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
|
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
|
||||||
vim.keymap.set("n", "<Leader>q", vim.diagnostic.setloclist)
|
vim.keymap.set("n", "<Leader>q", vim.diagnostic.setloclist)
|
||||||
-- vim.keymap.segcjk("n", "<F3>", function()
|
-- vim.keymap.segcjk("n", "<F3>", function()
|
||||||
-- vim.lsp.buf.format({ async = true })
|
-- vim.lsp.buf.format({ async = true })
|
||||||
-- end)
|
-- end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
-- Use a loop to conveniently call 'setup' on multiple servers and
|
||||||
-- map buffer local keybindings when the language server attaches
|
-- map buffer local keybindings when the language server attaches
|
||||||
local servers = {
|
local servers = {
|
||||||
clangd = {
|
clangd = {
|
||||||
filetypes = { "c", "cpp" }
|
filetypes = { "c", "cpp" }
|
||||||
},
|
},
|
||||||
dotls = {},
|
dotls = {},
|
||||||
eslint = {},
|
eslint = {},
|
||||||
gopls = {},
|
gopls = {},
|
||||||
jsonls = {},
|
jsonls = {},
|
||||||
kotlin_language_server = {},
|
kotlin_language_server = {},
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
runtime = { version = "LuaJIT" },
|
runtime = { version = "LuaJIT" },
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
globals = { "vim" },
|
globals = { "vim" },
|
||||||
unusedLocalExclude = { "_*" },
|
unusedLocalExclude = { "_*" },
|
||||||
},
|
|
||||||
workspace = {
|
|
||||||
checkThirdParty = false,
|
|
||||||
library = vim.api.nvim_get_runtime_file("", true),
|
|
||||||
},
|
|
||||||
telemetry = { enable = false },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
workspace = {
|
||||||
|
checkThirdParty = false,
|
||||||
|
library = vim.api.nvim_get_runtime_file("", true),
|
||||||
|
},
|
||||||
|
telemetry = { enable = false },
|
||||||
},
|
},
|
||||||
pylsp = {},
|
},
|
||||||
rust_analyzer = {
|
},
|
||||||
settings = {
|
pylsp = {},
|
||||||
['rust-analyzer'] = {
|
rust_analyzer = {
|
||||||
cargo = {
|
settings = {
|
||||||
features = "all"
|
['rust-analyzer'] = {
|
||||||
}
|
cargo = {
|
||||||
}
|
features = "all"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
taplo = {},
|
|
||||||
texlab = {},
|
|
||||||
tflint = {},
|
|
||||||
tsserver = {},
|
|
||||||
biome = {
|
|
||||||
cmd = { "pnpm", "exec", "biome", "lsp-proxy" }
|
|
||||||
},
|
|
||||||
typst_lsp = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
||||||
lsp.util.default_config = vim.tbl_deep_extend("force", lsp.util.default_config, { capabilities = capabilities })
|
|
||||||
for server, add_to_config in pairs(servers) do
|
|
||||||
local config = {
|
|
||||||
on_attach = on_lsp_attach,
|
|
||||||
flags = {
|
|
||||||
debounce_text_changes = 150,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for k, v in pairs(add_to_config) do
|
}
|
||||||
config[k] = v
|
},
|
||||||
end
|
taplo = {},
|
||||||
lsp[server].setup(config)
|
texlab = {},
|
||||||
end
|
tflint = {},
|
||||||
vim.cmd("LspStart")
|
tsserver = {},
|
||||||
|
biome = {
|
||||||
|
cmd = { "pnpm", "exec", "biome", "lsp-proxy" }
|
||||||
|
},
|
||||||
|
typst_lsp = {},
|
||||||
|
}
|
||||||
|
|
||||||
---- lsp_lines
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
require("lsp_lines").setup()
|
lsp.util.default_config = vim.tbl_deep_extend("force", lsp.util.default_config, { capabilities = capabilities })
|
||||||
-- Disable virtual_text since it's redundant due to lsp_lines.
|
for server, add_to_config in pairs(servers) do
|
||||||
vim.diagnostic.config({
|
local config = {
|
||||||
virtual_text = false,
|
on_attach = on_lsp_attach,
|
||||||
})
|
flags = {
|
||||||
|
debounce_text_changes = 150,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for k, v in pairs(add_to_config) do
|
||||||
|
config[k] = v
|
||||||
|
end
|
||||||
|
lsp[server].setup(config)
|
||||||
|
end
|
||||||
|
vim.cmd("LspStart")
|
||||||
|
|
||||||
---- lsp-timeout
|
---- lsp_lines
|
||||||
-- vim.g["lsp-timeout-config"] = {
|
require("lsp_lines").setup()
|
||||||
-- stopTimeout = 1000 * 60 * 5, -- ms, timeout before stopping all LSP servers
|
-- Disable virtual_text since it's redundant due to lsp_lines.
|
||||||
-- startTimeout = 1000 * 2, -- ms, timeout before restart
|
vim.diagnostic.config({
|
||||||
-- silent = false -- true to suppress notifications
|
virtual_text = false,
|
||||||
-- }
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---- lsp-timeout
|
||||||
|
-- vim.g["lsp-timeout-config"] = {
|
||||||
|
-- stopTimeout = 1000 * 60 * 5, -- ms, timeout before stopping all LSP servers
|
||||||
|
-- startTimeout = 1000 * 2, -- ms, timeout before restart
|
||||||
|
-- silent = false -- true to suppress notifications
|
||||||
|
-- }
|
||||||
|
|
||||||
-- -- Auto format on save
|
-- -- Auto format on save
|
||||||
-- vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
-- vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
-- callback = function()
|
-- callback = function()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue