lsp: lazy load
This commit is contained in:
parent
61eca53e06
commit
4116644979
6 changed files with 146 additions and 121 deletions
11
.gitmodules
vendored
11
.gitmodules
vendored
|
|
@ -7,7 +7,7 @@
|
||||||
url = https://github.com/rktjmp/lush.nvim
|
url = https://github.com/rktjmp/lush.nvim
|
||||||
branch = main
|
branch = main
|
||||||
[submodule "pack/general/start/nvim-lspconfig"]
|
[submodule "pack/general/start/nvim-lspconfig"]
|
||||||
path = pack/general/start/nvim-lspconfig
|
path = pack/general/opt/nvim-lspconfig
|
||||||
url = https://github.com/neovim/nvim-lspconfig
|
url = https://github.com/neovim/nvim-lspconfig
|
||||||
branch = master
|
branch = master
|
||||||
[submodule "pack/general/start/nvim-treesitter"]
|
[submodule "pack/general/start/nvim-treesitter"]
|
||||||
|
|
@ -111,15 +111,15 @@
|
||||||
url = https://github.com/Saecki/crates.nvim
|
url = https://github.com/Saecki/crates.nvim
|
||||||
branch = main
|
branch = main
|
||||||
[submodule "pack/general/start/neotest"]
|
[submodule "pack/general/start/neotest"]
|
||||||
path = pack/general/start/neotest
|
path = pack/general/opt/neotest
|
||||||
url = https://github.com/nvim-neotest/neotest
|
url = https://github.com/nvim-neotest/neotest
|
||||||
branch = master
|
branch = master
|
||||||
[submodule "pack/general/start/neotest-rust"]
|
[submodule "pack/general/start/neotest-rust"]
|
||||||
path = pack/general/start/neotest-rust
|
path = pack/general/opt/neotest-rust
|
||||||
url = https://github.com/rouge8/neotest-rust
|
url = https://github.com/rouge8/neotest-rust
|
||||||
branch = main
|
branch = main
|
||||||
[submodule "pack/general/start/lsp_lines.nvim"]
|
[submodule "pack/general/start/lsp_lines.nvim"]
|
||||||
path = pack/general/start/lsp_lines.nvim
|
path = pack/general/opt/lsp_lines.nvim
|
||||||
url = https://git.sr.ht/~whynothugo/lsp_lines.nvim
|
url = https://git.sr.ht/~whynothugo/lsp_lines.nvim
|
||||||
[submodule "pack/general/opt/crates.nvim"]
|
[submodule "pack/general/opt/crates.nvim"]
|
||||||
path = pack/general/opt/crates.nvim
|
path = pack/general/opt/crates.nvim
|
||||||
|
|
@ -132,3 +132,6 @@
|
||||||
path = pack/general/start/nvim-spider
|
path = pack/general/start/nvim-spider
|
||||||
url = https://github.com/chrisgrieser/nvim-spider
|
url = https://github.com/chrisgrieser/nvim-spider
|
||||||
branch = main
|
branch = main
|
||||||
|
[submodule "pack/general/opt/lsp_lines.nvim"]
|
||||||
|
path = pack/general/opt/lsp_lines.nvim
|
||||||
|
url = https://git.sr.ht/~whynothugo/lsp_lines.nvim
|
||||||
|
|
|
||||||
146
init.lua
146
init.lua
|
|
@ -1,47 +1,41 @@
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
---- Aliases ----
|
|
||||||
local cmd = vim.cmd
|
|
||||||
local g = vim.g
|
|
||||||
local opt = vim.opt
|
|
||||||
local opt_local = vim.opt_local
|
|
||||||
|
|
||||||
---- General Config ----
|
---- General Config ----
|
||||||
opt.mouse = "a"
|
vim.opt.mouse = "a"
|
||||||
opt.tabstop = 2
|
vim.opt.tabstop = 2
|
||||||
opt.shiftwidth = 2
|
vim.opt.shiftwidth = 2
|
||||||
opt.number = true
|
vim.opt.number = true
|
||||||
opt.breakindent = true
|
vim.opt.breakindent = true
|
||||||
opt.showmatch = true
|
vim.opt.showmatch = true
|
||||||
opt.ignorecase = true
|
vim.opt.ignorecase = true
|
||||||
opt.smartcase = true
|
vim.opt.smartcase = true
|
||||||
opt.joinspaces = false
|
vim.opt.joinspaces = false
|
||||||
opt.showmode = false
|
vim.opt.showmode = false
|
||||||
opt.hidden = true
|
vim.opt.hidden = true
|
||||||
opt.backup = false
|
vim.opt.backup = false
|
||||||
opt.writebackup = false
|
vim.opt.writebackup = false
|
||||||
opt.swapfile = false
|
vim.opt.swapfile = false
|
||||||
opt.shortmess:append({ I = true })
|
vim.opt.shortmess:append({ I = true })
|
||||||
-- whichwrap -- left/right keys can traverse up/down
|
-- whichwrap -- left/right keys can traverse up/down
|
||||||
opt.whichwrap:append("<,>,[,]")
|
vim.opt.whichwrap:append("<,>,[,]")
|
||||||
opt.cmdheight = 2
|
vim.opt.cmdheight = 2
|
||||||
opt.showcmd = true
|
vim.opt.showcmd = true
|
||||||
opt.splitright = true
|
vim.opt.splitright = true
|
||||||
opt.splitbelow = true
|
vim.opt.splitbelow = true
|
||||||
g.mapleader = " "
|
vim.g.mapleader = " "
|
||||||
|
|
||||||
---- Terminal ----
|
---- Terminal ----
|
||||||
vim.api.nvim_create_autocmd({ "TermOpen" }, {
|
vim.api.nvim_create_autocmd({ "TermOpen" }, {
|
||||||
callback = function()
|
callback = function()
|
||||||
opt_local.number = false
|
vim.opt_local.number = false
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
---- Theming ----
|
---- Theming ----
|
||||||
opt.termguicolors = true
|
vim.opt.termguicolors = true
|
||||||
opt.background = "dark"
|
vim.opt.background = "dark"
|
||||||
g.gruvbox_italic = true
|
vim.g.gruvbox_italic = true
|
||||||
cmd.colorscheme("gruvbox")
|
vim.cmd.colorscheme("gruvbox")
|
||||||
opt.listchars = {
|
vim.opt.listchars = {
|
||||||
eol = "↲",
|
eol = "↲",
|
||||||
tab = "▶▹",
|
tab = "▶▹",
|
||||||
nbsp = "␣",
|
nbsp = "␣",
|
||||||
|
|
@ -188,17 +182,17 @@ vim.filetype.add({ extension = { kdl = "kdl" } })
|
||||||
vim.api.nvim_create_autocmd({ "FileType" }, {
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
||||||
pattern = "markdown",
|
pattern = "markdown",
|
||||||
callback = function()
|
callback = function()
|
||||||
opt_local.textwidth = 85
|
vim.opt_local.textwidth = 85
|
||||||
opt_local.spell = true
|
vim.opt_local.spell = true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
-- YAML --
|
-- YAML --
|
||||||
vim.api.nvim_create_autocmd({ "FileType" }, {
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
||||||
pattern = "yaml",
|
pattern = "yaml",
|
||||||
callback = function()
|
callback = function()
|
||||||
opt_local.softtabstop = 2
|
vim.opt_local.softtabstop = 2
|
||||||
opt_local.expandtab = true
|
vim.opt_local.expandtab = true
|
||||||
opt_local.foldmethod = "indent"
|
vim.opt_local.foldmethod = "indent"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -271,11 +265,37 @@ cmp.setup({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
---- LSP ----
|
---- LSP ----
|
||||||
local lsp = require("lspconfig")
|
vim.g.lsp_loaded = false
|
||||||
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
||||||
|
pattern = {
|
||||||
|
"c",
|
||||||
|
"cpp",
|
||||||
|
"dot",
|
||||||
|
"go",
|
||||||
|
"javascript",
|
||||||
|
"json",
|
||||||
|
"latex",
|
||||||
|
"lua",
|
||||||
|
"markdown",
|
||||||
|
"python",
|
||||||
|
"rust",
|
||||||
|
"terraform",
|
||||||
|
"tex",
|
||||||
|
"toml",
|
||||||
|
"typescript",
|
||||||
|
},
|
||||||
|
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")
|
||||||
|
|
||||||
-- Use an on_attach function to only map the following keys
|
local lsp = require("lspconfig")
|
||||||
-- after the language server attaches to the current buffer
|
-- Use an on_attach function to only map the following keys
|
||||||
local on_lsp_attach = function(_client, _bufnr)
|
-- after the language server attaches to the current buffer
|
||||||
|
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)
|
||||||
|
|
@ -292,11 +312,11 @@ local on_lsp_attach = function(_client, _bufnr)
|
||||||
vim.keymap.set("n", "<F3>", function()
|
vim.keymap.set("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 = {},
|
||||||
dotls = {},
|
dotls = {},
|
||||||
eslint = {},
|
eslint = {},
|
||||||
|
|
@ -326,11 +346,11 @@ local servers = {
|
||||||
texlab = {},
|
texlab = {},
|
||||||
tflint = {},
|
tflint = {},
|
||||||
tsserver = {},
|
tsserver = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||||
lsp.util.default_config = vim.tbl_deep_extend("force", lsp.util.default_config, { capabilities = 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
|
for server, add_to_config in pairs(servers) do
|
||||||
local config = {
|
local config = {
|
||||||
on_attach = on_lsp_attach,
|
on_attach = on_lsp_attach,
|
||||||
flags = {
|
flags = {
|
||||||
|
|
@ -341,7 +361,16 @@ for server, add_to_config in pairs(servers) do
|
||||||
config[k] = v
|
config[k] = v
|
||||||
end
|
end
|
||||||
lsp[server].setup(config)
|
lsp[server].setup(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---- lsp_lines
|
||||||
|
require("lsp_lines").setup()
|
||||||
|
-- Disable virtual_text since it's redundant due to lsp_lines.
|
||||||
|
vim.diagnostic.config({
|
||||||
|
virtual_text = false,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-- Auto format on save
|
-- Auto format on save
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
|
|
@ -356,7 +385,7 @@ vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
if lsp_format then
|
if lsp_format then
|
||||||
vim.lsp.buf.format({ async = false })
|
vim.lsp.buf.format({ async = false })
|
||||||
else
|
else
|
||||||
cmd("Format")
|
vim.cmd("Format")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -485,9 +514,9 @@ require("gitsigns").setup({
|
||||||
---- Comment.nvim
|
---- Comment.nvim
|
||||||
require("Comment").setup()
|
require("Comment").setup()
|
||||||
---- vim-markdown
|
---- vim-markdown
|
||||||
g.vim_markdown_no_default_key_mappings = 1
|
vim.g.vim_markdown_no_default_key_mappings = 1
|
||||||
g.vim_markdown_folding_disabled = 1
|
vim.g.vim_markdown_folding_disabled = 1
|
||||||
g.vim_markdown_toml_frontmatter = 1
|
vim.g.vim_markdown_toml_frontmatter = 1
|
||||||
---- Telescope
|
---- Telescope
|
||||||
local telescope = require("telescope")
|
local telescope = require("telescope")
|
||||||
telescope.setup({
|
telescope.setup({
|
||||||
|
|
@ -603,13 +632,6 @@ vim.api.nvim_create_autocmd({ "FileType" }, {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
---- lsp_lines
|
|
||||||
require("lsp_lines").setup()
|
|
||||||
-- Disable virtual_text since it's redundant due to lsp_lines.
|
|
||||||
vim.diagnostic.config({
|
|
||||||
virtual_text = false,
|
|
||||||
})
|
|
||||||
|
|
||||||
---- nvim-surround
|
---- nvim-surround
|
||||||
require("nvim-surround").setup()
|
require("nvim-surround").setup()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue