1
0
Files
dotfiles/nvim/.config/nvim/lua/plugins/completion.lua
2025-02-13 20:24:17 +01:00

261 lines
8.9 KiB
Lua

return {
{
"folke/lazydev.nvim",
ft = "lua", -- only load on lua files
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
},
{
"saghen/blink.cmp",
-- optional: provides snippets for the snippet source
dependencies = {
"rafamadriz/friendly-snippets",
"Kaiser-Yang/blink-cmp-dictionary",
"moyiz/blink-emoji.nvim",
"mikavilpas/blink-ripgrep.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
},
-- use a release tag to download pre-built binaries
version = "*",
-- AND/OR build from source, requires nightly:
-- https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
-- build = 'cargo build --release',
-- If you use nix, you can build from source using latest nightly rust with:
-- build = 'nix run .#build-plugin',
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
-- 'default' for mappings similar to built-in completion
-- 'super-tab' for mappings similar to vscode (tab to accept, arrow keys to navigate)
-- 'enter' for mappings similar to 'super-tab' but with 'enter' to accept
-- See the full "keymap" documentation for information on defining your own keymap.
keymap = {
preset = "enter",
},
completion = {
list = {
selection = {
preselect = function(ctx)
return ctx.mode ~= "cmdline"
end,
},
},
menu = {
-- nvim-cmp style menu
draw = {
columns = {
{ "label", "label_description", gap = 1 },
{ "kind_icon", "kind" },
},
},
},
documentation = { auto_show = true, auto_show_delay_ms = 500 },
ghost_text = { enabled = false },
},
appearance = {
-- 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 = true,
-- Set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- Adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono",
},
-- 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', 'ctags' },
default = { "lazydev", "lsp", "path", "snippets", "buffer", "ripgrep", "emoji" },
providers = {
lazydev = {
name = "LazyDev",
module = "lazydev.integrations.blink",
-- make lazydev completions top priority (see `:h blink.cmp`)
score_offset = 100,
},
emoji = {
module = "blink-emoji",
name = "Emoji",
score_offset = 15, -- Tune by preference
opts = { insert = true }, -- Insert emoji (default) or complete its name
-- should_show_items = function()
-- return vim.tbl_contains(
-- -- Enable emoji completion only for git commits and markdown.
-- -- By default, enabled for all file-types.
-- { "gitcommit", "markdown" },
-- vim.o.filetype
-- )
-- end,
},
ripgrep = {
module = "blink-ripgrep",
name = "Ripgrep",
-- the options below are optional, some default values are shown
---@module "blink-ripgrep"
---@type blink-ripgrep.Options
opts = {
-- For many options, see `rg --help` for an exact description of
-- the values that ripgrep expects.
-- the minimum length of the current word to start searching
-- (if the word is shorter than this, the search will not start)
prefix_min_len = 3,
-- The number of lines to show around each match in the preview
-- (documentation) window. For example, 5 means to show 5 lines
-- before, then the match, and another 5 lines after the match.
context_size = 5,
-- The maximum file size of a file that ripgrep should include in
-- its search. Useful when your project contains large files that
-- might cause performance issues.
-- Examples:
-- "1024" (bytes by default), "200K", "1M", "1G", which will
-- exclude files larger than that size.
max_filesize = "1M",
-- Specifies how to find the root of the project where the ripgrep
-- search will start from. Accepts the same options as the marker
-- given to `:h vim.fs.root()` which offers many possibilities for
-- configuration. If none can be found, defaults to Neovim's cwd.
--
-- Examples:
-- - ".git" (default)
-- - { ".git", "package.json", ".root" }
project_root_marker = { ".git", ".terraform", "requirements.txt", "lazy-lock.json" },
-- Enable fallback to neovim cwd if project_root_marker is not
-- found. Default: `true`, which means to use the cwd.
project_root_fallback = true,
-- The casing to use for the search in a format that ripgrep
-- accepts. Defaults to "--ignore-case". See `rg --help` for all the
-- available options ripgrep supports, but you can try
-- "--case-sensitive" or "--smart-case".
search_casing = "--ignore-case",
-- (advanced) Any additional options you want to give to ripgrep.
-- See `rg -h` for a list of all available options. Might be
-- helpful in adjusting performance in specific situations.
-- If you have an idea for a default, please open an issue!
--
-- Not everything will work (obviously).
additional_rg_options = {},
-- When a result is found for a file whose filetype does not have a
-- treesitter parser installed, fall back to regex based highlighting
-- that is bundled in Neovim.
fallback_to_regex_highlighting = true,
-- Absolute root paths where the rg command will not be executed.
-- Usually you want to exclude paths using gitignore files or
-- ripgrep specific ignore files, but this can be used to only
-- ignore the paths in blink-ripgrep.nvim, maintaining the ability
-- to use ripgrep for those paths on the command line. If you need
-- to find out where the searches are executed, enable `debug` and
-- look at `:messages`.
ignore_paths = {},
-- Any additional paths to search in, in addition to the project
-- root. This can be useful if you want to include dictionary files
-- (/usr/share/dict/words), framework documentation, or any other
-- reference material that is not available within the project
-- root.
additional_paths = {},
-- Features that are not yet stable and might change in the future.
-- You can enable these to try them out beforehand, but be aware
-- that they might change. Nothing is enabled by default.
future_features = {
-- Keymaps to toggle features on/off. This can be used to alter
-- the behavior of the plugin without restarting Neovim. Nothing
-- is enabled by default.
toggles = {
-- The keymap to toggle the plugin on and off from blink
-- completion results. Example: "<leader>tg"
on_off = "<leader>tg",
},
},
-- Show debug information in `:messages` that can help in
-- diagnosing issues with the plugin.
debug = false,
},
-- (optional) customize how the results are displayed. Many options
-- are available - make sure your lua LSP is set up so you get
-- autocompletion help
transform_items = function(_, items)
for _, item in ipairs(items) do
-- example: append a description to easily distinguish rg results
item.labelDetails = {
description = "(rg)",
}
end
return items
end,
},
},
},
},
opts_extend = { "sources.default" },
},
{
"neovim/nvim-lspconfig",
dependencies = {
"saghen/blink.cmp",
-- "netmute/ctags-lsp.nvim"
},
-- example using `opts` for defining servers
opts = {
servers = {
-- brew install rust-analyzer
rust_analyzer = {
settings = {
["rust-analyzer"] = {},
},
},
-- brew install bash-language-server
bashls = {},
-- lua_ls = {
-- settings = {
-- Lua = {
-- diagnostics = {
-- globals = { "vim" },
-- undefined_global = false, -- remove this from diag!
-- missing_parameters = false, -- missing fields :)
-- },
-- },
-- },
-- },
-- ctags_lsp = {},
},
},
config = function(_, opts)
local lspconfig = require("lspconfig")
--- brew install netmute/tap/ctags-lsp
-- require("lspconfig").ctags_lsp.setup({})
for server, config in pairs(opts.servers) do
-- passing config.capabilities to blink.cmp merges with the capabilities in your
-- `opts[server].capabilities, if you've defined it
config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities)
lspconfig[server].setup(config)
end
end,
},
}