1
0
Fork 0

refactor and some lazy loading

This commit is contained in:
Felipe 2023-09-21 10:20:40 -03:00
parent 854f067991
commit 103961e892
Signed by: pitbuster
SSH key fingerprint: SHA256:HDYu2Pm4/TmSX8GBwV49UvFWr1Ljg8XlHxKeCpjJpOk
7 changed files with 155 additions and 120 deletions

9
.gitmodules vendored
View file

@ -62,13 +62,13 @@
path = pack/general/start/git-blame.nvim
url = https://github.com/f-person/git-blame.nvim
[submodule "nvim-dap"]
path = pack/general/start/nvim-dap
path = pack/general/opt/nvim-dap
url = https://github.com/mfussenegger/nvim-dap
[submodule "pack/general/start/nvim-dap-go"]
path = pack/general/start/nvim-dap-go
path = pack/general/opt/nvim-dap-go
url = https://github.com/leoluz/nvim-dap-go
[submodule "pack/general/start/nvim-dap-ui"]
path = pack/general/start/nvim-dap-ui
path = pack/general/opt/nvim-dap-ui
url = https://github.com/rcarriga/nvim-dap-ui
[submodule "pack/general/start/vim-helm"]
path = pack/general/start/vim-helm
@ -109,3 +109,6 @@
[submodule "pack/general/start/lsp_lines.nvim"]
path = pack/general/start/lsp_lines.nvim
url = https://git.sr.ht/~whynothugo/lsp_lines.nvim
[submodule "pack/general/opt/crates.nvim"]
path = pack/general/opt/crates.nvim
url = https://github.com/Saecki/crates.nvim

182
init.lua
View file

