From 5f2833cbd29ce4315a1bf9619685837d4a5c4974 Mon Sep 17 00:00:00 2001 From: aceforeverd Date: Wed, 21 Aug 2024 19:18:54 +0800 Subject: [PATCH] update - cmds: Sg/SG -> query with ast grep - rm null-ls, pounce, cmp-nvim-lua --- autoload/aceforeverd/plugin.vim | 8 ++++++++ lua/aceforeverd/cmd.lua | 19 +++++++++++++++++++ lua/aceforeverd/config/cmp.lua | 4 +--- lua/aceforeverd/init.lua | 9 +-------- lua/aceforeverd/keymap/init.lua | 23 ++++++++++++++++++++++- lua/aceforeverd/plugins/init.lua | 11 ----------- 6 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 lua/aceforeverd/cmd.lua diff --git a/autoload/aceforeverd/plugin.vim b/autoload/aceforeverd/plugin.vim index 7f45d89..74fca68 100644 --- a/autoload/aceforeverd/plugin.vim +++ b/autoload/aceforeverd/plugin.vim @@ -344,11 +344,19 @@ function! s:config_plugins() abort nnoremap B :BLines nnoremap L :Lines + " GGrep command! -bang -nargs=* GGrep \ call fzf#vim#grep( \ 'git grep --line-number -- '.shellescape(), 0, \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), 0) + " SG . relaunch sg on every keystroke + " TODO: sg pattern do not work well with single quote pattern + command! -bang -nargs=* SG + \ call fzf#vim#grep2( + \ 'sg run --heading never --pattern ', , 0, + \ fzf#vim#with_preview(), 0) + " more for vim-rsi let g:rsi_no_meta = 1 " & -> & , & -> forward & backward diff --git a/lua/aceforeverd/cmd.lua b/lua/aceforeverd/cmd.lua new file mode 100644 index 0000000..e1bd455 --- /dev/null +++ b/lua/aceforeverd/cmd.lua @@ -0,0 +1,19 @@ +-- runs a lua expr and print its results +local function inspect(opts) + local res = vim.api.nvim_eval('luaeval("' .. vim.fn.escape(opts.args, '"') .. '")') + vim.notify(vim.inspect(res), vim.log.levels.INFO, {}) +end + +return { + setup = function() + vim.api.nvim_create_user_command('LuaInspect', inspect, { complete = 'lua', nargs = 1 }) + + -- Sg [ ...] + vim.api.nvim_create_user_command( + 'Sg', + require('aceforeverd.keymap.init').ast_grep_search, + -- TODO: custom complete function + { nargs = '+', desc = 'ast grep search', complete = 'dir' } + ) + end, +} diff --git a/lua/aceforeverd/config/cmp.lua b/lua/aceforeverd/config/cmp.lua index 7c6f27f..88c340d 100644 --- a/lua/aceforeverd/config/cmp.lua +++ b/lua/aceforeverd/config/cmp.lua @@ -66,11 +66,10 @@ function M.setup() -- level 1 source local sources_1 = { - { name = 'nvim_lsp' }, { name = "lazydev" }, + { name = 'nvim_lsp' }, { name = 'luasnip', option = { use_show_condition = false } }, - { name = 'nvim_lua' }, { name = 'path' }, { name = 'git' }, @@ -141,7 +140,6 @@ function M.setup() luasnip = '[LuaSnip]', buffer = '[Buffer]', path = '[Path]', - nvim_lua = '[Lua]', look = '[Look]', emoji = '[Emoji]', treesitter = '[TreeSitter]', diff --git a/lua/aceforeverd/init.lua b/lua/aceforeverd/init.lua index 6b055be..85396ed 100644 --- a/lua/aceforeverd/init.lua +++ b/lua/aceforeverd/init.lua @@ -19,12 +19,6 @@ local function on_term_enter() vim.cmd[[DisableWhitespace]] end --- runs a lua expr and print its results -local function inspect(opts) - local res = vim.api.nvim_eval('luaeval("' .. vim.fn.escape(opts.args, '"') .. '")') - vim.notify(vim.inspect(res), vim.log.levels.INFO, {}) -end - function M.setup() if vim.g.lsp_process_provider == nil then vim.g.lsp_process_provider = 'lsp_status' @@ -64,8 +58,7 @@ function M.setup() callback = on_term_enter, }) - vim.api.nvim_create_user_command('LuaInspect', inspect, { complete = 'lua', nargs = 1 }) - + require('aceforeverd.cmd').setup() require('aceforeverd.plugins').setup() -- keymap guideline diff --git a/lua/aceforeverd/keymap/init.lua b/lua/aceforeverd/keymap/init.lua index 8d7bf79..bffe055 100644 --- a/lua/aceforeverd/keymap/init.lua +++ b/lua/aceforeverd/keymap/init.lua @@ -1,3 +1,24 @@ +---@param opts table ast grep search pattern +local function ast_grep_search(opts) + local args = opts.fargs + local pattern = args[1] + + local cmds = { 'sg', 'run', '--heading', 'never', '--pattern', pattern } + for i = 2, #args, 1 do + table.insert(cmds, args[i]) + end + + local expr = string.format( + 'system([%s])', + vim.iter(cmds):map(function(v) + return vim.fn.shellescape(v) + end):join(", ") + ) + vim.cmd('lgetexpr ' .. expr) + vim.cmd('lopen') +end + return { - select_browse_plugin = require('aceforeverd.keymap.plugin_browse').select_browse_plugin + select_browse_plugin = require('aceforeverd.keymap.plugin_browse').select_browse_plugin, + ast_grep_search = ast_grep_search, } diff --git a/lua/aceforeverd/plugins/init.lua b/lua/aceforeverd/plugins/init.lua index 47bbfa3..b8f5ae1 100644 --- a/lua/aceforeverd/plugins/init.lua +++ b/lua/aceforeverd/plugins/init.lua @@ -317,16 +317,6 @@ M.plugin_list = { event = 'VeryLazy', }, - { - 'nvimtools/none-ls.nvim', - dependencies = { - 'nvim-lua/plenary.nvim', - }, - config = function() - require('aceforeverd.plugins.null-ls').setup() - end, - }, - { 'mfussenegger/nvim-lint', config = function() @@ -424,7 +414,6 @@ M.plugin_list = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', - 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-emoji', 'uga-rosa/cmp-dictionary', 'ray-x/cmp-treesitter',