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

Spring Data JPA Content Assist #981

Closed
wants to merge 8 commits into from

Conversation

danthe1st
Copy link
Contributor

@danthe1st danthe1st commented Feb 20, 2023

Fixes #107

This PR adds more Content Assist options for Spring JPA Repository interfaces.

It adds simple text completions, e.g. a content assist is provided for countBy and automatically completes the return type and parameters of a method if it is named correctly.

2023-02-20_16-43-21.mp4

Aside from that, it includes a small fix allowing for primitive properties and also boolean properties if their getter names start with is.

To do:

  • Order/priorize completion proposals if possible (put text proposals at the bottom of the proposal list) - I am unsure whether this is possible does not seem to be possible without significant modifications and Eclipse seems to order it in a sensitive way anyways
  • more tests :)
  • split up some methods for better readability
  • Add completion proposals for property names (e.g. findByFirst should could completed to findByFirstName)
  • improve content assist for complex types that are indirectly referenced findByEmployee_FirstName so that it detects the type
  • complete partial attribute names (e.g. complete findByFirst to findByFirstName)

Future work:

  • The keywords In/IsIn should make the method expect a collection whereas Includes/... should expect a single element when a collection is on the left
  • create text-completions for keywords

Should there be a method/configuration for enabling/disabling these content assist options (e.g. enable some but not others)? If so, where/how are such things implemented in this project?

@martinlippert martinlippert added this to the 4.18.0.RELEASE milestone Feb 20, 2023
@danthe1st danthe1st marked this pull request as ready for review February 20, 2023 20:58
@BoykoAlex
Copy link
Contributor

@danthe1st Generally it all looks good to me. I suspect that the way to use it would be first type in the query keyword with a help of content assist (query proposals) then invoke content assist once query string is completed to fill in the rest for the method declaration (method proposals). Is this correct?
I'm going to squash the commits into one before merging. Hope this is okay with you

@danthe1st
Copy link
Contributor Author

danthe1st commented Feb 21, 2023

Yes, it does complete the signature of already existing queries once they are typed (if those refer to unknown attributes, it uses Object as the parameter).

Aside from that, it also autocompletes simple query method subjects like findFirst and tries to provide conpletions for attribute names. This us done via text completions.

I decided to return Lists (except for streamBy) in the query methods. I hope that's a sensible choice.

As seen in the Future work section, there still potential to improve it (e.g. keywords are not yet completed and it uses the wrong type for predicates like In) but I decided that those things could be done in upcoming PRs.

Finally, squashing is perfectly fine with me.

@BoykoAlex
Copy link
Contributor

I'm going to merge this PR as is squashed and rebased. It looks like we could factor some static stuff into spring beans but we can do it later as more PRs in this area are merged

@BoykoAlex
Copy link
Contributor

Squashed, rebased and merged with 97d6606

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.

add Spring Data JPA Content Assist to STS 4
3 participants