Skip to content

Conversation

@lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Dec 5, 2024

This is a prototype of a feature to show variable values directly in the editor, as permitted by the LSP protocol.

It looks like this inside VS Code:
inline-values-vscode

and inside NetBeans:
inline-values-nb

@lahodaj lahodaj added LSP [ci] enable Language Server Protocol tests VSCode Extension already fixed labels Dec 5, 2024
@lahodaj lahodaj added this to the NB25 milestone Dec 5, 2024
@apache apache locked and limited conversation to collaborators Dec 5, 2024
@apache apache unlocked this conversation Dec 5, 2024
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Dec 6, 2024
@apache apache locked and limited conversation to collaborators Dec 6, 2024
@apache apache unlocked this conversation Dec 6, 2024
@mbien
Copy link
Member

mbien commented Dec 20, 2024

really useful feature! We have to watch out for side effects of calling toString() though.

The debugger does have "Variable Formatters" which can be configured in the settings. Collections (which can be large) will only print their size by default for example. (but I imagine you are probably planning to do that anyway)

@mbien mbien modified the milestones: NB25, NB26 Jan 15, 2025
@lahodaj lahodaj marked this pull request as ready for review March 16, 2025 17:52
@lahodaj
Copy link
Contributor Author

lahodaj commented Mar 16, 2025

I did a lot of improvements lately. Lets see if this is heading in the right direction.

@lahodaj
Copy link
Contributor Author

lahodaj commented Mar 16, 2025

really useful feature! We have to watch out for side effects of calling toString() though.

The debugger does have "Variable Formatters" which can be configured in the settings. Collections (which can be large) will only print their size by default for example. (but I imagine you are probably planning to do that anyway)

Done.

@lahodaj
Copy link
Contributor Author

lahodaj commented Mar 16, 2025

FWIW, in VSCode, this needs to be enabled explicitly using the:

"debug.inlineValues": "on"

setting. I didn't find a way, yet, to make it work with auto.

@mbien
Copy link
Member

mbien commented Mar 20, 2025

gave it another try and it worked great. I got one exception once but wasn't able to reproduce it a second time:

java.lang.NullPointerException: Cannot invoke "com.sun.source.util.TreePath.getLeaf()" because "path" is null
	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:66)
	at org.netbeans.modules.debugger.jpda.ui.values.ComputeInlineValues.computeVariables(ComputeInlineValues.java:115)
	at org.netbeans.modules.debugger.jpda.ui.models.InlineValueComputerImpl$ComputeInlineVariablesFactory$1.run(InlineValueComputerImpl.java:344)
	at org.netbeans.modules.debugger.jpda.ui.models.InlineValueComputerImpl$ComputeInlineVariablesFactory$1.run(InlineValueComputerImpl.java:321)
[catch] at org.netbeans.modules.java.source.JavaSourceAccessor$CancelableTaskWrapper.run(JavaSourceAccessor.java:273)
	at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:561)
	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:786)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
	at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)

the inline hint should also listen to the main on/off toggle and be potentially also configurable like its other friends (see options window):

image

