Skip to content

Commit 80b7420

Browse files
committed
feat: make treesitter and blink work
1 parent 1d7d837 commit 80b7420

7 files changed

Lines changed: 143 additions & 170 deletions

File tree

modules/common/nvim/default.nix

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ let
5656
nixd
5757
nixfmt # nix
5858
lua-language-server
59+
tree-sitter
5960
stylua # lua
6061
vscode-langservers-extracted # html, css, json
6162
bash-language-server # bash
@@ -131,16 +132,9 @@ let
131132
garbage-day-nvim # stop inactive lsp clients
132133
];
133134
cmp = [
134-
nvim-cmp
135-
cmp-buffer
136-
cmp-path
137-
cmp-cmdline
138-
cmp-nvim-lsp
139-
cmp-nvim-lsp-document-symbol
140-
141-
cmp-git
142-
copilot-cmp
143-
minuet-ai-nvim
135+
blink-cmp
136+
blink-cmp-copilot
137+
blink-cmp-git
144138
];
145139
core = [
146140
plenary-nvim

modules/common/nvim/lua/chrishrb/lsp/handlers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ end
138138

139139
local capabilities = vim.lsp.protocol.make_client_capabilities()
140140

141-
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
141+
local status_ok, blink = pcall(require, "blink.cmp")
142142
if not status_ok then
143143
return
144144
end
145145

146-
M.capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
146+
M.capabilities = blink.get_lsp_capabilities(capabilities)
147147

148148
return M

modules/common/nvim/lua/chrishrb/plugins/config/autopairs.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-- Setup nvim-cmp.
21
local npairs = require("nvim-autopairs")
32

43
npairs.setup({
@@ -22,11 +21,6 @@ npairs.setup({
2221
},
2322
})
2423

25-
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
26-
local cmp = require("cmp")
27-
28-
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } }))
29-
3024
-- add rule for codecompanion filetype
3125
local Rule = require("nvim-autopairs.rule")
3226

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
local icons = require("chrishrb.config.icons")
2+
3+
local has_copilot = pcall(require, "blink-cmp-copilot")
4+
5+
local sources_default = { "lsp", "buffer", "path", "git" }
6+
if has_copilot then
7+
table.insert(sources_default, 1, "copilot")
8+
end
9+
10+
local providers = {
11+
lsp = {
12+
name = "LSP",
13+
module = "blink.cmp.sources.lsp",
14+
},
15+
buffer = {
16+
name = "Buffer",
17+
module = "blink.cmp.sources.buffer",
18+
},
19+
path = {
20+
name = "Path",
21+
module = "blink.cmp.sources.path",
22+
},
23+
git = {
24+
name = "Git",
25+
module = "blink-cmp-git",
26+
},
27+
}
28+
29+
if has_copilot then
30+
providers.copilot = {
31+
name = "Copilot",
32+
module = "blink-cmp-copilot",
33+
score_offset = 100,
34+
async = true,
35+
}
36+
end
37+
38+
require("blink.cmp").setup({
39+
keymap = {
40+
["<C-k>"] = { "select_prev", "fallback" },
41+
["<C-j>"] = { "select_next", "fallback" },
42+
["<C-b>"] = { "scroll_documentation_up", "fallback" },
43+
["<C-f>"] = { "scroll_documentation_down", "fallback" },
44+
["<C-Space>"] = { "show" },
45+
["<C-e>"] = { "cancel", "fallback" },
46+
["<CR>"] = { "accept", "fallback" },
47+
["<Tab>"] = { "select_next", "fallback" },
48+
["<S-Tab>"] = { "select_prev", "fallback" },
49+
},
50+
cmdline = {
51+
keymap = {
52+
preset = "inherit",
53+
54+
["<Tab>"] = { "show_and_insert_or_accept_single", "select_next" },
55+
["<S-Tab>"] = { "show_and_insert_or_accept_single", "select_prev" },
56+
},
57+
completion = { menu = { auto_show = false } },
58+
},
59+
completion = {
60+
menu = {
61+
draw = {
62+
columns = { { "kind_icon" }, { "label", gap = 1 }, { "source_name" } },
63+
components = {
64+
kind_icon = {
65+
text = function(ctx)
66+
return (icons.kind[ctx.kind] or icons.kind.Fallback) .. " "
67+
end,
68+
},
69+
source_name = {
70+
text = function(ctx)
71+
local labels = {
72+
LSP = "[LSP]",
73+
Copilot = "[Copilot]",
74+
AI = "[AI]",
75+
Buffer = "[Buffer]",
76+
Path = "[Path]",
77+
Git = "[Git]",
78+
}
79+
return labels[ctx.source_name] or ("[" .. ctx.source_name .. "]")
80+
end,
81+
},
82+
},
83+
},
84+
},
85+
documentation = {
86+
auto_show = true,
87+
auto_show_delay_ms = 0,
88+
window = {
89+
border = { "", "", "", "", "", "", "", "" },
90+
},
91+
},
92+
},
93+
sources = {
94+
default = sources_default,
95+
providers = providers,
96+
},
97+
})

