diff options
| author | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2024-12-30 18:39:09 +0000 |
|---|---|---|
| committer | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2024-12-30 18:54:04 +0000 |
| commit | 14fd73852847615a9de28b04e08e27b373e9e6be (patch) | |
| tree | 61635ec394778351761be43c413f7a3fba339cc4 /mut/neovim/lua | |
| parent | 54b71648f1ddf72dbe1092eae2da3ac6d2cd6ae0 (diff) | |
switch to ghostty
Diffstat (limited to 'mut/neovim/lua')
| -rw-r--r-- | mut/neovim/lua/my/init.lua | 118 | ||||
| -rw-r--r-- | mut/neovim/lua/my/lsp.lua | 1 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/blink.lua | 345 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/go.lua | 43 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/init.lua | 3 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/oil.lua | 2 |
6 files changed, 492 insertions, 20 deletions
diff --git a/mut/neovim/lua/my/init.lua b/mut/neovim/lua/my/init.lua index b10615b..6b368fe 100644 --- a/mut/neovim/lua/my/init.lua +++ b/mut/neovim/lua/my/init.lua @@ -7,10 +7,10 @@ _G.ternary = function ( cond , T , F ) end vim.cmd "colorscheme kanagawa-wave" -vim.cmd("filetype plugin on") -vim.cmd("filetype indent on") -vim.cmd("highlight WinSeparator guibg=None") -vim.cmd("packadd cfilter") +vim.cmd "filetype plugin on" +vim.cmd "filetype indent on" +vim.cmd "highlight WinSeparator guibg=None" +vim.cmd "packadd cfilter" vim.api.nvim_set_hl(0, "VirtualTextWarning", {link= "Grey"}) vim.api.nvim_set_hl(0, "VirtualTextError", {link= "DiffDelete"}) @@ -18,6 +18,7 @@ vim.api.nvim_set_hl(0, "VirtualTextInfo", {link= "DiffChange"}) vim.api.nvim_set_hl(0, "VirtualTextHint", {link= "DiffAdd"}) local map = vim.keymap.set +local unmap = vim.keymap.del function i_grep(word, file) vim.api.nvim_feedkeys( vim.api.nvim_replace_termcodes( @@ -32,6 +33,7 @@ function i_grep(word, file) end function cope() + require("quicker").refresh() vim.cmd(":botright copen " .. math.floor(vim.o.lines / 2.1)) end @@ -87,7 +89,7 @@ map("n", "<leader>:", function() i_grep("<c-r><c-w>", vim.fn.bufname("%")) end) map("v", "<leader>:", ":Vgrep!<cr>") map("n", "<leader>;", function() i_grep("", vim.fn.fnamemodify(vim.fn.bufname("%"), ":h")) end) map("v", "<leader>;", ":Vgrep<cr>") -map("n", "<leader>'", ":silent args `fd `<left>") +map("n", "<leader>'", ":Find ") map("n", "<leader>x<cr>", function() vim.cmd "b #" end) require("nvim_comment").setup() @@ -142,7 +144,10 @@ end, ) -function qf(inputs) +local last_job_state = nil +local last_job_thunk = nil +local last_job_lines = "" +function qf(inputs, opts) local id, title = inputs.id, inputs.title local prettify = function(line) local l = line:gsub("%c+%[[0-9:;<=>?]*[!\"#$%%&'()*+,-./]*[@A-Z%[%]^_`a-z{|}~]*;?[A-Z]?", "") @@ -159,11 +164,14 @@ function qf(inputs) return function(lines) lines = vim.iter(lines):map(prettify):totable() vim.schedule(function() + local what = { + id=id, + title=title, + lines=lines, + efm=opts.efm, + } vim.fn.setqflist( - {}, "a", { - id=id, title=title, - lines=lines - } + {}, "a", what ) if (not in_qf()) or (is_at_last_line() and in_qf()) then vim.cmd ":cbottom" @@ -172,28 +180,44 @@ function qf(inputs) end end -local last_job_state = nil -local last_job_thunk = nil -function qfjob(cmd, stdin) +function qfjob(cmd, stdin, opts) + last_job_lines = "" + local opts = opts or {} + opts.filter = opts.filter or (function(line) + return line + end) + local title = table.concat(cmd, " ") vim.fn.setqflist({}, " ", {title=title}) - local append_lines = qf(vim.fn.getqflist({id=0,title=1})) + local append_lines = qf(vim.fn.getqflist({id=0,title=1}), opts) last_job_state = vim.system( cmd, { stdin=stdin, stdout=function(err,data) if data then - append_lines(data:gmatch("[^\n]+")) + if not opts.buffer then + append_lines(vim.iter(data:gmatch("[^\n]+")):map(opts.filter)) + else + last_job_lines = last_job_lines .. data + end end end, stderr=function(err,data) if data then - append_lines(data:gmatch("[^\n]+")) + if not opts.buffer then + append_lines(vim.iter(data:gmatch("[^\n]+")):map(opts.filter)) + else + last_job_lines = last_job_lines .. data + end end end, }, function(job) vim.schedule(function() + if opts.buffer then + append_lines(vim.iter(last_job_lines:gmatch("[^\n]+")):map(opts.filter)) + end + local winnr = vim.fn.winnr() if not (job.code == 0) then cope() @@ -202,6 +226,9 @@ function qfjob(cmd, stdin) vim.cmd "wincmd p | cbot" end else + if opts.open then + cope() + end vim.notify([["]] .. title .. [[" succeeded!]]) end end) @@ -209,9 +236,47 @@ function qfjob(cmd, stdin) end vim.api.nvim_create_user_command( + "Find", + function(cmd) + local bufs = vim.iter(vim.api.nvim_list_bufs()) + :fold({}, function(acc, b) + acc[vim.api.nvim_buf_get_name(b)] = vim.api.nvim_buf_get_mark(b, [["]]) + return acc + end) + qfjob({ "fdfind", "--absolute-path", "--type", "f", "-E", vim.fn.expand("%:."), cmd.args }, nil, {efm = "%f:%l:%c:%m", open = true, filter = function(line) + local pos = bufs[line] or {} + local lnum, col = (pos[1] or "1"), (pos[2] or "0") + return line .. ":" .. lnum .. ":" .. col .. ":" .. "hello" + end}) + end, + {nargs="*", bang=true, complete="file"}) + +function opts_for_args(args) + local opts = { + go = { + test = function(cmd) + return {buffer = true, efm=require('my.packages.go').efm()} + end + } + } + local arg_opts = vim.iter(args) + :fold(opts, function(acc, v) + if type(acc) == "table" and acc[v] then + return acc[v] + end + return acc + end) + if type(arg_opts) == "function" then + return arg_opts() + elseif type(arg_opts) == "table" then + return (arg_opts[1] or function() return {} end)() + end +end + +vim.api.nvim_create_user_command( "Sh", function(cmd) - local thunk = function() qfjob({ "nu", "--commands", cmd.args }, nil) end + local thunk = function() qfjob({ "nu", "--commands", cmd.args }, nil, opts_for_args(cmd.fargs)) end last_job_thunk = thunk thunk() end, @@ -417,7 +482,24 @@ require('avante').setup ({ }, }) - +require("quicker").setup({ + keys = { + { + ">", + function() + require("quicker").expand({ before = 2, after = 2, add_to_existing = true }) + end, + desc = "Expand quickfix context", + }, + { + "<", + function() + require("quicker").collapse() + end, + desc = "Collapse quickfix context", + }, + }, +}) -- (local -- draw -- (fn [toggle] diff --git a/mut/neovim/lua/my/lsp.lua b/mut/neovim/lua/my/lsp.lua index 3097c58..2fad5aa 100644 --- a/mut/neovim/lua/my/lsp.lua +++ b/mut/neovim/lua/my/lsp.lua @@ -40,6 +40,7 @@ M.attach = function (ev) local fn = capability_map[c] if fn then fn() end end) + ev.client.capabilities = require('blink.cmp').get_lsp_capabilities(ev.client.capabilities) end return M diff --git a/mut/neovim/lua/my/packages/blink.lua b/mut/neovim/lua/my/packages/blink.lua new file mode 100644 index 0000000..bb5b30e --- /dev/null +++ b/mut/neovim/lua/my/packages/blink.lua @@ -0,0 +1,345 @@ +local blink = require('blink.cmp') +blink.setup { +-- When specifying 'preset' in the keymap table, the custom key mappings are merged with the preset, + -- and any conflicting keys will overwrite the preset mappings. + -- The "fallback" command will run the next non blink keymap. + -- + -- Example: + -- + -- keymap = { + -- preset = 'default', + -- ['<Up>'] = { 'select_prev', 'fallback' }, + -- ['<Down>'] = { 'select_next', 'fallback' }, + -- + -- -- disable a keymap from the preset + -- ['<C-e>'] = {}, + -- + -- -- show with a list of providers + -- ['<C-space>'] = { function(cmp) cmp.show({ providers = { 'snippets' } }) end }, + -- + -- -- note that your function will often be run in a "fast event" where most vim.api functions will throw an error + -- -- you may want to wrap your function in `vim.schedule` or use `vim.schedule_wrap` + -- ['<C-space>'] = { function(cmp) vim.schedule(function() your_behavior end) }, + -- + -- -- optionally, define different keymaps for cmdline + -- cmdline = { + -- preset = 'super-tab' + -- } + -- } + -- + -- When defining your own keymaps without a preset, no keybinds will be assigned automatically. + -- + -- Available commands: + -- show, hide, cancel, accept, select_and_accept, select_prev, select_next, show_documentation, hide_documentation, + -- scroll_documentation_up, scroll_documentation_down, snippet_forward, snippet_backward, fallback + -- + -- "default" keymap + -- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' }, + -- ['<C-e>'] = { 'hide' }, + -- ['<C-y>'] = { 'select_and_accept' }, + -- + -- ['<C-p>'] = { 'select_prev', 'fallback' }, + -- ['<C-n>'] = { 'select_next', 'fallback' }, + -- + -- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' }, + -- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' }, + -- + -- ['<Tab>'] = { 'snippet_forward', 'fallback' }, + -- ['<S-Tab>'] = { 'snippet_backward', 'fallback' }, + -- + -- "super-tab" keymap + -- you may want to set `completion.trigger.show_in_snippet = false` + -- or use `completion.list.selection = "manual" | "auto_insert"` + -- + -- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' }, + -- ['<C-e>'] = { 'hide', 'fallback' }, + -- + -- ['<Tab>'] = { + -- function(cmp) + -- if cmp.snippet_active() then return cmp.accept() + -- else return cmp.select_and_accept() end + -- end, + -- 'snippet_forward', + -- 'fallback' + -- }, + -- ['<S-Tab>'] = { 'snippet_backward', 'fallback' }, + -- + -- ['<Up>'] = { 'select_prev', 'fallback' }, + -- ['<Down>'] = { 'select_next', 'fallback' }, + -- ['<C-p>'] = { 'select_prev', 'fallback' }, + -- ['<C-n>'] = { 'select_next', 'fallback' }, + -- + -- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' }, + -- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' }, + -- + -- "enter" keymap + -- you may want to set `completion.list.selection = "manual" | "auto_insert"` + -- + -- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' }, + -- ['<C-e>'] = { 'hide', 'fallback' }, + -- ['<CR>'] = { 'accept', 'fallback' }, + -- + -- ['<Tab>'] = { 'snippet_forward', 'fallback' }, + -- ['<S-Tab>'] = { 'snippet_backward', 'fallback' }, + -- + -- ['<Up>'] = { 'select_prev', 'fallback' }, + -- ['<Down>'] = { 'select_next', 'fallback' }, + -- ['<C-p>'] = { 'select_prev', 'fallback' }, + -- ['<C-n>'] = { 'select_next', 'fallback' }, + -- + -- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' }, + -- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' }, + keymap = { preset = 'default' }, + + -- Enables keymaps, completions and signature help when true + enabled = function() return vim.bo.buftype ~= "prompt" and vim.b.completion ~= false end, + -- Example for blocking multiple filetypes + -- enabled = function() + -- return not vim.tbl_contains({ "lua", "markdown" }, vim.bo.filetype) + -- and vim.bo.buftype ~= "prompt" + -- and vim.b.completion ~= false + -- end, + + snippets = { + -- Function to use when expanding LSP provided snippets + expand = function(snippet) vim.snippet.expand(snippet) end, + -- Function to use when checking if a snippet is active + active = function(filter) return vim.snippet.active(filter) end, + -- Function to use when jumping between tab stops in a snippet, where direction can be negative or positive + jump = function(direction) vim.snippet.jump(direction) end, + }, + + signature = { + enabled = true, + trigger = { + blocked_trigger_characters = {}, + blocked_retrigger_characters = {}, + -- When true, will show the signature help window when the cursor comes after a trigger character when entering insert mode + show_on_insert_on_trigger_character = true, + }, + window = { + min_width = 1, + max_width = 100, + max_height = 10, + border = 'padded', + winblend = 0, + winhighlight = 'Normal:BlinkCmpSignatureHelp,FloatBorder:BlinkCmpSignatureHelpBorder', + scrollbar = false, -- Note that the gutter will be disabled when border ~= 'none' + -- Which directions to show the window, + -- falling back to the next direction when there's not enough space, + -- or another window is in the way + direction_priority = { 'n', 's' }, + -- Disable if you run into performance issues + treesitter_highlighting = true, + }, + }, + + sources = { + -- Static list of providers to enable, or a function to dynamically enable/disable providers based on the context + default = { 'lsp', 'path', 'snippets', 'buffer' }, + -- Example dynamically picking providers based on the filetype and treesitter node: + -- providers = function(ctx) + -- local node = vim.treesitter.get_node() + -- if vim.bo.filetype == 'lua' then + -- return { 'lsp', 'path' } + -- elseif node and vim.tbl_contains({ 'comment', 'line_comment', 'block_comment' }, node:type()) then + -- return { 'buffer' } + -- else + -- return { 'lsp', 'path', 'snippets', 'buffer' } + -- end + -- end + + -- You may also define providers per filetype + per_filetype = { + -- lua = { 'lsp', 'path' }, + }, + + -- By default, we choose providers for the cmdline based on the current cmdtype + -- You may disable cmdline completions by replacing this with an empty table + cmdline = function() + local type = vim.fn.getcmdtype() + -- Search forward and backward + if type == '/' or type == '?' then return { 'buffer' } end + -- Commands + if type == ':' then return { 'cmdline' } end + return {} + end, + + -- Function to use when transforming the items before they're returned for all providers + -- The default will lower the score for snippets to sort them lower in the list + transform_items = function(_, items) + for _, item in ipairs(items) do + if item.kind == require('blink.cmp.types').CompletionItemKind.Snippet then + item.score_offset = item.score_offset - 3 + end + end + return items + end, + -- Minimum number of characters in the keyword to trigger all providers + -- May also be `function(ctx: blink.cmp.Context): number` + min_keyword_length = 0, + -- Example for setting a minimum keyword length for markdown files + -- min_keyword_length = function() + -- return vim.bo.filetype == 'markdown' and 2 or 0 + -- end, + + -- Please see https://github.com/Saghen/blink.compat for using `nvim-cmp` sources + providers = { + lsp = { + name = 'LSP', + module = 'blink.cmp.sources.lsp', + -- Filter out text items from the LSP provider, since we have the buffer provider for that + transform_items = function(_, items) + return vim.tbl_filter( + function(item) return item.kind ~= require('blink.cmp.types').CompletionItemKind.Text end, + items + ) + end, + + --- *All* providers have the following options available + --- NOTE: All of these options may be functions to get dynamic behavior + --- See the type definitions for more information. + enabled = true, -- Whether or not to enable the provider + async = false, -- Whether we should wait for the provider to return before showing the completions + timeout_ms = 2000, -- How long to wait for the provider to return before showing completions and treating it as asynchronous + transform_items = nil, -- Function to transform the items before they're returned + should_show_items = true, -- Whether or not to show the items + max_items = nil, -- Maximum number of items to display in the menu + min_keyword_length = 0, -- Minimum number of characters in the keyword to trigger the provider + -- If this provider returns 0 items, it will fallback to these providers. + -- If multiple providers falback to the same provider, all of the providers must return 0 items for it to fallback + fallbacks = { 'buffer' }, + score_offset = 0, -- Boost/penalize the score of the items + override = nil, -- Override the source's functions + }, + path = { + name = 'Path', + module = 'blink.cmp.sources.path', + score_offset = 3, + 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 = false, + } + }, + snippets = { + name = 'Snippets', + module = 'blink.cmp.sources.snippets', + opts = { + friendly_snippets = true, + search_paths = { vim.fn.stdpath('config') .. '/snippets' }, + global_snippets = { 'all' }, + extended_filetypes = {}, + ignored_filetypes = {}, + get_filetype = function(context) + return vim.bo.filetype + end + } + + --- Example usage for disabling the snippet provider after pressing trigger characters (i.e. ".") + -- enabled = function(ctx) + -- return ctx ~= nil and ctx.trigger.kind == vim.lsp.protocol.CompletionTriggerKind.TriggerCharacter + -- end, + }, + luasnip = { + name = 'Luasnip', + module = 'blink.cmp.sources.luasnip', + opts = { + -- Whether to use show_condition for filtering snippets + use_show_condition = true, + -- Whether to show autosnippets in the completion list + show_autosnippets = true, + } + }, + buffer = { + name = 'Buffer', + module = 'blink.cmp.sources.buffer', + opts = { + -- default to all visible buffers + get_bufnrs = function() + return vim + .iter(vim.api.nvim_list_wins()) + :map(function(win) return vim.api.nvim_win_get_buf(win) end) + :filter(function(buf) return vim.bo[buf].buftype ~= 'nofile' end) + :totable() + end, + } + }, + }, + }, + + appearance = { + highlight_ns = vim.api.nvim_create_namespace('blink_cmp'), + -- Sets the fallback highlight groups to nvim-cmp's highlight groups + -- Useful for when your theme doesn't support blink.cmp + -- Will be removed in a future release + use_nvim_cmp_as_default = false, + -- Set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = 'mono', + kind_icons = { + Text = '', + Method = '', + Function = '', + Constructor = '', + + Field = '', + Variable = '', + Property = '', + + Class = '', + Interface = '', + Struct = '', + Module = '', + + Unit = '', + Value = '', + Enum = '', + EnumMember = '', + + Keyword = '', + Constant = '', + + Snippet = '', + Color = '', + File = '', + Reference = '', + Folder = '', + Event = '', + Operator = '', + TypeParameter = '', + }, + }, +} + +local map = vim.keymap.set +local unmap = vim.keymap.del +local event = vim.api.nvim_create_autocmd +map("n", "<leader>xf", function() + event({"CmdwinEnter"}, { + once = true, + callback = function() + map("i","<c-j>", function() + blink.hide() + vim.schedule(function() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes("<cr>", true, false, true), + "c", false) + end) + end,{buffer=true}) + map("i","<bs>","<c-o>vT/d",{buffer=true}) + end + }) + event({"CmdwinLeave"}, { + once = true, + callback = function() + unmap("i","<c-j>",{buffer=true}) + unmap("i","<bs>",{buffer=true}) + end + }) + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes(":edit <c-r>=expand('%:p:h')<cr><c-f>A/", true, false, true), + "c", false) +end) diff --git a/mut/neovim/lua/my/packages/go.lua b/mut/neovim/lua/my/packages/go.lua index 372d94b..4abf384 100644 --- a/mut/neovim/lua/my/packages/go.lua +++ b/mut/neovim/lua/my/packages/go.lua @@ -1,5 +1,10 @@ +local M = {} local go = require("go") +local gotest = require("go.gotest") go.setup { + test_efm = false, -- errorfomat for quickfix, default mix mode, set to true will be efm only + luasnip = true, + goimports = false, fillstruct = false, gofmt = false, @@ -29,6 +34,42 @@ go.setup { build_tags = "", test_runner = "go", run_in_floaterm = false, - luasnip = true, iferr_vertical_shift = 4, } + +local efm = function() + local indent = [[%\\%( %\\)]] + local efm = [[%-G=== RUN %.%#]] + efm = efm .. [[,%-G]] .. indent .. [[%#--- PASS: %.%#]] + efm = efm .. [[,%G--- FAIL: %\\%(Example%\\)%\\@= (%.%#)]] + efm = efm .. [[,%G]] .. indent .. [[%#--- FAIL: (%.%#)]] + efm = efm .. [[,%A]] .. indent .. [[%\\+%[%^:]%\\+: %f:%l: %m]] + efm = efm .. [[,%+Gpanic: test timed out after %.%\\+]] + efm = efm .. ',%+Afatal error: %.%# [recovered]' + efm = efm .. [[,%+Afatal error: %.%#]] + efm = efm .. [[,%+Apanic: %.%#]] + -- + -- -- exit + efm = efm .. ',%-Cexit status %[0-9]%\\+' + efm = efm .. ',exit status %[0-9]%\\+' + -- -- failed lines + efm = efm .. ',%-CFAIL%\\t%.%#' + efm = efm .. ',FAIL%\\t%.%#' + -- compiling error + + efm = efm .. ',%A%f:%l:%c: %m' + efm = efm .. ',%A%f:%l: %m' + efm = efm .. ',%f:%l +0x%[0-9A-Fa-f]%\\+' -- pannic with adress + efm = efm .. ',%-G%\\t%\\f%\\+:%\\d%\\+ +0x%[0-9A-Fa-f]%\\+' -- test failure, address invalid inside + -- multi-line + efm = efm .. ',%+G%\\t%m' + -- efm = efm .. ',%-C%.%#' -- ignore rest of unmatched lines + -- efm = efm .. ',%-G%.%#' + + efm = string.gsub(efm, ' ', [[\ ]]) + -- log(efm) + return efm +end +gotest.efm = efm +M.efm = efm +return M diff --git a/mut/neovim/lua/my/packages/init.lua b/mut/neovim/lua/my/packages/init.lua index 082cea4..849527e 100644 --- a/mut/neovim/lua/my/packages/init.lua +++ b/mut/neovim/lua/my/packages/init.lua @@ -1,5 +1,6 @@ require("my.packages.oil") -require("my.packages.cmp") +-- require("my.packages.cmp") +require("my.packages.blink") require("my.packages.lint") require("my.packages.luasnip") require("my.packages.dap") diff --git a/mut/neovim/lua/my/packages/oil.lua b/mut/neovim/lua/my/packages/oil.lua index 49c82c2..fa66001 100644 --- a/mut/neovim/lua/my/packages/oil.lua +++ b/mut/neovim/lua/my/packages/oil.lua @@ -1,5 +1,7 @@ local oil=require("oil") local fzf=require("fzf-lua") +local map = vim.keymap.set +local unmap = vim.keymap.del oil.setup({ default_file_explorer = true, |
