aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/nvim
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-07-07 21:17:31 -0500
committerToby Vincent <tobyv13@gmail.com>2022-07-07 21:17:31 -0500
commit1cad79be2fc264ad1a53c811ad570d8824ba5cad (patch)
treec5055f709a50ec7a8af0d39325bd43c4d7f21b6d /nvim
parent1ca41ab99d3df956a901834b8765b9d8ea7fd863 (diff)
feat(nvim): improve completion and snippet engine
Diffstat (limited to 'nvim')
-rw-r--r--nvim/.config/nvim/lua/tobyvin/lsp/symbol.lua2
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins.lua66
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/cmp-git.lua13
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/cmp-npm.lua13
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua189
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/crates.lua17
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/diffview.lua14
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/git-blame.lua3
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua16
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/luasnip.lua7
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/telescope.lua1
11 files changed, 266 insertions, 75 deletions
diff --git a/nvim/.config/nvim/lua/tobyvin/lsp/symbol.lua b/nvim/.config/nvim/lua/tobyvin/lsp/symbol.lua
index 6eabea7..00384ac 100644
--- a/nvim/.config/nvim/lua/tobyvin/lsp/symbol.lua
+++ b/nvim/.config/nvim/lua/tobyvin/lsp/symbol.lua
@@ -1,7 +1,7 @@
local M = {}
M.on_attach = function(client, bufnr)
- if client.server_capabilities.documentSymbolProvider then
+ if client.name ~= "cssls" and client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, bufnr)
end
end
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins.lua b/nvim/.config/nvim/lua/tobyvin/plugins.lua
index ee49319..2002f1e 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins.lua
@@ -55,7 +55,9 @@ M.plugins = function(use)
use({
"jose-elias-alvarez/null-ls.nvim",
- requires = "nvim-lua/plenary.nvim",
+ requires = {
+ "nvim-lua/plenary.nvim",
+ },
config = [[require("tobyvin.plugins.null-ls").setup()]],
})
@@ -69,6 +71,7 @@ M.plugins = function(use)
use({
"simrat39/rust-tools.nvim",
+ after = "nvim-lspconfig",
branch = "modularize_and_inlay_rewrite",
requires = {
"neovim/nvim-lspconfig",
@@ -85,25 +88,52 @@ M.plugins = function(use)
config = [[require("grammar-guard").init()]],
})
- -- use({
- -- "saecki/crates.nvim",
- -- requires = { "nvim-lua/plenary.nvim" },
- -- config = [[require("crates").setup()]],
- -- })
-
use({
"hrsh7th/nvim-cmp",
requires = {
- "ray-x/lsp_signature.nvim",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua",
- "hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
+ "hrsh7th/cmp-buffer",
+ "hrsh7th/cmp-cmdline",
+ "dmitmel/cmp-cmdline-history",
"hrsh7th/cmp-calc",
- "saadparwaiz1/cmp_luasnip",
+ "ray-x/lsp_signature.nvim",
"hrsh7th/cmp-nvim-lsp-signature-help",
+ "rcarriga/cmp-dap",
+ "petertriho/cmp-git",
+ "Dosx001/cmp-commit",
+ "davidsierradz/cmp-conventionalcommits",
+ "saadparwaiz1/cmp_luasnip",
+ "saecki/crates.nvim",
+ "kdheepak/cmp-latex-symbols",
+ },
+ config = [[require("tobyvin.plugins.cmp").setup()]],
+ })
+
+ use({
+ "petertriho/cmp-git",
+ requires = "nvim-lua/plenary.nvim",
+ config = [[require("tobyvin.plugins.cmp-git").setup()]],
+ })
+
+ use({
+ "David-Kunz/cmp-npm",
+ event = { "BufRead package.json" },
+ requires = {
+ "nvim-lua/plenary.nvim",
},
- config = [[require("tobyvin.plugins.cmp")]],
+ config = [[require("tobyvin.plugins.cmp-npm").setup()]],
+ })
+
+ use({
+ "saecki/crates.nvim",
+ event = { "BufRead Cargo.toml" },
+ requires = {
+ "nvim-lua/plenary.nvim",
+ "jose-elias-alvarez/null-ls.nvim",
+ },
+ config = [[require("tobyvin.plugins.crates").setup()]],
})
use({ "onsails/lspkind-nvim", config = [[require("tobyvin.plugins.lspkind").setup()]] })
@@ -142,8 +172,11 @@ M.plugins = function(use)
use({
"L3MON4D3/LuaSnip",
- requires = "rafamadriz/friendly-snippets",
- config = [[require("tobyvin.plugins.luasnip")]],
+ requires = {
+ "rafamadriz/friendly-snippets",
+ "molleweide/LuaSnip-snippets.nvim",
+ },
+ config = [[require("tobyvin.plugins.luasnip").setup()]],
})
use({
@@ -208,7 +241,10 @@ M.plugins = function(use)
use({
"sindrets/diffview.nvim",
- requires = "nvim-lua/plenary.nvim",
+ requires = {
+ "nvim-lua/plenary.nvim",
+ "kyazdani42/nvim-web-devicons",
+ },
config = [[require("tobyvin.plugins.diffview").setup()]],
})
@@ -318,7 +354,7 @@ M.setup = function()
group = augroup_packer,
pattern = "plugins.lua",
callback = function()
- utils.reload("tobyvin.plugins")
+ -- utils.reload("tobyvin.plugins")
packer.sync()
end,
desc = "Reload packer config on write",
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/cmp-git.lua b/nvim/.config/nvim/lua/tobyvin/plugins/cmp-git.lua
new file mode 100644
index 0000000..2877ef1
--- /dev/null
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/cmp-git.lua
@@ -0,0 +1,13 @@
+local M = {}
+
+M.setup = function()
+ local status_ok, cmp_git = pcall(require, "cmp_git")
+ if not status_ok then
+ vim.notify("Failed to load module 'cmp_git'", "error")
+ return
+ end
+
+ cmp_git.setup()
+end
+
+return M
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/cmp-npm.lua b/nvim/.config/nvim/lua/tobyvin/plugins/cmp-npm.lua
new file mode 100644
index 0000000..d76dadc
--- /dev/null
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/cmp-npm.lua
@@ -0,0 +1,13 @@
+local M = {}
+
+M.setup = function()
+ local status_ok, cmp_npm = pcall(require, "cmp-npm")
+ if not status_ok then
+ vim.notify("Failed to load module 'cmp-npm'", "error")
+ return
+ end
+
+ cmp_npm.setup()
+end
+
+return M
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua b/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua
index 5c353eb..8aad3fa 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua
@@ -1,56 +1,151 @@
-local status_ok, cmp = pcall(require, "cmp")
-if not status_ok then
- return
+local M = {}
+
+M.enabled = function()
+ local ctx = require("cmp.config.context")
+ local enabled = require("cmp.config.default")().enabled() or require("cmp_dap").is_dap_buffer()
+ if vim.api.nvim_get_mode().mode ~= "c" then
+ enabled = enabled and not ctx.in_treesitter_capture("comment")
+ enabled = enabled and not ctx.in_syntax_group("Comment")
+ end
+ return enabled
end
-local enabled = function()
- local context = require("cmp.config.context")
+M.snippets = function(args)
+ require("luasnip").lsp_expand(args.body)
+end
- if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
- -- disable completion in prompts
- return false
- elseif vim.api.nvim_get_mode().mode == "c" then
- -- keep command mode completion enabled when cursor is in a comment
- return true
+M.has_words_before = function()
+ local line, col = unpack(vim.api.nvim_win_get_cursor(0))
+ return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
+end
+
+M.complete = function(fallback)
+ local cmp = require("cmp")
+ if cmp.visible() then
+ cmp.confirm({ behavior = cmp.ConfirmBehavior.insert, select = true })
+ elseif M.has_words_before() then
+ cmp.complete()
else
- -- disable completion in comments
- return not (context.in_treesitter_capture("comment") == true or context.in_syntax_group("Comment"))
+ fallback()
end
end
-local get_snippets = function(args)
- require("luasnip").lsp_expand(args.body)
+M.next_item = function(fallback)
+ local cmp = require("cmp")
+ local luasnip = require("luasnip")
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ elseif M.has_words_before() then
+ cmp.complete()
+ else
+ fallback()
+ end
+end
+
+M.prev_item = function(fallback)
+ local cmp = require("cmp")
+ local luasnip = require("luasnip")
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+end
+
+M.close = function(fallback)
+ local cmp = require("cmp")
+ cmp.close()
+ fallback()
+end
+
+M.setup = function()
+ local status_ok, cmp = pcall(require, "cmp")
+ if not status_ok then
+ vim.notify("Failed to load module 'cmd'", "error")
+ return
+ end
+
+ cmp.setup({
+ enabled = M.enabled,
+ snippet = {
+ expand = M.snippets,
+ },
+ mapping = {
+ ["<Tab>"] = cmp.mapping(M.next_item),
+ ["<S-Tab>"] = cmp.mapping(M.prev_item),
+ ["<C-d>"] = cmp.mapping.scroll_docs(-4),
+ ["<C-u>"] = cmp.mapping.scroll_docs(4),
+ ["<C-Space>"] = cmp.mapping(M.complete),
+ ["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.insert }),
+ ["<C-c>"] = cmp.mapping(M.close),
+ },
+ ghost_text = true,
+ sources = {
+ { name = "nvim_lsp", group_index = 1 },
+ { name = "nvim_lua", group_index = 1 },
+ { name = "path", group_index = 1 },
+ { name = "luasnip", group_index = 1 },
+ { name = "dap", group_index = 1 },
+ { name = "buffer", keyword_length = 3, group_index = 2 },
+ },
+ })
+
+ cmp.setup.filetype({ "tex", "bib" }, {
+ sources = {
+ { name = "latex_symbols" },
+ },
+ })
+
+ cmp.setup.filetype("gitcommit", {
+ sources = {
+ { name = "git" },
+ { name = "commit" },
+ { name = "conventionalcommits" },
+ },
+ })
+
+ cmp.setup.filetype("json", {
+ sources = {
+ { name = "npm" },
+ },
+ })
+
+ cmp.setup.filetype("toml", {
+ sources = {
+ { name = "crates" },
+ },
+ })
+
+ cmp.setup.cmdline(":", {
+ sources = {
+ { name = "cmdline_history", max_item_count = 10 },
+ { name = "cmdline", max_item_count = 10 },
+ },
+ })
+
+ cmp.setup.cmdline("/", {
+ sources = {
+ { name = "buffer", max_item_count = 10 },
+ { name = "cmdline_history", max_item_count = 10 },
+ },
+ })
+
+ cmp.setup.cmdline("?", {
+ sources = {
+ { name = "buffer", max_item_count = 10 },
+ { name = "cmdline_history", max_item_count = 10 },
+ },
+ })
+
+ cmp.setup.cmdline("@", {
+ sources = {
+ { name = "cmdline_history", max_item_count = 10 },
+ },
+ })
end
-cmp.setup({
- enabled = enabled,
- completion = {
- completeopt = "menu,menuone,noinsert",
- },
- snippet = {
- expand = get_snippets,
- },
- -- TODO move mappings to which-key
- mapping = {
- ["<C-n>"] = cmp.mapping.select_next_item(),
- ["<C-p>"] = cmp.mapping.select_prev_item(),
- ["<Tab>"] = cmp.mapping.select_next_item(),
- ["<S-Tab>"] = cmp.mapping.select_prev_item(),
- ["<C-d>"] = cmp.mapping.scroll_docs(-4),
- ["<C-u>"] = cmp.mapping.scroll_docs(4),
- ["<C-Space>"] = cmp.mapping.complete(),
- ["<C-e>"] = cmp.mapping.close(),
- ["<CR>"] = cmp.mapping.confirm({
- behavior = cmp.ConfirmBehavior.Replace,
- select = true,
- }),
- },
- sources = {
- { name = "nvim_lsp" },
- { name = "nvim_lua" },
- { name = "path" },
- { name = "luasnip" },
- { name = "buffer", keyword_length = 1 },
- { name = "crates" },
- },
-})
+return M
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/crates.lua b/nvim/.config/nvim/lua/tobyvin/plugins/crates.lua
new file mode 100644
index 0000000..46f2077
--- /dev/null
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/crates.lua
@@ -0,0 +1,17 @@
+local M = {}
+
+M.setup = function()
+ local status_ok, crates = pcall(require, "crates")
+ if not status_ok then
+ vim.notify("Failed to load module 'crates'", "error")
+ return
+ end
+
+ crates.setup({
+ null_ls = {
+ enabled = true,
+ },
+ })
+end
+
+return M
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/diffview.lua b/nvim/.config/nvim/lua/tobyvin/plugins/diffview.lua
index 394d8eb..055941c 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins/diffview.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/diffview.lua
@@ -1,7 +1,17 @@
+local utils = require("tobyvin.utils")
local M = {}
-M.setup = function ()
- require("diffview").setup()
+M.setup = function()
+ local status_ok, diffview = pcall(require, "diffview")
+ if not status_ok then
+ vim.notify("Failed to load module 'diffview'", "error")
+ return
+ end
+
+ diffview.setup()
+
+ local nmap = utils.create_map_group("n", "<leader>g", "Git")
+ nmap("d", diffview.open, { desc = "Diffview" })
end
return M
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/git-blame.lua b/nvim/.config/nvim/lua/tobyvin/plugins/git-blame.lua
deleted file mode 100644
index 0e3a7ea..0000000
--- a/nvim/.config/nvim/lua/tobyvin/plugins/git-blame.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-vim.g.gitblame_enabled = 0
-vim.g.gitblame_message_template = "<summary> • <date> • <author>"
-vim.g.gitblame_highlight_group = "LineNr"
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua b/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua
index 30b1666..9d1cfcf 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua
@@ -13,6 +13,12 @@ M.setup = function()
lspconfig.tsserver.setup(lsp.config())
+ lspconfig.cssls.setup(lsp.config())
+
+ lspconfig.cssmodules_ls.setup(lsp.config())
+
+ lspconfig.stylelint_lsp.setup(lsp.config())
+
lspconfig.ccls.setup(lsp.config())
lspconfig.gopls.setup(lsp.config({
@@ -34,7 +40,15 @@ M.setup = function()
settings = {
texlab = {
build = {
- args = {"-pdf", "-interaction=nonstopmode", "-synctex=1", "-auxdir=../aux", "-outdir=../", "-emulate-aux-dir", "%f"},
+ args = {
+ "-pdf",
+ "-interaction=nonstopmode",
+ "-synctex=1",
+ "-auxdir=../aux",
+ "-outdir=../",
+ "-emulate-aux-dir",
+ "%f",
+ },
onSave = true,
},
chktex = {
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/luasnip.lua b/nvim/.config/nvim/lua/tobyvin/plugins/luasnip.lua
index b1dd30e..7fb80d5 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins/luasnip.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/luasnip.lua
@@ -11,12 +11,7 @@ M.setup = function()
updateevents = "TextChanged,TextChangedI",
})
- luasnip.snippets = { all = {}, html = {} }
-
- luasnip.snippets.javascript = luasnip.snippets.html
- luasnip.snippets.javascriptreact = luasnip.snippets.html
- luasnip.snippets.typescriptreact = luasnip.snippets.html
- require("luasnip.loaders.from_vscode").load({ include = { "html" } })
+ luasnip.snippets = require("luasnip_snippets").load_snippets()
require("luasnip.loaders.from_vscode").lazy_load()
end
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/telescope.lua b/nvim/.config/nvim/lua/tobyvin/plugins/telescope.lua
index 665ecbd..7c88372 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins/telescope.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/telescope.lua
@@ -74,6 +74,7 @@ M.setup = function()
local nmap_find = require("tobyvin.utils").create_map_group("n", "<leader>f", "Find")
nmap_find("b", builtins.buffers, { desc = "Buffers" })
+ nmap_find("c", builtins.command_history, { desc = "Command History" })
nmap_find("C", builtins.commands, { desc = "Commands" })
nmap_find("f", builtins.find_files, { desc = "Find files" })
nmap_find("g", builtins.live_grep, { desc = "Find Text" })