Compare commits

1 Commits

Author SHA1 Message Date
Chris
a086657031 Treesitter update 2025-12-10 14:19:07 +00:00
6 changed files with 325 additions and 177 deletions

View File

@@ -30,7 +30,7 @@ vim.api.nvim_create_autocmd('SwapExists', {
desc = 'Always choose to delete the swap file, files are saved automatically', desc = 'Always choose to delete the swap file, files are saved automatically',
group = vim.api.nvim_create_augroup('NoSwaps', { clear = true }), group = vim.api.nvim_create_augroup('NoSwaps', { clear = true }),
callback = function(args) callback = function(args)
vim.cmd("let v:swapchoice = 'd'") vim.cmd "let v:swapchoice = 'd'"
end, end,
}) })
@@ -116,4 +116,33 @@ vim.api.nvim_create_autocmd('BufWritePost', {
end, end,
}) })
vim.api.nvim_create_autocmd('FileType', {
pattern = {
'bash',
'c',
'diff',
'html',
'lua',
'luadoc',
'markdown',
'markdown_inline',
'query',
'vim',
'vimdoc',
'php',
'javascript',
'typescript',
'json',
},
callback = function()
-- syntax highlighting, provided by Neovim
vim.treesitter.start()
-- folds, provided by Neovim
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
vim.wo.foldmethod = 'expr'
-- indentation, provided by nvim-treesitter
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
require('helpers').edit_cf('a', '/lua/autocmd.lua') require('helpers').edit_cf('a', '/lua/autocmd.lua')

View File

@@ -30,13 +30,13 @@ vim.keymap.set('n', '<Leader>c', function()
vim.treesitter.inspect_tree() vim.treesitter.inspect_tree()
end, { desc = 'Treesitter' }) end, { desc = 'Treesitter' })
vim.keymap.set('n', '<C-S-D>', function() -- vim.keymap.set('n', '<C-S-D>', function()
local node = vim.treesitter.get_node {} -- local node = vim.treesitter.get_node {}
local range = { vim.treesitter.get_node_range(node) } -- local range = { vim.treesitter.get_node_range(node) }
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 }) -- vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 }) -- vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
vim.cmd.normal 'v`x' -- vim.cmd.normal 'v`x'
end, { desc = 'Select surrounding treesitter node' }) -- end, { desc = 'Select surrounding treesitter node' })
vim.keymap.set('v', '<C-S-D>', function() vim.keymap.set('v', '<C-S-D>', function()
local start = vim.api.nvim_win_get_cursor(0) local start = vim.api.nvim_win_get_cursor(0)
@@ -258,7 +258,6 @@ vim.keymap.set('n', '<Leader>]', '<CMD>cnext<CR>', { desc = 'Next item in quickf
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' }) vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' }) vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
local function open_test() local function open_test()
require('neotest').summary.open() require('neotest').summary.open()
require('neotest').output_panel.open() require('neotest').output_panel.open()

View File

@@ -0,0 +1,153 @@
-- Highlight, edit, and navigate code
return {
-- 'nvim-treesitter/nvim-treesitter-textobjects',
-- lazy = true,
-- branch = 'main',
-- dependencies = {
-- 'nvim-treesitter/nvim-treesitter',
-- },
-- config = function()
-- -- configuration
-- require('nvim-treesitter-textobjects').setup {
-- select = {
-- lookahead = true,
-- selection_modes = {
-- ['@parameter.outer'] = 'v', -- charwise
-- ['@function.outer'] = 'V', -- linewise
-- ['@class.outer'] = 'V', -- blockwise
-- },
-- include_surrounding_whitespace = false,
-- },
-- move = {
-- set_jumps = true,
-- },
-- }
-- for keys, query in
-- {
-- -- or you use the queries from supported languages with textobjects.scm
-- ['af'] = '@function.outer',
-- ['if'] = '@function.inner',
-- ['aC'] = '@class.outer',
-- ['iC'] = '@class.inner',
-- ['ay'] = '@conditional.outer',
-- ['iy'] = '@conditional.inner',
-- ['aj'] = '@loop.outer',
-- ['ij'] = '@loop.inner',
-- ['is'] = '@statement.inner',
-- ['as'] = '@statement.outer',
-- ['ac'] = '@comment.outer',
-- ['ic'] = '@comment.inner',
-- ['ap'] = '@comment.parameter',
-- ['ip'] = '@comment.parameter',
-- ['an'] = '@local.scope',
-- }
-- do
-- vim.keymap.set({ 'n', 'x', 'o' }, keys, function()
-- require('nvim-treesitter-textobjects.select').select_textobject(query, 'textobjects')
-- end)
-- end
-- for keys, query in
-- {
-- -- or you use the queries from supported languages with textobjects.scm
-- [']'] = '@function.outer',
-- ['o'] = { '@loop.inner', '@loop.outer' },
-- ['n'] = '@local.scope',
-- ['y'] = '@conditional.outer',
-- ['e'] = '@statement.outer',
-- ['/'] = '@comment.outer',
-- }
-- do
-- vim.keymap.set({ 'n', 'x', 'o' }, ']' .. keys, function()
-- require('nvim-treesitter-textobjects.move').goto_next_start(query, 'textobjects')
-- end)
-- vim.keymap.set({ 'n', 'x', 'o' }, '[' .. keys, function()
-- require('nvim-treesitter-textobjects.move').goto_previous_start(query, 'textobjects')
-- end)
-- end
-- -- require('nvim-treesitter.configs').setup {
-- -- incremental_selection = {
-- -- enable = true,
-- -- keymaps = {
-- -- -- mappings for incremental selection (visual mappings)
-- -- init_selection = '<C-S-D>', -- maps in normal mode to init the node/scope selection
-- -- node_incremental = '<C-S-D>', -- increment to the upper named parent
-- -- scope_incremental = '<C-S-U>', -- increment to the upper scope (as defined in locals.scm)
-- -- node_decremental = '<C-S-S>', -- decrement to the previous node
-- -- },
-- -- },
-- -- textobjects = {
-- -- -- syntax-aware textobjects
-- -- enable = true,
-- -- keymaps = {
-- -- ['iL'] = {
-- -- -- you can define your own textobjects directly here
-- -- go = '(function_definition) @function',
-- -- },
-- -- -- or you use the queries from supported languages with textobjects.scm
-- -- ['af'] = '@function.outer',
-- -- ['if'] = '@function.inner',
-- -- ['aC'] = '@class.outer',
-- -- ['iC'] = '@class.inner',
-- -- ['ay'] = '@conditional.outer',
-- -- ['iy'] = '@conditional.inner',
-- -- ['aj'] = '@loop.outer',
-- -- ['ij'] = '@loop.inner',
-- -- ['is'] = '@statement.inner',
-- -- ['as'] = '@statement.outer',
-- -- ['ac'] = '@comment.outer',
-- -- ['ic'] = '@comment.inner',
-- -- ['ap'] = '@comment.parameter',
-- -- ['ip'] = '@comment.parameter',
-- -- },
-- -- move = {
-- -- enable = true,
-- -- set_jumps = true, -- whether to set jumps in the jumplist
-- -- goto_next_start = {
-- -- [']m'] = '@function.outer',
-- -- [']]'] = '@class.outer',
-- -- },
-- -- goto_next_end = {
-- -- [']M'] = '@function.outer',
-- -- [']['] = '@class.outer',
-- -- },
-- -- goto_previous_start = {
-- -- ['[m'] = '@function.outer',
-- -- ['[['] = '@class.outer',
-- -- },
-- -- goto_previous_end = {
-- -- ['[M'] = '@function.outer',
-- -- ['[]'] = '@class.outer',
-- -- },
-- -- },
-- -- select = {
-- -- enable = true,
-- -- keymaps = {
-- -- -- You can use the capture groups defined in textobjects.scm
-- -- ['af'] = '@function.outer',
-- -- ['if'] = '@function.inner',
-- -- ['ac'] = '@class.outer',
-- -- ['ic'] = '@class.inner',
-- -- -- Or you can define your own textobjects like this
-- -- ['iF'] = {
-- -- python = '(function_definition) @function',
-- -- cpp = '(function_definition) @function',
-- -- c = '(function_definition) @function',
-- -- java = '(method_declaration) @function',
-- -- go = '(method_declaration) @function',
-- -- },
-- -- },
-- -- },
-- -- },
-- -- }
-- end,
-- opts = {},
-- -- There are additional nvim-treesitter modules that you can use to interact
-- -- with nvim-treesitter. You should go explore a few and see what interests you:
-- --
-- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
-- -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
-- -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
}

View File

@@ -2,10 +2,11 @@
return { return {
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate', build = ':TSUpdate',
main = 'nvim-treesitter.configs', -- Sets main module to use for opts branch = 'main',
-- [[ Configure Treesitter ]] See `:help nvim-treesitter` -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
opts = { config = function()
ensure_installed = { require('nvim-treesitter').setup {}
require('nvim-treesitter').install {
'bash', 'bash',
'c', 'c',
'diff', 'diff',
@@ -17,18 +18,13 @@ return {
'query', 'query',
'vim', 'vim',
'vimdoc', 'vimdoc',
}, 'php',
-- Autoinstall languages that are not installed 'javascript',
auto_install = true, 'typescript',
highlight = { 'json',
enable = true, }
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. end,
-- If you are experiencing weird indenting issues, add the language to opts = {},
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
additional_vim_regex_highlighting = { 'ruby' },
},
indent = { enable = true, disable = { 'ruby' } },
},
-- There are additional nvim-treesitter modules that you can use to interact -- There are additional nvim-treesitter modules that you can use to interact
-- with nvim-treesitter. You should go explore a few and see what interests you: -- with nvim-treesitter. You should go explore a few and see what interests you:
-- --

View File

@@ -16,7 +16,6 @@ local fmta = extend_decorator.apply(fmt, { delimiters = '#~' })
local utils = require 'snippets.snip_utils' local utils = require 'snippets.snip_utils'
local tr = utils.tr local tr = utils.tr
local etr = utils.etr local etr = utils.etr
local Etr = utils.Etr
local atr = utils.atr local atr = utils.atr
local ctr = utils.ctr local ctr = utils.ctr
local bs = utils.bs local bs = utils.bs
@@ -70,10 +69,10 @@ return {
--------------- ---------------
-- DEBUGGING -- -- DEBUGGING --
--------------- ---------------
s(etr('du ', 'Dump a variable to the dump server', { priority = 1001 }), fmta('dump(#~);', { i(0) })), s(etr('du ', 'Dump a variable to the dump server'), fmta('dump(#~);', { i(0) })),
bs(etr('du ', 'Dump a variable to the dump server'), fmta('dump(#~)', { i(0) })), bs(atr('du ', 'Dump a variable to the dump server'), fmta('dump(#~)', { i(0) })),
s(etr('r ', 'ray', { priority = 1001 }), fmta('ray(#~);', { i(0) })), s(etr('r ', 'ray'), fmta('ray(#~);', { i(0) })),
bs(etr('r ', 'ray'), fmta('ray(#~)', { i(0) })), bs(atr('r ', 'ray'), fmta('ray(#~)', { i(0) })),
s(etr('dt ', 'Dump PHPStan type definition'), fmta('\\PhpStan\\dumpType(#~);', { i(0) })), s(etr('dt ', 'Dump PHPStan type definition'), fmta('\\PhpStan\\dumpType(#~);', { i(0) })),
s( s(
etr('ql ', 'Log all queries'), etr('ql ', 'Log all queries'),
@@ -108,7 +107,6 @@ return {
}), }),
s(etr('@v', '@var docblock'), fmta('/** @var #~ $#~ */', { i(1), i(0) })), s(etr('@v', '@var docblock'), fmta('/** @var #~ $#~ */', { i(1), i(0) })),
s(ctr('@v', '@var docblock'), fmta('@var #~ $#~', { i(1), i(0) })), s(ctr('@v', '@var docblock'), fmta('@var #~ $#~', { i(1), i(0) })),
s(Etr('@pi', '@phpstan-ignore'), fmta('// @phpstan-ignore #~ (#~)', { i(1), i(0) })),
s(ctr('* @pr', 'Class property docblock'), fmta('* @property #~ $#~', { i(1), i(0) })), s(ctr('* @pr', 'Class property docblock'), fmta('* @property #~ $#~', { i(1), i(0) })),
s(ctr('* @pb', 'Class boolean property docblock'), fmta('* @property bool $#~', { i(0) })), s(ctr('* @pb', 'Class boolean property docblock'), fmta('* @property bool $#~', { i(0) })),
s(ctr('* @pi', 'Class int property docblock'), fmta('* @property int $#~', { i(0) })), s(ctr('* @pi', 'Class int property docblock'), fmta('* @property int $#~', { i(0) })),
@@ -214,36 +212,36 @@ return {
), ),
}), }),
}), }),
-- s( s(
-- etr('con', 'Constructor function block'), etr('con', 'Constructor function block'),
-- c(1, { c(1, {
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- public function __construct(#~) public function __construct(#~)
-- { {
-- #~ #~
-- } }
-- ]], ]],
-- { i(1), i(2) } { i(1), i(2) }
-- ) )
-- ), ),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- public function __construct( public function __construct(
-- #~ #~
-- ) { ) {
-- #~ #~
-- } }
-- ]], ]],
-- { i(1), i(2) } { i(1), i(2) }
-- ) )
-- ), ),
-- }) })
-- ), ),
bs(atr('function', 'Shorthand function block'), fmta('fun', {})), bs(atr('function', 'Shorthand function block'), fmta('fun', {})),
bs(atr('s%$', 'string type parameter'), fmta('string $#~', { i(0, 'var') })), bs(atr('s%$', 'string type parameter'), fmta('string $#~', { i(0, 'var') })),
bs(atr('i%$', 'int type parameter'), fmta('int $#~', { i(0, 'var') })), bs(atr('i%$', 'int type parameter'), fmta('int $#~', { i(0, 'var') })),
@@ -360,20 +358,9 @@ return {
etr('test', 'Create a test function'), etr('test', 'Create a test function'),
fmta( fmta(
[[ [[
test('#~', function () { test(#~ function () {
#~ #~
}); })
]],
{ i(1), i(0) }
)
),
s(
etr('it ', 'Create a test function'),
fmta(
[[
it('#~', function () {
#~
});
]], ]],
{ i(1), i(0) } { i(1), i(0) }
) )
@@ -522,92 +509,92 @@ return {
), ),
}) })
), ),
-- s( s(
-- atr('->wr', 'Eloquent where method'), atr('->wr', 'Eloquent where method'),
-- c(0, { c(0, {
-- sn(nil, fmta("->where('#~', #~)", { i(1), i(0) })), sn(nil, fmta("->where('#~', #~)", { i(1), i(0) })),
-- sn(nil, fmta('->where(fn ($query) => #~)', { i(0) })), sn(nil, fmta('->where(fn ($query) => #~)', { i(0) })),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- ->where(function ($query) { ->where(function ($query) {
-- #~ #~
-- }) })
-- ]], ]],
-- { i(0) } { i(0) }
-- ) )
-- ), ),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- ->where(function ($query) use (#~) { ->where(function ($query) use (#~) {
-- #~ #~
-- }) })
-- ]], ]],
-- { i(1), i(0) } { i(1), i(0) }
-- ) )
-- ), ),
-- }) })
-- ), ),
-- s(atr('->wi', 'Eloquent where in method'), fmta("->whereIn('#~', #~)", { i(1), i(0) })), s(atr('->wi', 'Eloquent where in method'), fmta("->whereIn('#~', #~)", { i(1), i(0) })),
-- s(atr('->wn', 'Eloquent where not in method'), fmta("->whereNotIn('#~', #~)", { i(1), i(0) })), s(atr('->wn', 'Eloquent where not in method'), fmta("->whereNotIn('#~', #~)", { i(1), i(0) })),
-- s( s(
-- atr('->wha', 'Eloquent where has method'), atr('->wh', 'Eloquent where has method'),
-- c(0, { c(0, {
-- sn(nil, fmta("->whereHas('#~')", { i(1) })), sn(nil, fmta("->whereHas('#~')", { i(1) })),
-- sn(nil, fmta("->whereHas('#~', fn ($query) => #~)", { i(1), i(0) })), sn(nil, fmta("->whereHas('#~', fn ($query) => #~)", { i(1), i(0) })),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- ->whereHas('#~', function ($query) { ->whereHas('#~', function ($query) {
-- #~ #~
-- }) })
-- ]], ]],
-- { i(1), i(0) } { i(1), i(0) }
-- ) )
-- ), ),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- ->whereHas('#~', function ($query) use (#~) { ->whereHas('#~', function ($query) use (#~) {
-- #~ #~
-- }) })
-- ]], ]],
-- { i(1), i(2), i(0) } { i(1), i(2), i(0) }
-- ) )
-- ), ),
-- }) })
-- ), ),
-- s( s(
-- atr('->we', 'Eloquent where exists method'), atr('->we', 'Eloquent where exists method'),
-- c(0, { c(0, {
-- sn(nil, fmta('->whereExists(fn ($query) => #~)', { i(0) })), sn(nil, fmta('->whereExists(fn ($query) => #~)', { i(0) })),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- ->whereExists(function ($query) { ->whereExists(function ($query) {
-- #~ #~
-- }) })
-- ]], ]],
-- { i(0) } { i(0) }
-- ) )
-- ), ),
-- sn( sn(
-- nil, nil,
-- fmta( fmta(
-- [[ [[
-- ->whereExists(function ($query) use (#~) { ->whereExists(function ($query) use (#~) {
-- #~ #~
-- }) })
-- ]], ]],
-- { i(1), i(0) } { i(1), i(0) }
-- ) )
-- ), ),
-- }) })
-- ), ),
} }

