Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 67 additions & 102 deletions lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,110 +1,75 @@
-- copied from cmp-under, but I don't think I need the plugin for this.
-- I might add some more of my own.
local function under_cmp(entry1, entry2)
local _, entry1_under = entry1.completion_item.label:find("^_+")
local _, entry2_under = entry2.completion_item.label:find("^_+")
entry1_under = entry1_under or 0
entry2_under = entry2_under or 0
if entry1_under > entry2_under then
return false
elseif entry1_under < entry2_under then
return true
end
end
---@param entry1 cmp.Entry
---@param entry2 cmp.Entry
local function snippets_down(entry1, entry2)
local types = require("cmp.types")
local kind1, kind2 = entry1:get_kind(), entry2:get_kind()
local Snippet = types.lsp.CompletionItemKind.Snippet
if kind1 == Snippet then
-- Only return if 2 is not a snippet
if kind2 ~= Snippet then return false end
elseif kind2 == Snippet then
return true
else -- Neither is a snippet, ignore it
return
end
-- Both are snippets, discourage nvim_lsp snippets
if entry1.source.name == "nvim_lsp" then return false end
if entry2.source.name == "nvim_lsp" then return true end
end

---@type LazySpec
return {
-- auto completion
{
"hrsh7th/nvim-cmp",
version = false, -- last release is way too old
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
},
opts = function()
local cmp = require("cmp")
local compare = cmp.config.compare
return { ---@type cmp.ConfigSchema
-- Change border of documentation hover window, See https://github.com/neovim/neovim/pull/13998.
window = { completion = { border = "rounded" }, documentation = { border = "rounded" } },
completion = { completeopt = "menu,menuone,noinsert" },
mapping = cmp.mapping.preset.insert({
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }), -- Accept without explicit selection
["<S-CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<C-CR>"] = function(fallback)
cmp.abort()
fallback()
end,
}),
sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "path" } }, { { name = "buffer" } }),
formatting = { ---@type cmp.FormattingConfig|{}
format = function(_, item)
local icons = require("config.icons").kinds
if icons[item.kind] then item.kind = icons[item.kind] .. item.kind end
return item
end,
"saghen/blink.cmp",
version = "*",
opts_extend = { "sources.completion.enabled_providers", "sources.default" },
dependencies = { "rafamadriz/friendly-snippets" },
event = { "InsertEnter", "CmdlineEnter" },
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
snippets = { preset = "default" },
appearance = {
nerd_font_variant = "mono",
kind_icons = require("config.icons").kinds,
},
completion = {
accept = {
auto_brackets = { enabled = false },
},
performance = { ---@type cmp.PerformanceConfig|{}
trigger_debounce_time = 500,
throttle = 550,
fetching_timeout = 80,
menu = {
border = "rounded",
draw = {
treesitter = { "lsp" },
},
},
experimental = { ghost_text = false }, -- Don't show the ghost text
sorting = {
priority_weight = 2,
comparators = {
compare.offset,
compare.exact,
snippets_down,
compare.score,
compare.recently_used,
compare.locality,
under_cmp,
compare.scopes, -- prioritize values in scope order
compare.kind, -- superseded by lsp_first -- just used for lowering text
compare.sort_text,
compare.length,
compare.order,
documentation = {
auto_show = true,
auto_show_delay_ms = 200,
window = {
border = "rounded",
},
},
}
end,
---@param opts cmp.ConfigSchema
config = function(_, opts)
for _, source in ipairs(opts.sources) do
source.group_index = source.group_index or 1
end
require("cmp").setup(opts)
end,
},
sources = {
default = { "lsp", "buffer", "path", "snippets" },
},
cmdline = {
enabled = true,
keymap = {
preset = "cmdline",
["<Right>"] = false,
["<Left>"] = false,
},
completion = {
list = { selection = { preselect = false } },
menu = { auto_show = function() return vim.fn.getcmdtype() == ":" end },
ghost_text = { enabled = true },
},
},
keymap = {
preset = "enter",
["<C-y>"] = { "select_and_accept" },
},
},
},

-- lazydev
{
"saghen/blink.cmp",
opts = {
sources = {
per_filetype = {
lua = { inherit_defaults = true, "lazydev" },
},
providers = {
lazydev = {
name = "LazyDev",
module = "lazydev.integrations.blink",
score_offset = 100, -- show at a higher priority than lsp
},
},
},
},
},
}
16 changes: 3 additions & 13 deletions lua/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ return {

--- Capabilities
local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
local has_blink, blink = pcall(require, "blink.cmp")
local capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
has_cmp and cmp_nvim_lsp.default_capabilities() or {}
has_cmp and cmp_nvim_lsp.default_capabilities() or {},
has_blink and blink.get_lsp_capabilities() or {}
)
vim.lsp.config("*", { capabilities = capabilities })
end,
Expand Down Expand Up @@ -112,17 +114,5 @@ return {
},
},
},
{ -- optional completion source for require statements and module annotations
"hrsh7th/nvim-cmp",
optional = true,
opts = function(_, opts)
_ = _ ---@module 'cmp'
opts.sources = opts.sources or {} ---@type cmp.SourceConfig[]
opts.sources[#opts.sources + 1] = {
name = "lazydev",
group_index = 0, -- set group index to 0 to skip loading LuaLS completions
}
end,
},
-- { "justinsgithub/wezterm-types", lazy = true },
}
10 changes: 1 addition & 9 deletions lua/plugins/luasnip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ return {
build = (not jit.os:find("Windows"))
and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp"
or nil,
dependencies = { "rafamadriz/friendly-snippets", "nvim-cmp" },
dependencies = { "rafamadriz/friendly-snippets" },
opts = { history = true, delete_check_events = "TextChanged" },
-- Note: <tab> in insert is handled in keymaps.lua
keys = {
Expand All @@ -25,14 +25,6 @@ return {
"rafamadriz/friendly-snippets",
config = function(self) return require("luasnip.loaders.from_vscode").lazy_load({ paths = self._.dir }) end,
},
{
"nvim-cmp",
dependencies = { "saadparwaiz1/cmp_luasnip" },
opts = function(_, opts)
opts.snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end }
table.insert(opts.sources, { name = "luasnip" })
end,
},
{
"chrisgrieser/nvim-scissors",
dependencies = "nvim-telescope/telescope.nvim",
Expand Down
13 changes: 0 additions & 13 deletions snippets/html.jsonc
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
{
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"insert_strong": {
"prefix": ["strong", "s", "b", "bold"],
"body": ["<strong>$TM_SELECTED_TEXT$0</strong>"],
Expand Down
13 changes: 0 additions & 13 deletions snippets/java.jsonc
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
{
// Place your snippets for java here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"System.out": {
"prefix": ["sysout", "stdout"],
"body": "System.out.println(${1:$TM_SELECTED_TEXT}",
Expand Down
10 changes: 0 additions & 10 deletions snippets/javascript.jsonc
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": ["console.log('$1');", "$2"],
// "description": "Log output to console"
// },
"For loop i++": {
"prefix": "for",
"body": [
Expand Down
13 changes: 0 additions & 13 deletions snippets/shellscript.jsonc
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
{
// Place your snippets for shellscript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Get User Confirmation": {
"prefix": "confirm",
"description": "Get a user's confirmation, default to yes",
Expand Down
Loading