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

[WIP] Use inlay hints to render captures #34

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jiribenes
Copy link
Contributor

@jiribenes jiribenes commented Nov 7, 2024

Very WIP, but here are a few screenshots:

image

Screenshot 2024-11-07 at 22 46 59 Screenshot 2024-11-07 at 22 46 30

A short-term goal is to retire the current hacky implementation of rendering inferred captures (by using inlay hints instead).
A long-term goal would be to use inlay hints as a proper mechanism on the server side (relevant to effekt-lang/effekt#524)

Resolves #32 (mostly by accident)

Current issues / TODOs:

  • I have no idea how the inferredCaptures API works, sometimes it's weirdly invalidated? (If I figure out what I should want, we could even change the Effekt compiler here...)
  • The editor currently asks for the captures very often, can we only ask for them on save?
  • Re-add showCaptures, add to docs that one needs to enable inlay hints in the editor globally (as a feature)
  • Remove the leftover commented-out code
  • Remove the DEBUG logger
  • Take a look if the holes code can also be replaced by this perhaps? (probably not though)

src/extension.ts Outdated
Comment on lines 89 to 99
const result = await client.sendRequest(ExecuteCommandRequest.type, {
command: "inferredCaptures",
arguments: [{ uri: document.uri.toString() }]
}) as { location: vscode.Location, captureText: string }[];

log("Inlay hints result: " + JSON.stringify(result));

if (!result) {
log("No results returned.");
return hints;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes the backend just returns null, no idea why.

src/extension.ts Outdated Show resolved Hide resolved
@b-studios
Copy link
Collaborator

Sometimes it's a bit much to see them. What's the expected UX?

Should we even show empty captures?

@jiribenes
Copy link
Contributor Author

jiribenes commented Nov 7, 2024

Sometimes it's a bit much to see them. What's the expected UX?

Agreed. The use case is teaching ( / demos ) and debugging. So roughly the same as it is right now.

In order to see the captures, you'll have to enable showCaptures in the Effekt VSCode plugin config and enable inlay hints in the VSCode config. So even more complicated than it is right now :)
If you wanna go further, some people have offUnlessPressed set in VSVode so that the inlay hints show up only on some key combo (like they do in IntelliJ).

It also serves as a tiny proof of concept of how we could even use inlay hints in the future. (It's a super rough WIP experiment since I though "well how hard could it be".)

Should we even show empty captures?

Yes, I think it's worth it for both of the mentioned use cases.


EDIT: For clarity, here's how you can set up how your inlay hints look in VSCode:
(+ then you can customise them in your theme):
Screenshot 2024-11-07 at 22 50 52
Screenshot 2024-11-07 at 22 50 46

Comment on lines +112 to +115
// Truncate long captures ourselves.
// TODO: Does this make sense? Shouldn't we at least show the first one?
// TODO: Can the backend send them in a list so that we can have a somewhat stable (alphabetic?) order?
const hintText = response.captureText.length > 30 ? "{…}" : response.captureText;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

VSCode actively truncates inlay hints that are too long (something like 34 chars?), therefore it's better that we try to truncate ourselves. We can bike shed the proper constant here, but should we show at least some captures like {async, io, Exception, ...} or should we just go to {...} in such a case (and rely only on the hover like in the screenshot above?)

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.

Illegible captures in dark themes
2 participants