You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need @Value annotation live hover info in vscode #177
The value of the property may come from multiple sources, e.g. a local config file / a cloud config server. It's useful if I can know the value when the application is running.
Update:
previous screenshot is kind of misleading, removed. Now I find the Value hover info works well for Spring Boot 1.x but NOT for 2.x
I think I've found the root cause. Let me share the findings.
1. The Value hover provider fails in SpringBoot 2.x projects. (But works well with Spring Boot 1.x)
It's due to the different data structures of the env returned by Acuator.
In 1.x the property sources are flatten, while in 2.x they are grouped into an array. E.g.
(comment in Pivotal Tracker added by Nieraj Singh:)
The findings appear to be correct. We were not parsing live properties from env for Boot 2.x.
I have fixed one of the two issues listed above. We should now be able to get live properties when hovering over @value for Boot 2.x, IF a user hovers over the property itself. The live hovers should also show the source of the property, and will show multiple sources if the property comes from various sources.
However, the second issue, as to when to trigger live hovers still remains to be fixed. At the moment live hovers will only appear if you hover over the actual property itself, so for example in:
@Value(value="${a.prop}")
if you hover over a.prop, then you will get live hover information, but not if you hover over value or the annotation itself.
However, the second issue, as to when to trigger live hovers still remains to be fixed.
Actually I was trying to fix the second issue by adding logic for // case: @Value(value="${a.prop}") hover on value , and then I find the reason why the original author didn't do that.
E.g. @Value(value="${a.prop} concat ${b.prop}"), when you hover over value, what's live hover information supposed to be like? What's the expected behavior? I've no idea for the moment.
(comment in Pivotal Tracker added by Nieraj Singh:)
@mlippert I'm working on trying to calculate hover hints for value properties when the watchdog requests highlight hints, and see if we can highlight the property name. I think it may require additional traversal of the AST during the live hover hints calculation, as to get to the StringLiteral node for the Annotation that is of interest to us to highlight. I'll update if I get it working.
However, the second issue, as to when to trigger live hovers still remains to be fixed.
Actually I was trying to fix the second issue by adding logic for // case: @Value(value="${a.prop}") hover on value , and then I find the reason why the original author didn't do that.
E.g. @Value(value="${a.prop} concat ${b.prop}"), when you hover over value, what's live hover information supposed to be like? What's the expected behavior? I've no idea for the moment.
Although my following comment won't address what to do if a user hovers over the Annotation or value, as we haven't considered this yet especially with your example above, I think for the time being, we will try to at least highlight the property itself with a hint as to make it clear to the user that live information is available there.
(comment in Pivotal Tracker added by Nieraj Singh:)
I've been able to add hint highlights for properties as seen in the attached screen shot in Pivotal Tracker (note: screenshot may not be visible in GitHub), so users will now be able to see when live hover information is available for @Value properties. Only the property names will be highlighted as that is the range where we provide live hover information. I think that is what we wanted for now.
I have pushed this to master so it should be available in the STS4 nightly snapshot to test.
Note that this only supports simple cases for properties in @Value expressions.
For more complex expressions that include multiple properties, this is not yet supported as the whole expression is still just one StringLiteral node in the JDT AST, so we would have to parse this expression String separately to obtain individual properties before we can provide both live hovers and hint highlights.
I recommend that we deliver this ticket for simple, single property cases in @value, and handle more complex SpEL expressions as an enhancement for later. I can raise a separate ticket to track this.
(comment in Pivotal Tracker added by Martin Lippert:)
I tested this and it seems to work nicely. But I would like to see it handle multiple occurrences of properties in the same expression while proving the live hover hint.
it should show the live hover hint on both referenced properties.
Interestingly, the hover itself works for the two cases, showing the right value for each property, but the hover hints disappear as soon as there is more than one occurrence.
This doesn't need a real SpEL parser or anything like that, it should just look for ${..} substrings, much in the same way than the hover itself is doing.
Activity
kdvolder commentedon Jan 9, 2019
Good idea. Thanks for the suggestion.
Eskibear commentedon Feb 11, 2019
I think I've found the root cause. Let me share the findings.
1. The Value hover provider fails in SpringBoot 2.x projects. (But works well with Spring Boot 1.x)
It's due to the different data structures of the env returned by Acuator.

In 1.x the property sources are flatten, while in 2.x they are grouped into an array. E.g.
But in
ValueHoverProviderthe logic is dedicated for 1.x projects.https://github.com/spring-projects/sts4/blob/705d81f9453b0f109c2e82e8322584d54525fe5f/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java#L82-L86
2. When hover on the
@Valueannotation itself instead of the property key, the hover provider doesn't work either.I find the provider has been designed not to handle such cases for the moment. (In such case, exactNode is a
SimpleNameinstead of aStringLiteral)https://github.com/spring-projects/sts4/blob/705d81f9453b0f109c2e82e8322584d54525fe5f/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java#L48-L54
spring-projects-issues commentedon Feb 11, 2019
(comment in Pivotal Tracker added by Nieraj Singh:)
The findings appear to be correct. We were not parsing live properties from env for Boot 2.x.
I have fixed one of the two issues listed above. We should now be able to get live properties when hovering over @value for Boot 2.x, IF a user hovers over the property itself. The live hovers should also show the source of the property, and will show multiple sources if the property comes from various sources.
However, the second issue, as to when to trigger live hovers still remains to be fixed. At the moment live hovers will only appear if you hover over the actual property itself, so for example in:
if you hover over
a.prop, then you will get live hover information, but not if you hover overvalueor the annotation itself.Eskibear commentedon Feb 12, 2019
Actually I was trying to fix the second issue by adding logic for
// case: @Value(value="${a.prop}") hover on value, and then I find the reason why the original author didn't do that.E.g.
@Value(value="${a.prop} concat ${b.prop}"), when you hover overvalue, what's live hover information supposed to be like? What's the expected behavior? I've no idea for the moment.spring-projects-issues commentedon Feb 12, 2019
(comment in Pivotal Tracker added by Martin Lippert:)
Nice. What about the hover hints? Do they show up for the range of the hover information, too? Maybe the prop name only? That would be quite awesome.
spring-projects-issues commentedon Feb 12, 2019
(comment in Pivotal Tracker added by Nieraj Singh:)
@mlippert I'm working on trying to calculate hover hints for value properties when the watchdog requests highlight hints, and see if we can highlight the property name. I think it may require additional traversal of the AST during the live hover hints calculation, as to get to the StringLiteral node for the Annotation that is of interest to us to highlight. I'll update if I get it working.
nierajsingh commentedon Feb 12, 2019
Although my following comment won't address what to do if a user hovers over the Annotation or
value, as we haven't considered this yet especially with your example above, I think for the time being, we will try to at least highlight the property itself with a hint as to make it clear to the user that live information is available there.spring-projects-issues commentedon Feb 13, 2019
(comment in Pivotal Tracker added by Nieraj Singh:)
I've been able to add hint highlights for properties as seen in the attached screen shot in Pivotal Tracker (note: screenshot may not be visible in GitHub), so users will now be able to see when live hover information is available for
@Valueproperties. Only the property names will be highlighted as that is the range where we provide live hover information. I think that is what we wanted for now.I have pushed this to master so it should be available in the STS4 nightly snapshot to test.
Note that this only supports simple cases for properties in
@Valueexpressions.For more complex expressions that include multiple properties, this is not yet supported as the whole expression is still just one StringLiteral node in the JDT AST, so we would have to parse this expression String separately to obtain individual properties before we can provide both live hovers and hint highlights.
I recommend that we deliver this ticket for simple, single property cases in @value, and handle more complex SpEL expressions as an enhancement for later. I can raise a separate ticket to track this.
spring-projects-issues commentedon Feb 14, 2019
(comment in Pivotal Tracker added by Martin Lippert:)
I tested this and it seems to work nicely. But I would like to see it handle multiple occurrences of properties in the same expression while proving the live hover hint.
So if I have something like:
it should show the live hover hint on both referenced properties.
Interestingly, the hover itself works for the two cases, showing the right value for each property, but the hover hints disappear as soon as there is more than one occurrence.
This doesn't need a real SpEL parser or anything like that, it should just look for
${..}substrings, much in the same way than the hover itself is doing.spring-projects-issues commentedon Feb 15, 2019
(comment in Pivotal Tracker added by Nieraj Singh:)
I pushed some support for live hints for multiple properties. See attached screenshot.
Please check the STS4 nightly snapshot and let me know if it covers your cases.
spring-projects-issues commentedon Feb 15, 2019
(comment in Pivotal Tracker added by Martin Lippert:)
Looks great !!!