@ -1,3 +1,4 @@
vim.loader.enable()
---- Aliases ----
local cmd = vim.cmd
local g = vim.g
@ -115,8 +116,7 @@ vim.keymap.set("v", "<", "<gv")
vim.keymap.set("n", "<C-L>", ":nohlsearch<CR>")
---- Treesitter ----
local ts = require("nvim-treesitter.configs")
ts.setup({
require("nvim-treesitter.configs").setup({
auto_install = true,
sync_install = false,
ignore_install = {},
@ -203,8 +203,7 @@ vim.api.nvim_create_autocmd({ "FileType" }, {
})
---- formatter.nvim ----
local formatter = require("formatter")
formatter.setup({
require("formatter").setup({
filetype = {
lua = {
require("formatter.filetypes.lua").stylua,
@ -220,6 +219,57 @@ formatter.setup({
}
})
---- LuaSnip
local luasnip = require("luasnip")
require("luasnip.loaders.from_lua").lazy_load()
luasnip.config.set_config({
store_selection_keys = "<c-s>",
})
vim.keymap.set({ "i", "s" }, "<Tab>", function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes("<Tab>", true, false, true),
"n", -- noremap to avoid infinite recursion
true
)
end
end, { silent = true })
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
if luasnip.jumpable(-1) then
luasnip.jump(-1)
end
end, { silent = true })
---- completion-nvim
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "buffer" },
{ name = "crates" },
}),
})
---- LSP ----
local lsp = require("lspconfig")
@ -277,8 +327,21 @@ local servers = {
tflint = {},
tsserver = {},
}
-- Setup loop moved to the cmp section, since calling setup multiple times
-- overrides the previous calls.
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
lsp[server].setup(config)
end
-- Auto format on save
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
@ -298,7 +361,6 @@ vim.api.nvim_create_autocmd({ "BufWritePre" }, {
end,
})
---- Plugins ----
---- nvim-lint ----
local lint = require("lint")
local clippy_format = "%E%f:%l:%c: %\\d%#:%\\d%# %.%\\{-}"
@ -385,73 +447,7 @@ for ft, ft_linters in pairs(linters) do
})
end
end
---- LuaSnip
local luasnip = require("luasnip")
require("luasnip.loaders.from_lua").lazy_load()
luasnip.config.set_config({
store_selection_keys = "<c-s>",
})
vim.keymap.set({ "i", "s" }, "<Tab>", function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes("<Tab>", true, false, true),
"n", -- noremap to avoid infinite recursion
true
)
end
end, { silent = true })
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
if luasnip.jumpable(-1) then
luasnip.jump(-1)
end
end, { silent = true })
---- completion-nvim
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "buffer" },
{ name = "crates" },
}),
})
-- Setup lspconfig.
local capabilities = vim.lsp.protocol.make_client_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
lsp[server].setup(config)
end
---- gitblame
local gitblame = require("gitblame")
gitblame.setup({
@ -515,10 +511,19 @@ vim.keymap.set("n", "<Leader>cg", builtin.grep_string)
vim.keymap.set("n", "<Leader>:", builtin.commands)
vim.keymap.set("n", "<Leader>s", telescope.extensions.luasnip.luasnip)
---- nvim-dap
vim.g.dap_loaded = false
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = { "go" },
callback = function()
vim.g.dap_loaded = true
vim.cmd("packadd nvim-dap")
vim.cmd("packadd nvim-dap-ui")
vim.cmd("packadd nvim-go")
local dap = require("dap")
vim.fn.sign_define("DapBreakpoint", { text = "🟥", texthl = "", linehl = "", numhl = "" })
vim.fn.sign_define("DapStopped", { text = "▶️", texthl = "", linehl = "", numhl = "" })
-- Set keymaps to control the debugge
-- Set keymaps to control the debugger
vim.keymap.set("n", "<leader>dc", dap.continue)
vim.keymap.set("n", "<leader>do", dap.step_over)
vim.keymap.set("n", "<leader>di", dap.step_into)
@ -539,6 +544,8 @@ dap.listeners.before.event_exited["dapui_config"] = function()
end
-- nvim-dap-go
require("dap-go").setup()
end,
})
---- web-devicons
require("nvim-web-devicons").setup()
@ -549,6 +556,16 @@ vim.keymap.set('n', '<leader>yy', '<leader>y_', { remap = true })
vim.keymap.set('v', '<leader>y', require('osc52').copy_visual)
---- crates
vim.g.crates_loaded = false
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "Cargo.toml" },
callback = function()
if vim.g.crates_loaded then
return
end
vim.g.crates_loaded = true
vim.cmd("packadd crates.nvim")
local crates = require('crates')
crates.setup()
vim.keymap.set('n', '<leader>cv', crates.show_versions_popup)
@ -558,8 +575,21 @@ vim.keymap.set('n', '<leader>cu', crates.update_crate)
vim.keymap.set('v', '<leader>cu', crates.update_crates)
vim.keymap.set('n', '<leader>ca', crates.update_all_crates)
vim.keymap.set('n', '<leader>cD', crates.open_documentation)
end,
})
---- neotest
vim.g.neotest_loaded = false
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = { "rust" },
callback = function()
if vim.g.neotest_loaded then
return
end
vim.g.neotest_loaded = true
vim.cmd("packadd neotest")
vim.cmd("packadd neotest-rust")
local neotest = require("neotest")
neotest.setup({
adapters = {
@ -570,10 +600,12 @@ vim.keymap.set('n', '<leader>tr', function() neotest.run.run() end)
vim.keymap.set('n', '<leader>tf', function() neotest.run.run(vim.fn.expand("%")) end)
vim.keymap.set('n', '<leader>ts', function() neotest.run.stop() end)
vim.keymap.set('n', '<leader>tt', function() neotest.summary.toggle() 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,
virtual_lines = { only_current_line = true },
})

@ -0,0 +1 @@
Subproject commit db629b5cfb2aa8de9e44efb795657297ee95ca91

@ -1 +0,0 @@
Subproject commit d5caf28aba49e81ac4099426231f3cf3c151013a