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

add Spring Data JPA Content Assist to STS 4 #107

Closed
ismailsalloo opened this issue Oct 9, 2018 · 32 comments
Closed

add Spring Data JPA Content Assist to STS 4 #107

ismailsalloo opened this issue Oct 9, 2018 · 32 comments
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode theme: code completion theme: spring-data-support theme: sts3-feature-request please port this specific feature of STS3 over to the new Spring Tools 4 type: enhancement

Comments

@ismailsalloo
Copy link

Has Spring Data JPA Content Assist been removed from STS 4? In version 3 I was able to use content assist to show what fields were allowed to be part of the name of the method when using Query Methods. Has it been removed / not added to STS4 or is it a bug or disabled by default?

@kdvolder
Copy link
Member

kdvolder commented Oct 9, 2018

Possibly, but I am not totally sure what you are exactly referring to. So, can you give a concrete example of something that used to work and now doesn't anymore? With "concrete", I mean with some code sample and a bit of explanation exactly what you expect to work.

We may consider trying to somehow 'rescue' the feature from the old code-base or re-implement it from scratch, but we need to know what you are actually talking about first. Oh, and thanks for the report, we rely on these reports to determine which parts of the old tooling people are really missing.

@thackel
Copy link

thackel commented Oct 9, 2018

I can confirm that the Spring-Data JPA Content assist is not working anymore.

When editing JPA Repositories, STS is no longer providing completion for possible fields of the entity.

Here is the original feature ticket for older versions which describe the functionality: https://jira.spring.io/browse/IDE-1249

@ismailsalloo
Copy link
Author

ismailsalloo commented Oct 9, 2018

Possibly, but I am not totally sure what you are exactly referring to. So, can you give a concrete example of something that used to work and now doesn't anymore? With "concrete", I mean with some code sample and a bit of explanation exactly what you expect to work.

We may consider trying to somehow 'rescue' the feature from the old code-base or re-implement it from scratch, but we need to know what you are actually talking about first. Oh, and thanks for the report, we rely on these reports to determine which parts of the old tooling people are really missing.

I'm attaching screenshots of what code completion looks like in STS 3 vs STS 4 (specifically around JPA Query Methods)

STS 3:
sts3

STS 4:
sts4

@ismailsalloo
Copy link
Author

I can confirm that the Spring-Data JPA Content assist is not working anymore.

When editing JPA Repositories, STS is no longer providing completion for possible fields of the entity.

Here is the original feature ticket for older versions which describe the functionality: https://jira.spring.io/browse/IDE-1249

This pretty much sums up what's missing :-)

@kdvolder
Copy link
Member

kdvolder commented Oct 9, 2018

Thanks for the reference and the screenshots. That helps to know what is being talked about here.

Now, I'm pretty sure we are not going to re-implement or 'rescue' all of that as it was before because it seems much of it was specific to beans defined by XML.

From the screenshots, am I correct in assuming you are really mostly interested in the content assist and validations in Java context? WE might be able to re-implement that, though I suspect it will have to be done mostly from scratch. (Not saying we won't do it, we might, but it could take some time as its not a trivial feature to re-implement).

@martinlippert
Copy link
Member

This is indeed a feature of the Spring Data support in STS 3.9.x that we didn't re-implement for STS4 yet. This is due to the fact that the Spring support in STS4 is a complete re-write and we focused on specific pieces first (instead of "blindly" re-implementing everything from the old tooling). So this piece didn't make it into the first version of the all-new Spring Tools 4.

We should add this to the backlog in order to bring this content-assist for Spring Data repositories back - maybe in an even better shape than we had before... :-)

@ismailsalloo
Copy link
Author

Thanks for the reference and the screenshots. That helps to know what is being talked about here.

Now, I'm pretty sure we are not going to re-implement or 'rescue' all of that as it was before because it seems much of it was specific to beans defined by XML.

From the screenshots, am I correct in assuming you are really mostly interested in the content assist and validations in Java context? WE might be able to re-implement that, though I suspect it will have to be done mostly from scratch. (Not saying we won't do it, we might, but it could take some time as its not a trivial feature to re-implement).

Yes, we mainly work within the Java context nowadays. Can't remember when last I defined a bean via XML :-)

@ismailsalloo
Copy link
Author

This is indeed a feature of the Spring Data support in STS 3.9.x that we didn't re-implement for STS4 yet. This is due to the fact that the Spring support in STS4 is a complete re-write and we focused on specific pieces first (instead of "blindly" re-implementing everything from the old tooling). So this piece didn't make it into the first version of the all-new Spring Tools 4.

We should add this to the backlog in order to bring this content-assist for Spring Data repositories back - maybe in an even better shape than we had before... :-)

I'm pretty impressed with STS 4 at the moment. Looking forward to what's in store for the future

@martinlippert
Copy link
Member