(I think listening to the main toggle would be sufficient, finer grained options could be added when needed in followup PRs - we don't have to solve everything at once)

@lahodaj
Copy link
Contributor Author

lahodaj commented Mar 21, 2025

Thanks for testing. I'll look at the exception.

For the toggle - I think I would prefer to have a different toggle (people may want the debugger values, but not parameter hints, and maybe even vice versa). I'll look into that.

@neilcsmith-net
Copy link
Member

I like where this is going, and agree that this shouldn't be aligned with the inline hints toggle but something separately configured.

@mbien
Copy link
Member

mbien commented Mar 21, 2025

What I had in mind is that I think it would be nice to retain the master switch for all inline hints, but add more shortcuts for the sub-switches. It could be somewhere in the debugger toolbar too potentially. Completely decoupled from the editor setting could also work - not sure what is more intuitive. (I suppose i could double-bind my mouse button to achieve something like a master switch still no matter how its implemented)

@neilcsmith-net
Copy link
Member

Aside from commit cleanup (cause of failing test) is this close to ready for merging, or are we retargetting for NB27?

@lahodaj lahodaj modified the milestones: NB26, NB27 Apr 15, 2025
@lahodaj
Copy link
Contributor Author

lahodaj commented Apr 15, 2025

Moving to NB 27, although assuming I can stabilize tests, I would like to integrate as early as possible (so that there's time to fix any breakages).

@lahodaj lahodaj changed the title Prototype for inlining values inside debugger Inlining values inside debugger Apr 15, 2025
@lahodaj lahodaj force-pushed the inline-values branch 2 times, most recently from af6ff55 to 470ee74 Compare April 17, 2025 17:08
@lahodaj lahodaj force-pushed the inline-values branch 2 times, most recently from b6b14eb to 380837c Compare April 22, 2025 06:15
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

there seems to be a problem where the inline hints state and the displayed values in the UI are out of sync.

When I press alt+I the checkbox in the view menu (and options) don't update to the new value, even though the inline hints do toggle within the editor. The UI does still work, but it can become inverted with the editor state.

This is a bit of a dejavu since I think this happened before while working on a prior inline hint PR - but I can't remember what the problem was.

@lahodaj
Copy link
Contributor Author

lahodaj commented May 19, 2025

there seems to be a problem where the inline hints state and the displayed values in the UI are out of sync.

When I press alt+I the checkbox in the view menu (and options) don't update to the new value, even though the inline hints do toggle within the editor. The UI does still work, but it can become inverted with the editor state.

This is a bit of a dejavu since I think this happened before while working on a prior inline hint PR - but I can't remember what the problem was.

I tried to reproduce, but does not happen for me. Is there something specific you do? (I did a merge, so there's a possibility that fixed it, although I'd be surprised if it did.)

@mbien
Copy link
Member

mbien commented May 19, 2025

got the same NPE again while testing (#8019 (comment)):

java.lang.NullPointerException: Cannot invoke "com.sun.source.util.TreePath.getLeaf()" because "path" is null
	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:66)
	at org.netbeans.modules.debugger.jpda.ui.values.ComputeInlineValues.computeVariables(ComputeInlineValues.java:113)
	at org.netbeans.modules.debugger.jpda.ui.models.InlineValueComputerImpl$ComputeInlineVariablesFactory$1.run(InlineValueComputerImpl.java:361)
	at org.netbeans.modules.debugger.jpda.ui.models.InlineValueComputerImpl$ComputeInlineVariablesFactory$1.run(InlineValueComputerImpl.java:338)
[catch] at org.netbeans.modules.java.source.JavaSourceAccessor$CancelableTaskWrapper.run(JavaSourceAccessor.java:273)
	at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:561)
	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:786)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
	at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)

I tried to reproduce, but does not happen for me. Is there something specific you do? (I did a merge, so there's a possibility that fixed it, although I'd be surprised if it did.)

Oops, I just noticed that this problem is already in NB 26 - so we can probably ignore it here since it is not a regression:
image

I don't have a reliable reproducer yet unfortunately. At some point the View menu can get out-of-sync if the state is toggled by other means, e.g alt-I hotkey or the checkbox in options -> inline hints. The same happened while testing the new value hints - but it turns out its nothing new.

@lahodaj
Copy link
Contributor Author

lahodaj commented May 20, 2025

I've fixed the NPE (hopefully), and squashed (to hopefully get a clean GH Actions). I wonder what are the current impressions on this?

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

looks good overall. Left a few comments.

@lahodaj
Copy link
Contributor Author

lahodaj commented May 22, 2025

what is the purpose of the empty loop?

It was there to initialize the computer. But turned out I can simply instantiate it, and it (hopefully) works as well, using Session instead of ContextProvider).

@mbien
Copy link
Member

mbien commented May 22, 2025

what is the purpose of the empty loop?

It was there to initialize the computer. But turned out I can simply instantiate it, and it (hopefully) works as well, using Session instead of ContextProvider).

I guessed that something like that might have been the reason for it. I was just thinking since lookup returns a List and no lazily initialized structure, it could have been already sufficient without the loop itself. But the new impl is more direct and less mysterious - thanks.

@lahodaj
Copy link
Contributor Author

lahodaj commented May 27, 2025

Unless there are objections, I would like to merge sometime soon - probably today or tomorrow.

@mbien
Copy link
Member

mbien commented May 27, 2025

great feature! I agree that it would be good to get it in. Don't forget to squash ;)

@lahodaj lahodaj merged commit 98c78a5 into apache:master May 29, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) 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.

3 participants