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

code action/double click to transition inlay hints to real life #198

Open
KotlinIsland opened this issue Mar 25, 2024 · 8 comments
Open
Labels
language server LSP: code actions LSP: inlay hints pylance parity feature that exists in pylance but not pyright / bug specific to our impl of a pylance feature

Comments

@KotlinIsland
Copy link
Collaborator

KotlinIsland commented Mar 25, 2024

Before

backticks represent inlay hints

class A: ...
a`: A` = A()

After

class A: ...
a: A = A()
@KotlinIsland
Copy link
Collaborator Author

@KotlinIsland KotlinIsland changed the title code action to transition inlay hints to real life code action/double click to transition inlay hints to real life Apr 21, 2024
@DetachHead
Copy link
Owner

something i noticed about pylance's implementation of this feature is that it doesn't work on all inlay hints for some reason. eg:

def f(a: int, /) -> str: ...

x = f  # works

foo = "" # doesn't work

image

imo inlay hints should always be valid code, so they should always allow double-clicking to insert them

@NCBM
Copy link
Contributor

NCBM commented Jul 16, 2024

something i noticed about pylance's implementation of this feature is that it doesn't work on all inlay hints for some reason. eg:

def f(a: int, /) -> str: ...

x = f  # works

foo = "" # doesn't work

image

Recently I tested the case once doesn't work and it worked now (Pylance v2024.7.1).

image

image

Auto-import from typing is even done.

imo inlay hints should always be valid code, so they should always allow double-clicking to insert them

Actually there are also inlay hints which are not valid code, e.g.

a, b = "foo", int()  # `a` is shown nothing while `b` is shown as `int` in inlay hints.

c = 42  # `c` is shown nothing in inlay hints. hovering mouse cursor to see the type.

image

of course they cannot be inserted.

Another thing we can notice is that some not-quite-useful Literals are sometimes not shown.

@DetachHead
Copy link
Owner

oops, in my example i had it the wrong way around. it's the Callable inlay hint that doesn't work:

def f(a: int, /) -> str: ...

x = f  # doesn't work

foo = "" # works

related: #199

@NCBM
Copy link
Contributor

NCBM commented Jul 19, 2024

maybe Callable inlay hints are considered complex by pylance that should be assigned to a type alias?

@KotlinIsland
Copy link
Collaborator Author

KotlinIsland commented Jul 19, 2024

maybe Callable inlay hints are considered complex by pylance that should be assigned to a type alias?

Such a based idea:

def f(a=1, /, *, b=False):
    return 1

a = f

After transition operation:

class F(Protocol): # maybe "A"?
    def __call__(self, a: int = ..., /, *, b: bool = ...) -> int: ...

a: F = f

@npip99
Copy link

npip99 commented Sep 23, 2024

I personally use inlay for maximum information possible, so I'd rather just max info in all situations (I've never used the feature to bring inlay hints into real life / it wouldn't matter to me personally inlay hints aren't valid syntax)

Could be a config option though, to disable invalid inlay hints; maybe there's an option for the LSP to throw an error dialog if you try an action but it fails, e.g. for trying to bring invalid inlay hints to real life.

If there are two options that provide the same information, but one was valid and the other was invalid, yeah prefer the valid. It would also make more sense.

-> Just my thoughts, not saying that's the avg thought or anything.

@npip99
Copy link

npip99 commented Sep 27, 2024

Interesting potential edge cases -

It's also keyword arguments that appear but aren't actually keyword. E.g., dt.datetime.fromisoformat(date_string=user.timezone), date_string in this case is not a valid keyword argument.

Inlay hints currently don't use namespaces.

my_datetime: datetime = dt.datetime.fromisoformat(my_str)
In this case, : datetime is an inlay hint, but it should be dt.datetime to namespace correctly. Might be nicer to read dt.datetime too, so that it matches how you're using it in the code (dt.datetime.fromisoformat).

--
Currently also has an effect if e.g. using the mouse to copy code with inlay hints, from a terminal to a repl, which then fails on the repl due to invalid type hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language server LSP: code actions LSP: inlay hints pylance parity feature that exists in pylance but not pyright / bug specific to our impl of a pylance feature
Projects
None yet
Development

No branches or pull requests

4 participants