@ismailsalloo Anything specific you are looking for with regards to the Spring Data content-assist? Just the Spring Data query method completions? Or something else in addition to that?

@ismailsalloo
Copy link
Author

@ismailsalloo Anything specific you are looking for with regards to the Spring Data content-assist? Just the Spring Data query method completions? Or something else in addition to that?

I mainly used it for query method completions. It would be cool if syntax within a @query annotation could also be validated.

@martinlippert
Copy link
Member

@ismailsalloo What exactly do you mean with syntax validation within a @query annotation? Can you provide a few examples?

Since we try to stay away from validations to avoid annoying users with false warnings, I would like to understand this in more detail first.

@ismailsalloo
Copy link
Author

ismailsalloo commented Oct 16, 2018

@ismailsalloo What exactly do you mean with syntax validation within a @query annotation? Can you provide a few examples?

Since we try to stay away from validations to avoid annoying users with false warnings, I would like to understand this in more detail first.

@martinlippert, I understand the annoyance behind false validations. It also gets to me at times.

Basically my idea is not too much different from the query method suggestion. I was thinking of something to the effect where as you start typing your query within the @query annotation, based on your entity structure, STS provides the user with suggestions of what fields you can extract within your query as well as what fields you can use in your search criteria. In addition to that, if you have a number field within your search criteria, the method param that it maps to must be of type number. I know it's pie in the sky, but it would be super awesome to have that functionality in STS.

I hope I'm making sense

@martinlippert
Copy link
Member

@ismailsalloo Thanks for the details, this content-assist support for the values in the annotation sounds indeed quite useful and like an awesome feature, thanks a lot for the suggestion. Will put that on the list of things to consider for future versions.

@martinlippert martinlippert added this to the 4.1.0 milestone Oct 16, 2018
@ismailsalloo
Copy link
Author

@ismailsalloo Thanks for the details, this content-assist support for the values in the annotation sounds indeed quite useful and like an awesome feature, thanks a lot for the suggestion. Will put that on the list of things to consider for future versions.

@martinlippert thanks for taking out time to respond to my query and possibly having it included in the future :-)

@thackel
Copy link

thackel commented Oct 17, 2018

Providing content-assist support for JPA queries (thats what int the @Query annotation for JPARepositories) will be a rather hard task.
I think the whole entity model has to be build to allow this. Compared to the "simple" query derivation based on entity properties and SD keywords, this will be expensive.
Last time a saw this was for the old (and outdated?) hibernate tools in eclipse.

But i am also looking forward to a possible solution B-)

@martinlippert martinlippert changed the title Spring Data JPA Content Assist removed from STS 4? add Spring Data JPA Content Assist to STS 4 Oct 19, 2018
@martinlippert martinlippert added the theme: sts3-feature-request please port this specific feature of STS3 over to the new Spring Tools 4 label Dec 23, 2018
@alextadams88
Copy link

I am trying to learn Spring Data so I downloaded STS to help with that effort. But as there is no content assist I am struggling a lot with learning what is capable in Spring Data. So I will have to use STS 3.9 until this is re-implemented in STS 4 unfortunately. Please prioritize this!

@martinlippert
Copy link
Member

@alextadams88 we already implemented a first step towards content-assist for Spring Data repository query methods in STS 4.1.0 and will continue to improve that for sure.

But I would also like to recommend to you to NOT use the content-assist of the IDE as the main driver for learning Spring Data. I would strongly recommend to use the official documentation, guides, and maybe books on Spring Data to learn that. Even the content-assist implementation in STS 3.9.x covers only a fraction of the Spring Data features and doesn't really help a lot when learning Spring Data, I would say.

@LorenzoBettini
Copy link

Besides the missing content assist, what I mainly miss is the validation part which was in STS3: there was an error if you typing something like findByMame instead of findByName. Such errors are not caught only at runtime.

@martinlippert
Copy link
Member

@LorenzoBettini I agree that these error or warning markers would be extremely useful, there are also somewhat hard to get right and the probability of producing wrong (and then annoying) error and warning markers is quite high. Therefore we opted out of implementing those validations in the first place. And (at the moment) they are not yet on the list of things to re-implement in Spring Tools 4. But we clearly see your vote and take that into account. Please keep the feedback coming.

Did you try the first limited content-assist already? What do you miss from it the most?
And with regards to the validation: what sort of validation do you miss? findBy methods only?

@LorenzoBettini
Copy link

@martinlippert the limited content-assist somehow helps, but as I said I'm more concerned about the missing static validation. I don't remember the full signature convention of repository query methods, but the crucial validations I miss is mispelling a field name (are there other things that could be checked besides field names? I guess probably the types of the parameters of the method maybe?)

I was wondering whether the logic used by Spring when creating the implementation of such methods at run-time could be reused to do the validation of the fly. In such a case, the validation should not produce any wrong results, right? But I have no idea on how Spring creates the implementation so what I've just said might make no sense at all ;)

And in general sts 4 just rocks! :D

@martinlippert
Copy link
Member

@LorenzoBettini the idea about re-using the spring data implementation itself to implement the validation is a good one in general, this is the way we implemented this in STS3. The downside of this approach is that you have to ship corresponding Spring Data libraries inside of the IDE. And you would need to somehow match the versions, so that you validate the source code of your project with the right version of the Spring Data library, otherwise you can quickly run into version compatibility issues. In addition to that the library is implemented to use runtime type information, so loading classes of your project via a class loader into the JVM and then looking at Class objects. You can bridge this gap by loading the types of your project into the JVM of the IDE (this is what we did up to a certain degree in the past), but it turns out to be a pretty bad idea in the long run (due to various reasons). And validations are usually quite performance critical, since you don't want to slow down your workspace build and IDE due to validations doing a lot of analysis. As you can see, this is all possible, but certainly not a trivial task... :-) That doesn't mean we should not do it, but it means for us that we should carefully select which validations we can/should implement, if we are going down that path.

@LorenzoBettini
Copy link

OK, I see. Indeed, IIRC, in sts 3 that validation was performed only on file saving, not on the fly.

@martinlippert
Copy link
Member

@LorenzoBettini yeah, doing the validation not during the workspace build but on file changes/save events definitely saves some time, but it raises additional questions about dependent changes (like changes to the domain type that is used in the validation for checking the repository methods), so you would need to keep track of those dependencies (including super classes and maybe interfaces). The alternative would be to show those errors/warnings only when the file is open in an editor while typing and remove them once the file is not being edited anymore, but would that be what you would expect? Error shows up when the file is open and disappears when you close the editor again?

@LorenzoBettini
Copy link

Coming from Xtext, the first option is almost automatic ;)
However, also the second one sounds good. I agree with you that'd be counter intuitive though.

@shahrk
Copy link

shahrk commented Apr 6, 2020

I still can't see the method query completion. I'm using STS 4.2.2

image

@martinlippert
Copy link
Member

Unfortunately, that is correct, we did not improve the existing, simple content-assist for Spring Data yet. Any help with this would be much appreciated (to speed things up)... :-)

@shahrk
Copy link

shahrk commented Apr 4, 2021

@martinlippert how should I get started. I'd like to help with this feature. I really think it is essential.

@martinlippert
Copy link
Member

@shahrk Sounds great, your help on this one would be very welcome.

This is the class that implements the existing, but very limited content-assist for Spring Data repositories:
https://github.com/spring-projects/sts4/blob/master/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositoryCompletionProcessor.java

Here is a simple test case for that implementation:
https://github.com/spring-projects/sts4/blob/master/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/data/test/DataRepositoryCompletionProcessorTest.java

The first step to make some progress here would be to get a workspace up that contains the projects. The easiest way would be, most likely, so import all the projects in the headless-services directory as Maven project into a fresh workspace.

The second step would be to get the existing test running (Run as -> JUnit Test).

The unit test case uses this:
https://github.com/spring-projects/sts4/tree/master/headless-services/spring-boot-language-server/src/test/resources/test-projects/test-spring-data-symbols

as a test project to work against.

This line in the test prepares the content of the editor:
https://github.com/spring-projects/sts4/blob/master/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/data/test/DataRepositoryCompletionProcessorTest.java#L55

By adding the <*> to the content of the editor the test knows where the cursor position is. Then you basically invoke the content-assist on the editor by asking it for all the completions and see if the result is what you would expect.

The infrastructure around this "asking the editor for all the completions" doesn't allow you to specify all the things yet that a completion request to the language server could contain (like a prefix, etc.), so you might want to add that to the infrastructure as you need it.

If you decide to work on this, please make sure you accept the CLA upfront and then submit PRs. Also feel free to submit several small PRs instead of one big. That would make reviewing them easier.

Hope that helps to get started with this!

@danthe1st
Copy link
Contributor

I have created a PR for this. I hope it is useful.

@martinlippert
Copy link
Member

I have created a PR for this. I hope it is useful.

Absolutely, this is truly awesome. I asked @BoykoAlex to review and provide feedback, so that we can get this into the next release. 😀

danthe1st added a commit to danthe1st/sts4 that referenced this issue Feb 21, 2023
@martinlippert martinlippert added this to the 4.18.0.RELEASE milestone Feb 24, 2023
@martinlippert martinlippert added for: eclipse something that is specific for Eclipse theme: spring-data-support for: vscode something that is specific for VSCode theme: code completion labels Feb 24, 2023
@martinlippert
Copy link
Member

I will mark this as closed and fixed for now, due to the contribution from @danthe1st. Many thanks for that again!!!

@martinlippert
Copy link
Member

Further improvements to the content-assist should be captured in separate issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode theme: code completion theme: spring-data-support theme: sts3-feature-request please port this specific feature of STS3 over to the new Spring Tools 4 type: enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants