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

setup cmp window, item.abbr maxwidth and minwidth #361

Open
wants to merge 8 commits into
base: v3.0
Choose a base branch
from

Conversation

Song-Tianxiang
Copy link

Sometimes, cmp completion window, item.abbr too long. this commit can restrict item.abbr width. Maybe the default maxwidth and minwidth can be adjust.

before:
Screenshot 2024-10-10 at 8 25 52 PM

after:
Screenshot 2024-10-10 at 8 25 17 PM

@siduck
Copy link
Member

siduck commented Oct 10, 2024

is there not a better way to do this :/ , i dont like such computations in cmp config as it'd render on every keystroke!

@lucario387
Copy link
Collaborator

It's looking way too similar to this hrsh7th/nvim-cmp#980 (comment)

@Song-Tianxiang
Copy link
Author

Song-Tianxiang commented Oct 10, 2024

is there not a better way to do this :/ , i dont like such computations in cmp config as it'd render on every keystroke!有没有更好的方法来做到这一点:/,我不喜欢 cmp 配置中的此类计算,因为它会在每次击键时呈现!

I think there's two ways to solve:

  1. set a constant number but less flexible
  2. compute once and save it, but since vim.o.columns would updated when window resiezed, maybe we need a autocmd VimResized

@Song-Tianxiang
Copy link
Author

It's looking way too similar to this hrsh7th/nvim-cmp#980 (comment)它看起来和这个太相似了 hrsh7th/nvim-cmp#980 (comment)

shamelessly stole from there

@@ -26,7 +26,7 @@ local M = {

-- item.abbr maxwidth and minwidth
local ellipsis_char = '…'
local abbr_maxwidth = math.floor(vim.o.columns / 2)
local abbr_maxwidth = 29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

au VimResized with a variable storing the width will be better (if it's possible)

exposed an option ` cmp.format_abbr` to user:
```
    cmp        = {
        format_abbr = {
            maxwidth = 20,
            minwidth = 20,
        }
    }
```
@Song-Tianxiang
Copy link
Author

I have added an option cmp.format_abbr.
the current nvconfig.ui.cmp is

    cmp = {
        icons_left = false, -- only for non-atom styles!
        lspkind_text = true,
        style = "default", -- default/flat_light/flat_dark/atom/atom_colored
        format_colors = {
            tailwind = false, -- will work for css lsp too
            icon = "󱓻",
        },
        format_abbr = {
            maxwidth = 20,
            minwidth = 10,
        }
    },

How about make it look like:

    cmp = {
        icons_left = false, -- only for non-atom styles!
        lspkind_text = true,
        style = "default", -- default/flat_light/flat_dark/atom/atom_colored
        format = {
            colors = {
                tailwind = false, -- will work for css lsp too
                icon = "󱓻",
            },
            abbr = {
                maxwidth = 20,
                minwidth = 10,
            }
        },
    }

Its' more clean but not back compatiable (we need to use cmp.format_colors or cmp.format.colors).

There's maybe other cmp.format.[something] in the future though.

@siduck
Copy link
Member

siduck commented Oct 11, 2024

ugh i dislike such large & complex changes :/

cant we just use string:sub?

I can not find a better way...
@Song-Tianxiang
Copy link
Author

I don’t think I can come up with a better solution...

@Song-Tianxiang
Copy link
Author

Does adding this autocmd make the code seem too complex to you? The entire cost of this commit is that for each completion item, it needs to determine if it is too long, which is an unavoidable cost. The cost of the autocmd is almost negligible.

@siduck
Copy link
Member

siduck commented Oct 13, 2024

dont close this yet, i dont think the autocmd is much of useful, I want the user to keep a fixed maxwidth. not depending on the nvim's window size.

@siduck siduck reopened this Oct 13, 2024
@siduck siduck force-pushed the v3.0 branch 2 times, most recently from 8b670b9 to 5be808e Compare October 29, 2024 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants