summaryrefslogtreecommitdiff
path: root/.config/nvim/lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua')
-rw-r--r--.config/nvim/lua/cmp_helper.lua143
-rw-r--r--.config/nvim/lua/plugins/blink-cmp.lua163
-rw-r--r--.config/nvim/lua/plugins/colorful-menu.lua91
-rw-r--r--.config/nvim/lua/plugins/nvim-cmp.lua14
-rw-r--r--.config/nvim/lua/plugins/nvim-scissors.lua27
-rw-r--r--.config/nvim/lua/plugins/nvim-treesitter.lua12
6 files changed, 259 insertions, 191 deletions
diff --git a/.config/nvim/lua/cmp_helper.lua b/.config/nvim/lua/cmp_helper.lua
deleted file mode 100644
index ffa3418..0000000
--- a/.config/nvim/lua/cmp_helper.lua
+++ /dev/null
@@ -1,143 +0,0 @@
--- Load cmp_opts
-for _, ft_path in ipairs(vim.api.nvim_get_runtime_file('lua/snippets/*.lua', true)) do
- loadfile(ft_path)()
-end
-
-local luasnip = require('luasnip')
-local lspkind = require('lspkind')
-local cmp = require('cmp')
-
--- Enable paretheses for function completions
-cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm_done())
-
--- Helper functions
-local function snippet_jump(jump_amount)
- return cmp.mapping(function(fallback)
- if luasnip.locally_jumpable(jump_amount) then
- luasnip.jump(jump_amount)
- else
- fallback()
- end
- end, { 'i', 's' })
-end
-
-local function is_enabled()
- local context = require('cmp.config.context')
-
- local is_in_comment = context.in_treesitter_capture('comment') or context.in_syntax_group('Comment')
- if is_in_comment then
- return false
- end
-
- return true
-end
-
-cmp.setup({
- enabled = is_enabled,
- preselect = cmp.PreselectMode.None,
- completion = { completeopt = 'menu,menuone,noinsert' },
- sources = cmp.config.sources({
- { name = 'luasnip' }, -- for snippets
- {
- name = 'nvim_lsp',
- option = {
- markdown_oxide = {
- keyword_pattern = [[\(\k\| \|\/\|#\)\+]],
- },
- },
- }, -- for lsp
- { name = 'lazydev', group_index = 0 }, -- for lazydev.nvim
- { name = 'path' }, -- for filesystem
- }, {}),
- snippet = {
- expand = function(args)
- luasnip.lsp_expand(args.body)
- end,
- },
- window = {
- documentation = cmp.config.window.bordered(),
- completion = {
- border = 'rounded',
- winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None',
- col_offset = -3,
- side_padding = 0,
- },
- },
- ---@diagnostic disable-next-line: missing-fields
- sorting = {
- comparators = {
- cmp.config.compare.offset,
- cmp.config.compare.exact,
- cmp.config.compare.recently_used,
- require('clangd_extensions.cmp_scores'),
- cmp.config.compare.kind,
- cmp.config.compare.sort_text,
- cmp.config.compare.length,
- cmp.config.compare.order,
- },
- },
- mapping = {
- ['<Tab>'] = snippet_jump(1),
- ['<S-Tab>'] = snippet_jump(-1),
- ['<C-Space>'] = cmp.mapping.complete(), -- invoke completion
- ['<CR>'] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }),
- ['<C-u>'] = cmp.mapping.scroll_docs(-4),
- ['<C-d>'] = cmp.mapping.scroll_docs(4),
- ['<C-c>'] = cmp.mapping.abort(),
- ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
- ['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
- },
- ---@diagnostic disable-next-line: missing-fields
- formatting = {
- fields = { 'kind', 'abbr', 'menu' },
- format = function(entry, vim_item)
- local kind = lspkind.cmp_format({ mode = 'symbol_text', maxwidth = 50 })(entry, vim_item)
- local strings = vim.split(kind.kind, '%s', { trimempty = true })
- kind.kind = ' ' .. (strings[1] or '') .. ' ' -- left (icon)
- kind.menu = ' ' .. (strings[2] or '') .. '' -- right (text)
- return kind
- end,
- },
-})
-
--- -- Customization for Pmenu
--- vim.api.nvim_set_hl(0, 'PmenuSel', { bg = '#282C34', fg = 'NONE' })
--- vim.api.nvim_set_hl(0, 'Pmenu', { fg = '#C5CDD9', bg = '#22252A' })
---
-vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { fg = '#ff8294', bg = 'NONE', strikethrough = true })
--- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { fg = '#82AAFF', bg = 'NONE', bold = true })
--- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { fg = '#82AAFF', bg = 'NONE', bold = true })
--- vim.api.nvim_set_hl(0, 'CmpItemMenu', { fg = '#C792EA', bg = 'NONE', italic = true })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindField', { fg = '#EED8DA', bg = '#B5585F' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindProperty', { fg = '#EED8DA', bg = '#B5585F' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindEvent', { fg = '#EED8DA', bg = '#B5585F' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindText', { fg = '#C3E88D', bg = '#9FBD73' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindEnum', { fg = '#C3E88D', bg = '#9FBD73' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindKeyword', { fg = '#C3E88D', bg = '#9FBD73' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindConstant', { fg = '#FFE082', bg = '#D4BB6C' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindConstructor', { fg = '#FFE082', bg = '#D4BB6C' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindReference', { fg = '#FFE082', bg = '#D4BB6C' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindFunction', { fg = '#EADFF0', bg = '#A377BF' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindStruct', { fg = '#EADFF0', bg = '#A377BF' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindClass', { fg = '#EADFF0', bg = '#A377BF' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindModule', { fg = '#EADFF0', bg = '#A377BF' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindOperator', { fg = '#EADFF0', bg = '#A377BF' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { fg = '#C5CDD9', bg = '#7E8294' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindFile', { fg = '#C5CDD9', bg = '#7E8294' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindUnit', { fg = '#F5EBD9', bg = '#D4A959' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindSnippet', { fg = '#F5EBD9', bg = '#D4A959' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindFolder', { fg = '#F5EBD9', bg = '#D4A959' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { fg = '#DDE5F5', bg = '#6C8ED4' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindValue', { fg = '#DDE5F5', bg = '#6C8ED4' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindEnumMember', { fg = '#DDE5F5', bg = '#6C8ED4' })
---
--- vim.api.nvim_set_hl(0, 'CmpItemKindInterface', { fg = '#D8EEEB', bg = '#58B5A8' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindColor', { fg = '#D8EEEB', bg = '#58B5A8' })
--- vim.api.nvim_set_hl(0, 'CmpItemKindTypeParameter', { fg = '#D8EEEB', bg = '#58B5A8' })
diff --git a/.config/nvim/lua/plugins/blink-cmp.lua b/.config/nvim/lua/plugins/blink-cmp.lua
index 51d910b..85f93c9 100644
--- a/.config/nvim/lua/plugins/blink-cmp.lua
+++ b/.config/nvim/lua/plugins/blink-cmp.lua
@@ -1,44 +1,151 @@
return {
'saghen/blink.cmp',
+ event = 'InsertEnter',
version = '1.*',
+ dependencies = {
+ {
+ 'Kaiser-Yang/blink-cmp-git',
+ dependencies = { 'nvim-lua/plenary.nvim' },
+ },
+ },
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
- -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
- -- 'super-tab' for mappings similar to vscode (tab to accept)
- -- 'enter' for enter to accept
- -- 'none' for no mappings
- --
- -- All presets have the following mappings:
- -- C-space: Open menu or open docs if already open
- -- C-n/C-p or Up/Down: Select next/previous item
- -- C-e: Hide menu
- -- C-k: Toggle signature help (if signature.enabled = true)
- --
- -- See :h blink-cmp-config-keymap for defining your own keymap
- keymap = { preset = 'default' },
+ keymap = {
+ preset = 'enter',
+ ['<C-e>'] = {},
+ ['<C-c>'] = { 'hide', 'fallback' },
- appearance = {
- -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
- -- Adjusts spacing to ensure icons are aligned
- nerd_font_variant = 'mono',
+ ['<C-b>'] = {},
+ ['<C-f>'] = {},
+ ['<C-u>'] = { 'scroll_documentation_up', 'fallback' },
+ ['<C-d>'] = { 'scroll_documentation_down', 'fallback' },
},
- -- (Default) Only show the documentation popup when manually triggered
- completion = { documentation = { auto_show = false } },
+ completion = {
+ -- Show documentation when selecting a completion item
+ documentation = {
+ auto_show = true, -- TODO: turn this to off? once carbonight is ready
+ auto_show_delay_ms = 0,
+ window = { border = 'single' },
+ },
- -- Default list of enabled providers defined so that you can extend it
- -- elsewhere in your config, without redefining it, due to `opts_extend`
- sources = {
- default = { 'lsp', 'path', 'snippets', 'buffer' },
+ keyword = { range = 'full' },
+ -- Full seems cool but might be annoying
+ -- TODO: after a while, did I like this?
+ -- If so keep, otherwise switch to prefix
+
+ -- Preselect first one, don't complete until confirmation
+ list = { selection = { preselect = true, auto_insert = false } },
+
+ menu = {
+ draw = {
+ -- TODO: really cool but ugly AF now
+ -- need to add support for this in carbonight first
+ -- We don't need label_description now because label and label_description are already
+ -- combined together in label by colorful-menu.nvim.
+ -- columns = { { 'kind_icon' }, { 'label', gap = 1 } },
+ -- components = {
+ -- label = {
+ -- text = function(ctx)
+ -- return require('colorful-menu').blink_components_text(ctx)
+ -- end,
+ -- highlight = function(ctx)
+ -- return require('colorful-menu').blink_components_highlight(ctx)
+ -- end,
+ -- },
+ -- },
+ },
+ },
},
- -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
- -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
- -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
- --
- -- See the fuzzy documentation for more information
+ -- TODO: configure this when I get to fixing the LSP signature thing
+ signature = {},
+
fuzzy = { implementation = 'prefer_rust_with_warning' },
+
+ sources = {
+ default = { 'lsp', 'path', 'snippets', 'lazydev', 'git' },
+
+ providers = {
+ lazydev = {
+ name = 'LazyDev',
+ module = 'lazydev.integrations.blink',
+ score_offset = 100, -- prioritize lazydev
+ },
+ git = {
+ module = 'blink-cmp-git',
+ name = 'Git',
+ opts = {},
+ },
+
+ snippets = {
+ score_offset = 200, -- make snippets highest priority
+ transform_items = function(_, items)
+ return vim.tbl_filter(function(item)
+ if item.kind ~= require('blink.cmp.types').CompletionItemKind.Snippet then
+ return true
+ end
+
+ local name = item.description
+ -- vim.print(name)
+ local parts = vim.split(name, ' ', { trimempty = false })
+ local namespace = #parts > 1 and parts[1] or nil
+ -- vim.print(namespace)
+ if not namespace then
+ return true
+ end
+
+ -- vim.print(vim.fn.getcwd())
+ local path = vim.split(vim.fn.getcwd(), '/')
+ local dir = path[#path]
+ -- vim.print(dir)
+
+ return dir == namespace
+ end, items)
+ end,
+ },
+ },
+ },
+
+ appearance = {
+ -- TODO: change icons to make more sense to me
+ 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 = '󰬛',
+ },
+ },
},
opts_extend = { 'sources.default' },
+
+ -- TODO: pressing backk (deleting), should re-show completion menu
+ -- TODO: ghost text only for LLMs?
}
diff --git a/.config/nvim/lua/plugins/colorful-menu.lua b/.config/nvim/lua/plugins/colorful-menu.lua
new file mode 100644
index 0000000..71ef6b9
--- /dev/null
+++ b/.config/nvim/lua/plugins/colorful-menu.lua
@@ -0,0 +1,91 @@
+return {
+ "xzbdmw/colorful-menu.nvim",
+ config = function()
+ -- You don't need to set these options.
+ require("colorful-menu").setup({
+ ls = {
+ lua_ls = {
+ -- Maybe you want to dim arguments a bit.
+ arguments_hl = "@comment",
+ },
+ gopls = {
+ -- By default, we render variable/function's type in the right most side,
+ -- to make them not to crowd together with the original label.
+
+ -- when true:
+ -- foo *Foo
+ -- ast "go/ast"
+
+ -- when false:
+ -- foo *Foo
+ -- ast "go/ast"
+ align_type_to_right = true,
+ -- When true, label for field and variable will format like "foo: Foo"
+ -- instead of go's original syntax "foo Foo". If align_type_to_right is
+ -- true, this option has no effect.
+ add_colon_before_type = false,
+ -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
+ preserve_type_when_truncate = true,
+ },
+ -- for lsp_config or typescript-tools
+ ts_ls = {
+ -- false means do not include any extra info,
+ -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
+ extra_info_hl = "@comment",
+ },
+ vtsls = {
+ -- false means do not include any extra info,
+ -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
+ extra_info_hl = "@comment",
+ },
+ ["rust-analyzer"] = {
+ -- Such as (as Iterator), (use std::io).
+ extra_info_hl = "@comment",
+ -- Similar to the same setting of gopls.
+ align_type_to_right = true,
+ -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
+ preserve_type_when_truncate = true,
+ },
+ clangd = {
+ -- Such as "From <stdio.h>".
+ extra_info_hl = "@comment",
+ -- Similar to the same setting of gopls.
+ align_type_to_right = true,
+ -- the hl group of leading dot of "•std::filesystem::permissions(..)"
+ import_dot_hl = "@comment",
+ -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
+ preserve_type_when_truncate = true,
+ },
+ zls = {
+ -- Similar to the same setting of gopls.
+ align_type_to_right = true,
+ },
+ roslyn = {
+ extra_info_hl = "@comment",
+ },
+ dartls = {
+ extra_info_hl = "@comment",
+ },
+ -- The same applies to pyright/pylance
+ basedpyright = {
+ -- It is usually import path such as "os"
+ extra_info_hl = "@comment",
+ },
+ -- If true, try to highlight "not supported" languages.
+ fallback = true,
+ -- this will be applied to label description for unsupport languages
+ fallback_extra_info_hl = "@comment",
+ },
+ -- If the built-in logic fails to find a suitable highlight group for a label,
+ -- this highlight is applied to the label.
+ fallback_highlight = "@variable",
+ -- If provided, the plugin truncates the final displayed text to
+ -- this width (measured in display cells). Any highlights that extend
+ -- beyond the truncation point are ignored. When set to a float
+ -- between 0 and 1, it'll be treated as percentage of the width of
+ -- the window: math.floor(max_width * vim.api.nvim_win_get_width(0))
+ -- Default 60.
+ max_width = 60,
+ })
+ end,
+}
diff --git a/.config/nvim/lua/plugins/nvim-cmp.lua b/.config/nvim/lua/plugins/nvim-cmp.lua
deleted file mode 100644
index 16b3612..0000000
--- a/.config/nvim/lua/plugins/nvim-cmp.lua
+++ /dev/null
@@ -1,14 +0,0 @@
-return {
- -- 'hrsh7th/nvim-cmp',
- -- event = 'InsertEnter',
- -- dependencies = {
- -- 'onsails/lspkind.nvim', -- icons for completion type
- -- 'hrsh7th/cmp-path', -- complete filepaths
- -- 'hrsh7th/cmp-nvim-lsp', -- lsp source for nvim-cmp
- -- 'saadparwaiz1/cmp_luasnip', -- snippets source for nvim-cmp
- -- { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, -- snippets plugin
- -- },
- -- config = function()
- -- require('cmp_helper')
- -- end,
-}
diff --git a/.config/nvim/lua/plugins/nvim-scissors.lua b/.config/nvim/lua/plugins/nvim-scissors.lua
new file mode 100644
index 0000000..8eb3b8b
--- /dev/null
+++ b/.config/nvim/lua/plugins/nvim-scissors.lua
@@ -0,0 +1,27 @@
+return {
+ 'chrisgrieser/nvim-scissors',
+ dependencies = 'folke/snacks.nvim',
+ event = 'VeryLazy',
+ opts = {
+ ---@type "yq"|"jq"|"none"|string[]
+ jsonFormatter = 'jq',
+ },
+ keys = {
+ {
+ '<leader>sa',
+ function()
+ require('scissors').addNewSnippet()
+ end,
+ desc = '[S]nippet [A]dd',
+ mode = { 'n', 'x' },
+ },
+ {
+ '<leader>se',
+ function()
+ require('scissors').editSnippet()
+ end,
+ desc = '[S]nippet [E]dit',
+ mode = { 'n', 'x' },
+ },
+ },
+}
diff --git a/.config/nvim/lua/plugins/nvim-treesitter.lua b/.config/nvim/lua/plugins/nvim-treesitter.lua
index 7313054..7ee6a47 100644
--- a/.config/nvim/lua/plugins/nvim-treesitter.lua
+++ b/.config/nvim/lua/plugins/nvim-treesitter.lua
@@ -59,12 +59,12 @@ return {
},
swap = {
enable = true,
- swap_next = {
- ['<leader>sa'] = { query = '@parameter.inner', desc = 'Swap Argument (next)' },
- },
- swap_previous = {
- ['<leader>sA'] = { query = '@parameter.inner', desc = 'Swap Argument (prev)' },
- },
+ -- swap_next = {
+ -- ['<leader>sa'] = { query = '@parameter.inner', desc = 'Swap Argument (next)' },
+ -- },
+ -- swap_previous = {
+ -- ['<leader>sA'] = { query = '@parameter.inner', desc = 'Swap Argument (prev)' },
+ -- },
},
},
})