nil icon indicating copy to clipboard operation
nil copied to clipboard

Hover support

Open DieracDelta opened this issue 1 year ago • 1 comments

I'm interested in adding hover support to get type information. I'm mostly interested in the trivial cases for now. Stubbing out a hover function is not too hard, but I'm wondering what the right way to get definition information is. Like the other passes, I can see grabbing a syntax node based on the cursor position, then traversing its ancestors until we hit something interesting. That's where I get confused. Suppose we want the type of some named variable v in an attrset. { v = 3; } for example.

I can manually go up and find the parent syntax node, then get the syntaxnode of the rhs. Or I can go up to the ATTRSET node and then get the exprid corresponding to the node's name from the module map. But then that syntax node needs to be evaluated in order to get type information out, and it's unclear how to do this. Does this sort of functionality exist in the code anywhere?

DieracDelta avatar Aug 22 '22 01:08 DieracDelta

I'm interested in adding hover support to get type information. Does this sort of functionality exist in the code anywhere?

Not yet. Type inference is planned. I'll work on single-file type inference later this week (hopefully), after amending attrset desugaring stuff. It currently still has troubles finding locations of merged bindings.

Suppose we want the type of some named variable v in an attrset. { v = 3; } for example. I can manually go up and find the parent syntax node, then get the syntaxnode of the rhs. Or I can go up to the ATTRSET node and then get the exprid corresponding to the node's name from the module map.

Typically we'll select the deepest interested node which completely covers the selecting range, which is what rust-analyzer did. So selecting v will give you the ATTR node (or ATTRPATH_VALUE?) but { gives you the whole ATTRSET.

oxalica avatar Aug 23 '22 15:08 oxalica

Hover text is implemented in f94b668d25769473d32041b498e8fb58c3ff93c3. It currently shows where the name comes from, as well as documentations for builtin names.

I opened an individual tracking issue #14 for type system. I'll close this.

oxalica avatar Sep 22 '22 15:09 oxalica