View File

@@ -11,7 +11,6 @@ local d = ls.dynamic_node
local fmt = require('luasnip.extras.fmt').fmt local fmt = require('luasnip.extras.fmt').fmt
local rep = require('luasnip.extras').rep local rep = require('luasnip.extras').rep
local line_begin = require('luasnip.extras.conditions').line_begin local line_begin = require('luasnip.extras.conditions').line_begin
local line_end = require('luasnip.extras.conditions').line_end
local extend_decorator = require 'luasnip.util.extend_decorator' local extend_decorator = require 'luasnip.util.extend_decorator'
local fmta = extend_decorator.apply(fmt, { delimiters = '#~' }) local fmta = extend_decorator.apply(fmt, { delimiters = '#~' })
@@ -110,21 +109,6 @@ utils.atr = function(trigger, description, options)
) )
end end
--- Create a trigger for a snippet to expand at the end of a line
---@param trigger string
---@param description? string
---@param options? table
---@return table
utils.Etr = function(trigger, description, options)
return utils.tr(
trigger,
description,
vim.tbl_extend('force', {
condition = line_end
}, options or {})
)
end
--- Create a snippet that will expand anywhere but in the middle of a word --- Create a snippet that will expand anywhere but in the middle of a word
---@param trigger any ---@param trigger any
---@param nodes any ---@param nodes any