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

improvement: Use inlay hints for worksheets #6827

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Oct 7, 2024

inlay-worksheets

Advantages:

  • this would allow us to stop using a custom extension and support more editors such as Zed
  • can reuse any new enhancement to inlay hints

Disadvantages:

  • no way to set color
  • could mix with normal decorations

I plan on removing decoration protocol and worksheet fallback in this PR

TODO

  • remove worksheet publishers
  • add specific test to using inlay hints

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 17, 2024

@ckipp01 do you know if inlay hints would work ok for nvim-metals? I want to remove as many custom extensions as I can since we get more and more editors and implementing those custom extension might be too much of a hassle.

@tgodzik tgodzik force-pushed the switch-inlay-hints branch 3 times, most recently from 8084e55 to 4994a1f Compare November 17, 2024 17:14
@ckipp01
Copy link
Member

ckipp01 commented Nov 18, 2024

@ckipp01 do you know if inlay hints would work ok for nvim-metals?

Yup, inlay hints are supported in nvim, so this should work. If I get a bit of time I'll try this pr out with nvim-metals and see if I hit on any issues.

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 18, 2024

@ckipp01 do you know if inlay hints would work ok for nvim-metals?

Yup, inlay hints are supported in nvim, so this should work. If I get a bit of time I'll try this pr out with nvim-metals and see if I hit on any issues.

Thanks! I think I mostly need to fix tests here. I will also see how Zed handles it since I managed to get that set up for myself.

@dragove
Copy link

dragove commented Nov 19, 2024

I did some test on nvim-metals. here are my feedbacks.

  1. Evaluation results showed using inlay hints style as expected.
  2. Adding a character to make code not compilable and the inlay hints not go away (while vscode only shows the error and hindes the inlay hints)
  3. Deleting the character to make code compilable again then I can not see the evaluation results.
  4. use :e to reload the file things get working again.

There is one thing should be mentioned. Using inlay hints also means disabling editor's inlay hints feature will cause results not showing. Example configs are:

  1. vscode's "editor.inlayHints.enabled": "off"
  2. neovim's vim.lsp.inlay_hint.enable(false)

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 19, 2024

Adding a character to make code not compilable and the inlay hints not go away (while vscode only shows the error and hindes the inlay hints)

Looks like maybe it's because of lacking inlayHints/refresh ? Does neovim support that?

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 19, 2024

There is one thing should be mentioned. Using inlay hints also means disabling editor's inlay hints feature will cause results not showing. Example configs are:

Sure, but it's enabled by default (at least in VS Code) and other editor users might be sued to turning things on. We need to write about it in the release notes for sure.

@tgodzik tgodzik force-pushed the switch-inlay-hints branch 2 times, most recently from 2180ce1 to 00e1925 Compare November 20, 2024 10:18
Advantages:
- this would allow us to stop using a custom extension and support more editors such as Zed
- can reuse any new feature inlay hints add
- reevaluate on change? (or should we remove it?)

Disadvantages:
- no way to set color
- could mix with normal decorations

TODO:

- [ ] gather feedback
- [ ] fix tests
- [ ] check if we can remove other ways of publishing altogether
@tgodzik tgodzik force-pushed the switch-inlay-hints branch 2 times, most recently from fb1cc3d to 476256a Compare December 7, 2024 19:16
@tgodzik tgodzik force-pushed the switch-inlay-hints branch from 476256a to ec2a1b6 Compare December 8, 2024 20:31
@tgodzik tgodzik marked this pull request as ready for review December 9, 2024 08:54
@tgodzik tgodzik requested a review from kasiaMarek December 9, 2024 08:54
@tgodzik tgodzik force-pushed the switch-inlay-hints branch from ec2a1b6 to d60c695 Compare December 9, 2024 09:02
@tgodzik tgodzik force-pushed the switch-inlay-hints branch from d60c695 to 1f0aa91 Compare December 9, 2024 10:06
Comment on lines +19 to +20
"as a inlay hint at the end of the line." ->
"hover on the inlay hint to expand it."
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't it be more editors than only vscode that support inline hints? Also aren't worksheet decorations using comments not supported after this PR?

getLabelParts(inlayHint).zip(parseData(data))
Option(inlayHint.getData()) match {
case Some(data: JsonArray) =>
resolve(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you move resolve to try?

Comment on lines 983 to +985
.map(_.map(_.toLsp()))
.map(
_.orElse {
val path = params.textDocument.getUri.toAbsolutePath
if (path.isWorksheet)
worksheetProvider.hover(path, params.getPosition)
else
None
}.orNull
_.orNull
Copy link
Contributor

Choose a reason for hiding this comment

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

 .map(_.map(_.toLsp()).orNull)

@@ -1016,7 +997,11 @@ abstract class MetalsLspService(
if (userConfig.areSyntheticsEnabled())
compilers.inlayHints(params, token)
else Future.successful(List.empty[l.InlayHint].asJava)
} yield hints
worksheet <- worksheetProvider.inlayHints(
params.getTextDocument().getUri().toAbsolutePath,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
params.getTextDocument().getUri().toAbsolutePath,
params.getTextDocument().getUri().toAbsolutePathSafe,

Comment on lines +215 to +220
distance.toRevised(statEnd) match {
case Left(_) =>
case Right(right) =>
statEnd.setLine(right.startLine)
statEnd.setCharacter(right.startColumn)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
distance.toRevised(statEnd) match {
case Left(_) =>
case Right(right) =>
statEnd.setLine(right.startLine)
statEnd.setCharacter(right.startColumn)
}
distance.toRevised(statEnd).foreach { right =>
statEnd.setLine(right.startLine)
statEnd.setCharacter(right.startColumn)
}

_ = client.onWorkDoneProgressStart = (_, _) => {}
_ <- cancelled.future.withTimeout(10.seconds)
_ = client.onWorkDoneProgressStart = (message, _) => {
scribe.info(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

?

@@ -266,6 +208,7 @@ abstract class BaseWorksheetLspSuite(
cleanWorkspace()
val cancelled = Promise[Unit]()
client.onWorkDoneProgressStart = { (message, cancelParams) =>
scribe.info(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

?

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.

4 participants