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 complete support for Java annotations in SemanticDB #2281
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution. This is a fantastic milestone! Lack of comprehensive support for annotations has always been a weak spot in SemanticDB and it's really exciting to see that we now have a complete implementation for Java annotations.
I have a few minor comments, otherwise this looks good to me 👍
@@ -278,7 +278,7 @@ message SymbolInformation { | |||
int32 properties = 4; | |||
string display_name = 5; | |||
Signature signature = 17; | |||
repeated Annotation annotations = 13; | |||
repeated AnnotationTree annotations = 13; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repeated AnnotationTree annotations = 13; | |
repeated AnnotationTree annotations = 13; // NOTE: it's possible to manually change the type to `Annotation` for source compatibility with older SemanticDB versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tgodzik @gabro I'm curious to hear your thoughts about this Protobuf binary-compatible but Scala binary+source-incompatible change. It's possible to keep the old Annotation
signature to preserve source compatibility but the new AnnotationTree
is more consistently named with other Tree
subclasses.
A few sidenotes:
- The ScalaPB-generated classes have intentionally never been marked as public APIs exactly so that we can make Protobuf binary-compatible changes like this.
- SemanticDB annotations are not really used by any meaningful Scalameta project from what I can tell because they are incomplete for Scala (no parameters until this PR) and they were officially unsupported for Java.
- Scalafix will be able to incorporate these changes into its public API without breaking changes.
WDYT?
still relevant? |
We've been using this in https://github.com/sourcegraph/scip-java for the past ~2 years, along with #2292 which also has not been merged here yet |
I think the issue was the Maybe we could keep Annotation at least as an existing class and just AnnotationTree as a completely new thing? This might break some logic, but not break binary compat. |
That change looks non-breaking from a Scalafix perspective as ScalaPB classes are not leaking to the public Scalafix API (they are all converted to case classes manually-defined in When parameters are actually filled by semanticdb-scalac (since they don't seem in this PR?), we'd have to see if it is possible to expose |
So I think we should be good to merge this, what do you think @kitbellew ? |
@tgodzik looks like it. i am confused about one thing, however: do we want to add |
I think we want to drop the old |
|
does this mean we don't need to create a new type, and can stick with the old one? protobuf is backwards-compatible when it comes to adding new fields, is our usage of it as well? |
I guess technically? I dont remember if there was a reason beyond having the naming more aligned with the rest of the This change is byte compatible, yes, but not source compatible. Scala code would most likely complain as theyre different types in the generated code, but programs using either the old or the new schema can communicate with each other just fine |
This PR expands the SemanticDB spec to allow for representing Annotation AST's (incl. parameters) by introducing two new types to the
Tree
family:AnnotationTree
andAssignTree
.As
AnnotationTree
is binary compatible with theAnnotation
type, this proposal deprecatesAnnotation
in favour ofAnnotationTree
, replacing its usages inSymbolInformation
andAnnotatedType
. Alternatively, I would also be open to addingAnnotation
to theTree
oneof instead, if source-level backwards compatibility is also strongly desired.The specification doc is updated to include some more examples, given the new capabilities to also model the parameters of annotations.
Working example of rendering annotations from the structures built via the changes in this PR can be found at sourcegraph/scip-java#148