modules/common/nvim/lua/chrishrb/plugins/config/cmp.lua

Lines changed: 0 additions & 128 deletions
This file was deleted.

modules/common/nvim/lua/chrishrb/plugins/config/treesitter.lua

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1-
local indent_disabled = { "yaml", "python", "java", "terraform" }
1+
---@param buf integer
2+
---@param language string
3+
local function treesitter_try_attach(buf, language)
4+
-- check if parser exists and load it
5+
if not vim.treesitter.language.add(language) then
6+
return false
7+
end
8+
-- enables syntax highlighting and other treesitter features
9+
vim.treesitter.start(buf, language)
210

11+
-- enables treesitter based folds
12+
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
13+
vim.wo.foldmethod = "expr"
14+
-- ensure folds are open to begin with
15+
vim.o.foldlevel = 99
16+
17+
-- enables treesitter based indentation
18+
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
19+
20+
return true
21+
end
22+
23+
local installable_parsers = require("nvim-treesitter").get_available()
324
vim.api.nvim_create_autocmd("FileType", {
425
callback = function(args)
5-
local ok = pcall(vim.treesitter.start, args.buf)
6-
if ok then
7-
local ft = vim.bo[args.buf].filetype
8-
if not vim.tbl_contains(indent_disabled, ft) then
9-
vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
26+
local buf, filetype = args.buf, args.match
27+
local language = vim.treesitter.language.get_lang(filetype)
28+
if not language then
29+
return
30+
end
31+
32+
if not treesitter_try_attach(buf, language) then
33+
if vim.tbl_contains(installable_parsers, language) then
34+
-- not already installed, so try to install them via nvim-treesitter if possible
35+
require("nvim-treesitter").install(language):await(function()
36+
treesitter_try_attach(buf, language)
37+
end)
1038
end
1139
end
1240
end,

modules/common/nvim/lua/chrishrb/plugins/init.lua

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,13 @@ local plugins = {
157157
-- Completions
158158
-----------------------------------------------------------------------------
159159
{
160-
"hrsh7th/nvim-cmp",
160+
"saghen/blink.cmp",
161161
dependencies = {
162-
"hrsh7th/cmp-buffer", -- Buffer completions
163-
"hrsh7th/cmp-path", -- Path completions
164-
"hrsh7th/cmp-cmdline", -- Cmdline completions
165-
"hrsh7th/cmp-nvim-lsp", -- LSP completions
166-
"hrsh7th/cmp-nvim-lsp-document-symbol", -- For textDocument/documentSymbol
167-
"petertriho/cmp-git", -- git source
168-
{
169-
"zbirenbaum/copilot-cmp",
170-
enabled = nixCats("ai"),
171-
config = function()
172-
require("copilot_cmp").setup()
173-
end,
174-
},
162+
"giuxtaposition/blink-cmp-copilot", -- Copilot completions
163+
"Kaiser-Yang/blink-cmp-git", -- git source
175164
},
176165
config = function()
177-
require("chrishrb.plugins.config.cmp")
166+
require("chrishrb.plugins.config.blink")
178167
end,
179168
event = "InsertEnter",
180169
},
@@ -184,8 +173,7 @@ local plugins = {
184173
-----------------------------------------------------------------------------
185174
{
186175
"nvim-treesitter/nvim-treesitter",
187-
branch = "main",
188-
build = nixCatsUtils.lazyAdd(":TSUpdate"),
176+
lazy = false,
189177
config = function()
190178
require("chrishrb.plugins.config.treesitter")
191179
end,
@@ -300,7 +288,7 @@ local plugins = {
300288
dependencies = {
301289
"nvim-lua/plenary.nvim",
302290
"nvim-treesitter/nvim-treesitter",
303-
"hrsh7th/nvim-cmp", -- Optional: For using slash commands and variables in the chat buffer
291+
"saghen/blink.cmp", -- Optional: For using slash commands and variables in the chat buffer
304292
{
305293
"echasnovski/mini.diff",
306294
config = function()

0 commit comments

Comments
 (0)