Skip to content

Commit

Permalink
chore: adding custom snippets and switching from mini.comments to `…
Browse files Browse the repository at this point in the history
…ts-comments`
  • Loading branch information
shubham-cpp committed Jan 10, 2025
1 parent 3c76515 commit da62cc9
Show file tree
Hide file tree
Showing 18 changed files with 558 additions and 189 deletions.
3 changes: 1 addition & 2 deletions .config/lazygit/state.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
lastupdatecheck: 0
recentrepos:
- /home/shubham/Documents/Programming/WebDev/temp-app
- /home/shubham/Documents/dotfiles
- /home/shubham/Documents/Programming/WebDev/social-media-manager-app
- /home/shubham/Documents/dotfiles
- /home/shubham/Documents/Programming/WebDev/invoice-genrator-nextjs
- /home/shubham/Documents/Programming/WebDev/vue3-chrome-ai
- /home/shubham/Documents/Programming/WebDev/demo-shadcn
Expand Down
131 changes: 127 additions & 4 deletions .config/nvim/lua/plugins/blink-cmp.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
-- NOTE: Specify the trigger character(s) used for luasnip
local trigger_text = ';'
---@type LazySpec
return {
'Saghen/blink.cmp',
enabled = false,
-- use a release tag to download pre-built binaries
version = '*',
-- optional: provides snippets for the snippet source
dependencies = {
'rafamadriz/friendly-snippets',
'mikavilpas/blink-ripgrep.nvim',
{
'folke/lazydev.nvim',
Expand All @@ -21,6 +20,43 @@ return {
},
},
{ 'Bilal2453/luvit-meta', lazy = true },
{
'L3MON4D3/LuaSnip',
version = 'v2.*',
build = 'make install_jsregexp',
dependencies = { 'rafamadriz/friendly-snippets' },
opts = { history = true, delete_check_events = 'TextChanged', region_check_events = 'CursorMoved' },
config = function(_, opts)
if opts then
require('luasnip').config.setup(opts)
end

vim.tbl_map(function(type)
require('luasnip.loaders.from_' .. type).lazy_load()
end, { 'vscode', 'snipmate', 'lua' })
require('luasnip.loaders.from_vscode').lazy_load({ paths = { vim.fn.stdpath 'config' .. '/snippets' } })

local extends = {
typescript = { 'tsdoc' },
javascript = { 'jsdoc' },
lua = { 'luadoc' },
python = { 'pydoc' },
rust = { 'rustdoc' },
cs = { 'csharpdoc' },
java = { 'javadoc' },
c = { 'cdoc' },
cpp = { 'cppdoc' },
php = { 'phpdoc' },
kotlin = { 'kdoc' },
ruby = { 'rdoc' },
sh = { 'shelldoc' },
}
-- friendly-snippets - enable standardized comments snippets
for ft, snips in pairs(extends) do
require('luasnip').filetype_extend(ft, snips)
end
end,
},
},
---@module 'blink.cmp'
---@type blink.cmp.Config
Expand Down Expand Up @@ -69,7 +105,7 @@ return {
---@type blink-ripgrep.Options
opts = {
prefix_min_len = 4,
score_offset = 10, -- should be lower priority
score_offset = -3, -- should be lower priority
max_filesize = '300K',
search_casing = '--smart-case',
},
Expand All @@ -80,6 +116,75 @@ return {
-- make lazydev completions top priority (see `:h blink.cmp`)
score_offset = 100,
},
lsp = {
name = 'lsp',
enabled = true,
module = 'blink.cmp.sources.lsp',
kind = 'LSP',
fallbacks = { 'snippets', 'buffer' },
score_offset = 95, -- the higher the number, the higher the priority
},
path = {
name = 'Path',
module = 'blink.cmp.sources.path',
score_offset = 25,
fallbacks = { 'buffer' },
opts = {
trailing_slash = false,
label_trailing_slash = true,
get_cwd = function(context)
return vim.fn.expand(('#%d:p:h'):format(context.bufnr))
end,
show_hidden_files_by_default = true,
},
},
buffer = {
name = 'Buffer',
enabled = true,
module = 'blink.cmp.sources.buffer',
min_keyword_length = 4,
score_offset = 15, -- the higher the number, the higher the priority
},
snippets = {
name = 'snippets',
enabled = true,
min_keyword_length = 2,
module = 'blink.cmp.sources.snippets',
score_offset = 80, -- the higher the number, the higher the priority
-- Only show snippets if I type the trigger_text characters, so
-- to expand the "bash" snippet, if the trigger_text is ";" I have to
should_show_items = function()
local col = vim.api.nvim_win_get_cursor(0)[2]
local before_cursor = vim.api.nvim_get_current_line():sub(1, col)
-- NOTE: remember that `trigger_text` is modified at the top of the file
return before_cursor:match(trigger_text .. '%w*$') ~= nil
end,
-- After accepting the completion, delete the trigger_text characters
-- from the final inserted text
transform_items = function(_, items)
local col = vim.api.nvim_win_get_cursor(0)[2]
local before_cursor = vim.api.nvim_get_current_line():sub(1, col)
local trigger_pos = before_cursor:find(trigger_text .. '[^' .. trigger_text .. ']*$')
if trigger_pos then
for _, item in ipairs(items) do
item.textEdit = {
newText = item.insertText or item.label,
range = {
start = { line = vim.fn.line '.' - 1, character = trigger_pos - 1 },
['end'] = { line = vim.fn.line '.' - 1, character = col },
},
}
end
end
-- NOTE: After the transformation, I have to reload the luasnip source
-- Otherwise really crazy shit happens and I spent way too much time
-- figurig this out
vim.schedule(function()
require('blink.cmp').reload 'snippets'
end)
return items
end,
},
},
cmdline = function()
local type = vim.fn.getcmdtype()
Expand All @@ -92,5 +197,23 @@ return {
return {}
end,
},
snippets = {
preset = 'luasnip',
-- This comes from the luasnip extra, if you don't add it, won't be able to
-- jump forward or backward in luasnip snippets
-- https://www.lazyvim.org/extras/coding/luasnip#blinkcmp-optional
expand = function(snippet)
require('luasnip').lsp_expand(snippet)
end,
active = function(filter)
if filter and filter.direction then
return require('luasnip').jumpable(filter.direction)
end
return require('luasnip').in_snippet()
end,
jump = function(direction)
require('luasnip').jump(direction)
end,
},
},
}
41 changes: 7 additions & 34 deletions .config/nvim/lua/plugins/comment.lua
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
---@type LazySpec
return {
{
'numToStr/Comment.nvim',
enabled = false,
keys = {
{ 'gc', mode = { 'x', 'n' }, desc = 'comment' },
{ 'gb', desc = 'Comment(block)' },
{ '<leader>/', '<cmd>lua require("Comment.api").toggle.linewise.current()<CR>', desc = 'Toggle Comment' },
{
'<leader>/',
function()
local esc = vim.api.nvim_replace_termcodes('<ESC>', true, false, true)
vim.api.nvim_feedkeys(esc, 'nx', false)
require('Comment.api').toggle.linewise(vim.fn.visualmode())
end,
mode = 'v',
desc = 'Toggle Comment',
},
{ '<A-/>', '"ayy"ap<cmd>lua require("Comment.api").toggle.linewise.current()<CR>', desc = 'Toggle Comment' },
'folke/ts-comments.nvim',
opts = {
lang = {
jsdoc = '/** %s */',
phpdoc = { '// %s' },
},
dependencies = {
{
'JoosepAlviste/nvim-ts-context-commentstring',
config = function()
-- vim.g.skip_ts_context_commentstring_module = true
require('ts_context_commentstring').setup({
enable_autocmd = false,
})
end,
},
},
config = function()
require('Comment').setup({
pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
})
end,
},
event = 'VeryLazy',
enabled = vim.fn.has 'nvim-0.10.0' == 1,
}
1 change: 1 addition & 0 deletions .config/nvim/lua/plugins/dooing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
return {
'atiladefreitas/dooing',
keys = { '<leader>td' },
enabled = false,
cmd = { 'Dooing' },
opts = {
-- Keymaps
Expand Down
57 changes: 55 additions & 2 deletions .config/nvim/lua/plugins/fzf-lua.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
--- ivy fzf
--[[
local fzf_lua = require("fzf-lua")
fzf_lua.files{
prompt = "Files",
fzf_opts = { ["--layout"] = "reverse" },
winopts = {
height = 0.35,
width = 1.00,
row = 1,
col = 1,
border = { " ", " ", " ", " ", " ", " ", " ", " " },
preview = {
layout = "flex",
hidden = "nohidden",
flip_columns = 130,
scrollbar = "float",
scrolloff = "-1",
scrollchars = { "█", "░" },
},
},
}
--]]

---Dropdown fzf
--[[
local fzf_lua = require("fzf-lua")
fzf_lua.files{
prompt = "Files",
fzf_opts = { ["--layout"] = "reverse" },
winopts = {
height = 0.70,
width = 0.45,
row = 0.1,
col = 0.5,
preview = { hidden = "hidden", layout = "vertical", vertical = "up:50%" },
},
}
--]]

---@type LazySpec
return {
'ibhagwan/fzf-lua',
dependencies = { 'nvim-tree/nvim-web-devicons' },
Expand Down Expand Up @@ -50,6 +91,7 @@ return {
['alt-enter'] = actions.file_tabedit,
['ctrl-t'] = actions.file_tabedit,
['ctrl-x'] = actions.file_split,
['ctrl-g'] = fzf.actions.grep_lgrep,
-- ['ctrl-q'] = actions.file_edit_or_qf,
}
-- calling `setup` is optional for customization
Expand Down Expand Up @@ -167,10 +209,21 @@ return {
helptags = { winopts = { preview = { layout = 'vertical', vertical = 'up:60%' } } },
grep = {
winopts = { preview = { layout = 'vertical', vertical = 'up:60%' } },
multiprocess = true,
prompt = '',
actions = m_keys,
rg_opts = "--hidden --column --line-number --no-ignore-vcs --no-heading --color=always --smart-case -g '!{.git,node_modules,android,ios,.env,.next,dist,package-lock.json,yarn.lock,pnpm-lock.yaml,.svelte-kit,*.aider.*}'",

rg_glob = true,
glob_flah = '--glob',
glob_separator = '%s%-%-',
glob_flag = '--iglob', -- for case sensitive globs use '--glob'
rg_glob_fn = function(query, opts)
-- this enables all `rg` arguments to be passed in after the `--` glob separator
local search_query, glob_str = query:match('(.*)' .. opts.glob_separator .. '(.*)')
local glob_args = glob_str:gsub('^%s+', ''):gsub('-', '%-') .. ' '

return search_query, glob_args
end,
},
blines = {
actions = m_keys,
Expand Down Expand Up @@ -325,7 +378,7 @@ return {
{ desc = '[F]iles' },
},
['<leader>fr'] = { fzf.resume, { desc = '[R]esume' } },
['<leader>fs'] = { fzf.live_grep_native, { desc = '[S]earch(Project)' } },
['<leader>fs'] = { fzf.live_grep, { desc = '[S]earch(Project)' } },
['<leader>fc'] = { fzf_create_file, { desc = 'Create File' } },
['<leader>fS'] = {
function()
Expand Down
13 changes: 13 additions & 0 deletions .config/nvim/lua/plugins/lazydo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---@type LazySpec
return {
'Dan7h3x/LazyDo',
keys = { -- recommended keymap for easy toggle LazyDo in normal and insert modes (arbitrary)
{
'<F2>',
'<CMD>LazyDoToggle<CR>',
mode = { 'n', 'i' },
desc = 'Toggle LazyDo',
},
},
opts = {},
}
17 changes: 10 additions & 7 deletions .config/nvim/lua/plugins/lsp/astrolsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ return {
desc = 'Workspace symbols',
cond = 'workspace/symbol',
},
['<F2>'] = {
vim.lsp.buf.rename,
desc = 'Rename',
cond = 'textDocument/rename',
},
-- ['<F2>'] = {
-- vim.lsp.buf.rename,
-- desc = 'Rename',
-- cond = 'textDocument/rename',
-- },
['<leader>lr'] = {
vim.lsp.buf.rename,
desc = 'Rename',
Expand Down Expand Up @@ -350,9 +350,12 @@ return {
},
handlers = {
function(server, opts)
local ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
if ok then
local ok_cmp, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
local ok_blink, blink = pcall(require, 'blink.cmp')
if ok_cmp then
opts.capabilities = cmp_nvim_lsp.default_capabilities(opts.capabilities)
elseif ok_blink then
opts.capabilities = blink.get_lsp_capabilities(opts.capabilities)
end
require('lspconfig')[server].setup(opts)
end,
Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/lua/plugins/mini/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
return {
'echasnovski/mini.comment',
version = '*',
enabled = true,
enabled = false,
keys = {
{ 'gc', mode = { 'n', 'x', 'o' } },
{ 'gcc' },
Expand Down
Loading

0 comments on commit da62cc9

Please sign in to comment.