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

Truncate long inlay hints #27240

Open
MariaSolOs opened this issue Jan 28, 2024 · 5 comments
Open

Truncate long inlay hints #27240

MariaSolOs opened this issue Jan 28, 2024 · 5 comments
Labels
enhancement feature request lsp

Comments

@MariaSolOs
Copy link
Member

Problem

microsoft/vscode#199610 explains the problem, but the TLDR is that some language servers (like the TypeScript one) don't perform any truncation on inlay hints, which might result on several lines of virtual text.

Expected behavior

My proposal is to add a configuration setting (and hence easily customizable with vim.lsp.with) that limits the length of inlay hints.

@MariaSolOs MariaSolOs added the enhancement feature request label Jan 28, 2024
@wookayin wookayin added the lsp label Jan 28, 2024
@MariaSolOs
Copy link
Member Author

And as always, if people find this reasonable I'm more than happy to implement it :)

@GitMurf
Copy link

GitMurf commented Apr 14, 2024

Did anything come of this? looks like the PR was cancelled. Curious if you have any workarounds currently? I use TS mainly and have to disable includeInlayVariableTypeHints because many types/interfaces are too large inline especially for objects. I would love to be able to just add like a max length of 30 or 40 characters which for most types would give me what I need but for larger ones I atleast get an idea of the type/shape from the first 30 or 40 characters.

@MariaSolOs
Copy link
Member Author

@GitMurf as a user (and maintainer) of TypeScript I understand your pain.

There's still a design discussion of whether this truncation should happen on the server or the client: The client would be able to provide "more universal" truncation mechanisms for several language servers, but the server is able to provide a "smarter" truncation based on what's semantically relevant.

I'm partly responsible (okay yeah it's my fault) for the issue with TypeScript, since I removed the truncation when working on interactive inlay hints. However, the TypeScript server did nothing smart about truncation; it had a hard-coded limit of 30 characters and just cut the inlay hint label after that.

All that being said, the following is my personal hack, which I don't recommend as a long term solution and I absolve myself from all negative consequences if you decide to copy-paste this into your dotfiles: https://github.com/MariaSolOs/dotfiles/blob/88646ab9bd20d6f36dacea0cdee8b6af3ffc4c50/.config/nvim/lua/lsp.lua#L275-L292

The above code should kind of reproduce the previous TypeScript behaviour.

@GitMurf
Copy link

GitMurf commented Apr 14, 2024

@MariaSolOs you are awesome! Love your work btw on both TS and neovim! saw your talk in the neovim annual conference. Appreciate all you do! That "hack" is exactly what I was looking for now!

I also think an alternative "solution" (or helpful) would be this gh issue (#28261) for choosing to push inlay hints to end of line. Definitely not perfect, and lose some value, but it would be less disruptive to the code flow IMO.

Lastly, I am also using your toggle on insert mode autocmds from here: #24305 Thanks!

@MariaSolOs
Copy link
Member Author

@GitMurf thanks for the kind words, it truly means a lot <3

I've replied to the issue you linked. I'm trying to make everyone happy, remaining on what the LSP currently allows (we can always propose for a change though ;) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request lsp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants