Skip to content

Conversation

@lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Jun 7, 2023

Adding ability to show the inline hints (using "inlayHints" of the LSP), showing the same hints as for NetBeans. Enabled by default, but can be adjusted either in global settings (Editor/Inlay Hints), or individual Java-specific capabilities can be enabled/disabled in the extension settings.

It looks like this:
inlay-hints


^Add meaningful description above

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.

If you're a first time contributor, see the Contributing guidelines for more information.

If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.

js.runUserActionTask(cc -> {
cc.toPhase(JavaSource.Phase.RESOLVED);
Preferences preferences = NbPreferences.root().node("/org/netbeans/modules/java/editor/InlineHints/default");
preferences.putBoolean(JAVA_INLINE_HINT_PARAMETER_NAME, enabled.contains("parameter"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Preferences.put!? Quite a hacky solution. I'd replace this with "branding API"_ and specified different default in nbcode suite.

@jtulach
Copy link
Contributor

jtulach commented Jun 13, 2023

From end user perspective, the solution is really great:

TreeToIr.java

it will make it way easier for me to work with Enso code base.

@jtulach jtulach self-requested a review June 13, 2023 12:49
@jtulach
Copy link
Contributor

jtulach commented Jun 16, 2023

Btw. Metals - the VSCode support for Scala is using Italics to render the additional inline hints:

image

@lahodaj lahodaj force-pushed the inline-hints-vscode branch from 5dbbf28 to f54619a Compare March 1, 2024 20:13
@lahodaj lahodaj added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension labels Feb 4, 2025
@lahodaj lahodaj added this to the NB26 milestone Feb 4, 2025
@apache apache locked and limited conversation to collaborators Feb 4, 2025
@apache apache unlocked this conversation Feb 4, 2025
@lahodaj
Copy link
Contributor Author

lahodaj commented Feb 10, 2025

I've updated the patch, make a general provider (so that other languages can contribute as well), the settings in package.json are better now, changed the default in the extension to not produce any inline hints by default. The default in the server if there's no configuration at all is to produce all the hints.

Any insights/feedback? Might be good to finalize this at some point.

Thanks!

Copy link
Contributor

@jtulach jtulach left a comment

Choose a reason for hiding this comment

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

Thanks for making this work!

@MimeLocation(subfolderName = "CodeLensProvider")
public interface InlayHintsProvider {

public Set<String> supportedHintTypes();
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing documentation and explanation of what this is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

*/
public CompletableFuture<List<? extends InlayHint>> codeLens(@NonNull Context context);

public static final class Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

No documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

private final @NonNull Set<String> requestedHintTypes;
private final @NullAllowed Range range;

public Context(@NonNull FileObject file, @NonNull Set<String> requestedHintTypes, @NullAllowed Range range) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be "module private", right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly, I think java.lsp.server needs to create the Context, so that it can call the inlayHints method.

public static Settings getDefault() {
Preferences preferences = NbPreferences.root().node("/org/netbeans/modules/java/editor/InlineHints/default");
return new Settings(preferences.getBoolean(JAVA_INLINE_HINT_PARAMETER_NAME, DEFAULT_VALUES.get(JAVA_INLINE_HINT_PARAMETER_NAME)),
preferences.getBoolean(JAVA_INLINE_HINT_CHAINED_TYPES, DEFAULT_VALUES.get(JAVA_INLINE_HINT_CHAINED_TYPES)),
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this connected with vscode/package.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A different instance of Settings is created, and used when running the semantic highlighter. It is created here:

new SemanticHighlighterBase.Settings(context.getRequestedHintTypes().contains("parameter"),

The instance created here is only used when running inside the NetBeans IDE.

@lahodaj lahodaj force-pushed the inline-hints-vscode branch from 999706b to 5f2b8b4 Compare February 13, 2025 14:04
@lahodaj lahodaj force-pushed the inline-hints-vscode branch from 5f2b8b4 to a3c2f88 Compare April 9, 2025 14:29
@lahodaj
Copy link
Contributor Author

lahodaj commented Apr 9, 2025

Commit squashed, tests are passing. Unless there are objections, I probably should integrate in the next day or so. @dbalek, @MartinBalin

*
* @since 1.33
*/
@MimeLocation(subfolderName = "CodeLensProvider")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the registrations located under CodeLensProvider ?

@neilcsmith-net neilcsmith-net modified the milestones: NB26, NB27 Apr 16, 2025
@lahodaj lahodaj force-pushed the inline-hints-vscode branch from a3c2f88 to 105eea1 Compare April 16, 2025 18:04
@lahodaj lahodaj merged commit c4f4f73 into apache:master Apr 17, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants