Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow configuring cmp label shorten length #127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions lua/supermaven-nvim/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local CompletionPreview = require("supermaven-nvim.completion_preview")
local config = require("supermaven-nvim.config")
local u = require("supermaven-nvim.util")

local loop = u.uv
Expand All @@ -8,13 +9,14 @@ local source = { executions = {} }
local label_text = function(text)
local shorten = function(str)
local short_prefix = string.sub(str, 0, 20)
local short_suffix = string.sub(str, string.len(str) - 15, string.len(str))
local delimiter = " ... "
local suffix_length = config.cmp_label_shorten_length - 23
local short_suffix = string.sub(str, string.len(str) - suffix_length, string.len(str))
local delimiter = " … "
return short_prefix .. delimiter .. short_suffix
end

text = text:gsub("^%s*", "")
return string.len(text) > 40 and shorten(text) or text
return string.len(text) > config.cmp_label_shorten_length and shorten(text) or text
end

function source.get_trigger_characters()
Expand Down
1 change: 1 addition & 0 deletions lua/supermaven-nvim/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local default_config = {
return false
end,
log_level = "info",
cmp_label_shorten_length = 40,
}

local M = {
Expand Down