DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
1.02k stars 19 forks source link

In-Line Hints (Variable Types) #389

Closed karimlevallois closed 2 months ago

karimlevallois commented 4 months ago

I have just come back to my laptop after a few weeks away, updated everything and now seeing these greyed out/ghosts in line hints for variable types etc.

Screenshot 2024-06-01 at 22 45 10

Is there a way to disable them?

Many thanks, Karim

DetachHead commented 4 months ago

these are called inlay hints. the setting to disable them depends on your editor. are you using neovim? if so, i'm not sure because i've never used it. @baco would you happen to know?

karimlevallois commented 4 months ago

I have always had inlay hints enabled, but I’ve never seen these before with basedpyright and they don’t show on pyright or pylance either. Is it something recently added?

DetachHead commented 4 months ago

inlay hints were added in version 1.5.0. the reason you didn't see them in pyright is because they are a pylance-exclusive feature. unlike pylance though, they are enabled by default in basedpyright, and can be turned off in vscode by setting "editor.inlayHints.enabled": "off" to "off".

karimlevallois commented 4 months ago

These have only started showing the past few weeks, since I last used Neovim. I know inlay hints have been working as I’ve set diagnostics to ‘Standard’ and had that for a couple of months. These however that give details on the variables before them have never shown before. Can I disable these specific ones rather than all inlay hints?

DetachHead commented 4 months ago

so you only want inlay hints on function parameter names but not on assignments to variables?

we haven't made any changes to inlay hints recently so im not sure what could've caused this change in behaviour. if you could create a minimal reproduction of an inlay hint that wasn't present on an older version, i can investigate.

we could also add options to customize which types of inlay hints are displayed.

baco commented 4 months ago

Hi. I may need more info... First, some clarifications: Pylance never worked as an LSP server for Neovim (it has some proprietary stuff that the Neovim+Python community was never interested to deal with). You may be using Pyright, but Pyright on Neovim, only works as a type checker and an auto-completion engine (the part of Pyright Microsoft didn't chop off to move it to Pylance). For instance, it doesn't implement diagnostics.

I am curious on how were you able to have InlayHints “always on”. That, as a feature, came (for all LSP servers at the same time) a few weeks ago with the release of Neovim 0.10; and no other LSP sever (despite BasedPyright) implements it for Python. Are you using CoC.nvim as a client instead of native Neovim's LSP-client feature? Are you confused with virtual-text, which is mostly used for diagnostics, because of their similarities (with InlayHints) in showing up, but not being reachable by keystrokes?

If the InlayHint is the only feature that's bothering you, you'll have to look on your Neovim's config where is being turned on, and comment out that part. Look if you have something like:

...
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
...

in your settings.

Are you using a Neovim-distro? They are very common (NvimChad, AstroNvim, etc.) and the tend to turn stuff on, that the user didn't know it was there.

If you want to turn it off, maybe you can add an extra setting for doing that explicitly:

vim.lsp.inlay_hint.enable(false)

but that's the default, so... if you are using some Neovim distro, perhaps you can comment out the part that's turning it on in the first place.

baco commented 4 months ago

For instance (colors may vary on your theme): image

karimlevallois commented 4 months ago

Hi. I may need more info... First, some clarifications: Pylance never worked as an LSP server for Neovim (it has some proprietary stuff that the Neovim+Python community was never interested to deal with). You may be using Pyright, but Pyright on Neovim, only works as a type checker and an auto-completion engine (the part of Pyright Microsoft didn't chop off to move it to Pylance). For instance, it doesn't implement diagnostics.

I am curious on how were you able to have InlayHints “always on”. That, as a feature, came (for all LSP servers at the same time) a few weeks ago with the release of Neovim 0.10; and no other LSP sever (despite BasedPyright) implements it for Python. Are you using CoC.nvim as a client instead of native Neovim's LSP-client feature? Are you confused with virtual-text, which is mostly used for diagnostics, because of their similarities (with InlayHints) in showing up, but not being reachable by keystrokes?

If the InlayHint is the only feature that's bothering you, you'll have to look on your Neovim's config where is being turned on, and comment out that part. Look if you have something like:

...
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
...

in your settings.

Are you using a Neovim-distro? They are very common (NvimChad, AstroNvim, etc.) and the tend to turn stuff on, that the user didn't know it was there.

If you want to turn it off, maybe you can add an extra setting for doing that explicitly:

vim.lsp.inlay_hint.enable(false)

but that's the default, so... if you are using some Neovim distro, perhaps you can comment out the part that's turning it on in the first place.

Hey!

I have pylance via a rather hacky method, but it is fully functional for the most part.

I’ve been running the nightly version of Neovim for months and using standard LSP.

Ah, I may well be thinking of virtual text then, the diagnostics element at the end of the lines in red… that mostly disappear when using ‘Standard’ for diagnostics.

Will disable inlay hints then and hopefully it will go.

Thanks for your help, much appreciated.

baco commented 4 months ago

I have pylance via a rather hacky method, but it is fully functional for the most part.

Ok, now I am more curious on the how. Because even VSCodium people are struggling to get it working, and VSCodium shares everything with VSCode, except for the telemetry and branding, and that's where having BasedPyright shines (in VSCodium). But that may be topic for another thread/discussion; I'm not that curious, I prefer FLOSS.

I’ve been running the nightly version of Neovim for months and using standard LSP.

Ok, I understand now. Maybe start with that, next time. It's useful to know what set of features you may or may not have, beforehand.

Ah, I may well be thinking of virtual text then, the diagnostics element at the end of the lines in red… that mostly disappear when using ‘Standard’ for diagnostics.

Yup, that makes sense then. BasedPyright controls the amount of diagnostics shown by the setting you mention. In Neovim, those diagnostics are shown via the Virtual Text feature; not the Inlay Hint feature, rather used for inferred typing and argument's names.

Will disable inlay hints then and hopefully it will go.

Regarding that, if the setting was turned-on already, I recommend you search where is being turned on, because “on” is not the default value. I mean, to avoid turning off, something that was just turned on. You may save some startup time if not turning it on at all in first place.

It may also be of help, either you leave it on or off by default, to add a keymap on Neovim to toggle the state. I have the following in Lua:

local opts = { noremap=true, silent=true, buffer=args.buf }
vim.keymap.set("n", "<Leader>ih", function()
  vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, opts)

With that, I can turn it on/off on demand pressing the Leader key, plus i, plus h.

Thanks for your help, much appreciated.

No problem at all. Thanks for reaching out. Tell us if that solved your orignal issue so we may close this report.

DetachHead commented 2 months ago

closing this as issue as per the above comment. feel free to raise another issue if you have any further questions