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 signature pretty-printer to lsif-semanticdb conversion process #131

Merged
merged 18 commits into from
Apr 1, 2021

Conversation

Strum355
Copy link
Contributor

@Strum355 Strum355 commented Mar 29, 2021

PR adds support for generating a pretty-printed hover text from the emitted SemanticDB Signature and SymbolInformation types.
This happens at the SemanticDB to LSIF stage and is included in the hover results lists for a range, alongside the doc string if it exists.


TODO (either in this PR or a follow-up):

  • annotation interfaces
  • annotations on SymbolInformation (follow up)
  • additional properties (strictfp/synchronized etc) (follow up)
  • pretty-print enums properly
  • implements vs extends
  • Comment outlined here (follow up)
  • skip abstract in interface + interface methods
  • constructors
  • this keyword references field named this that doesn't exist

@Strum355 Strum355 force-pushed the nsc/lsif-semanticdb-sigformat branch from ed1e6ed to f170c72 Compare March 29, 2021 16:34
@Strum355 Strum355 force-pushed the nsc/lsif-semanticdb-sigformat branch from c7586de to 4fc0ce9 Compare March 30, 2021 14:41
@Strum355 Strum355 force-pushed the nsc/lsif-semanticdb-sigformat branch from 4a2808f to 2a08071 Compare March 30, 2021 20:19
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

This is outstanding work! It will be a big milestone when lsif-java supports proper hover messages.

A few comments, mostly minor. The only blocking comments are

  • print class name instead of <init>
  • why are there so many unresolved_type in the snapshots?

// we cheese it a bit here, as this is less work than trying to reconstruct
// a Signature from the pretty-printed Signature, with accompanying logic
// to fallback to display_name in SemanticdbPrinters.scala
.setDisplayName(hover).setSymbol(symbol).build()
Copy link
Member

Choose a reason for hiding this comment

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

Can we use Documentation instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we (currently) dont emit Documentation in the snapshots, only the Signature with DisplayName as fallback.
This should probably still not use Documentation even if we did, if we decide to go ahead with the original "musing" of formatting documentation in a fashion similar to Lorem ipsum ... facilisis, in convallis ex imperdiet., truncating for brevity

Copy link
Member

Choose a reason for hiding this comment

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

I see, the android.view.View class is indeed missing from the classpath that we're using in the snapshots

❯ javap -cp $(cs fetch -r https://maven.google.com/ 'com.airbnb.android:epoxy:4.3.1' -p) android.view.View

Error: class not found: android.view.View

The class is defined in android.jar from the SDK

❯ javap -cp $ANDROID_HOME/platforms/android-30/android.jar android.view.View | head
Compiled from "View.java"
public class android.view.View implements android.graphics.drawable.Drawable$Callback,android.view.KeyEvent$Callback,android.view.accessibility.AccessibilityEventSource {
  public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE;
  public static final int ACCESSIBILITY_LIVE_REGION_NONE;
  public static final int ACCESSIBILITY_LIVE_REGION_POLITE;
  public static final android.util.Property<android.view.View, java.lang.Float> ALPHA;
  public static final int AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
  public static final java.lang.String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE;
  public static final java.lang.String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its weird because many other android types do resolve. 🤷

// ^^^^^^^^ reference androidx/annotation/Nullable#
// ^^^^ reference java/util/List#
// ^^^^^^^^^^ reference com/airbnb/epoxy/EpoxyModel#
// ^^^^^^ definition local0
// ^^^^^^ definition local0 List<? extends EpoxyModel<?>> models
Copy link
Member

Choose a reason for hiding this comment

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

👏 🤩

}

/**
* A Handler class that uses the main thread's Looper.
*/
public static final Handler MAIN_THREAD_HANDLER =
// ^^^^^^^ reference _root_/
// ^^^^^^^^^^^^^^^^^^^ definition com/airbnb/epoxy/EpoxyAsyncUtil#MAIN_THREAD_HANDLER.
// ^^^^^^^^^^^^^^^^^^^ definition com/airbnb/epoxy/EpoxyAsyncUtil#MAIN_THREAD_HANDLER. public static final unresolved_type MAIN_THREAD_HANDLER
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have unresolved_type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of android types dont seem to resolve for some reason. You can see that above where the field type is _root_/ instead of the android/os/Handler# that it should be

@Strum355 Strum355 force-pushed the nsc/lsif-semanticdb-sigformat branch from 38188cb to 6ad078d Compare March 31, 2021 19:54
@Strum355
Copy link
Contributor Author

why are there so many unresolved_type in the snapshots?

There seems to be some issue with types from the android sdk occasionally (and Im not sure why only occasionally) where they dont resolved. This is always accompanied with the reference occurrence being given the symbol _root_/. Id be curious to see if this happens in non-android-based codebases too.

@Strum355 Strum355 force-pushed the nsc/lsif-semanticdb-sigformat branch from 6ad078d to 7da5641 Compare March 31, 2021 20:29
@Strum355 Strum355 force-pushed the nsc/lsif-semanticdb-sigformat branch from 7da5641 to a285b29 Compare March 31, 2021 21:11
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Feel free to merge once you think this is ready to go.

// we cheese it a bit here, as this is less work than trying to reconstruct
// a Signature from the pretty-printed Signature, with accompanying logic
// to fallback to display_name in SemanticdbPrinters.scala
.setDisplayName(hover).setSymbol(symbol).build()
Copy link
Member

Choose a reason for hiding this comment

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

I see, the android.view.View class is indeed missing from the classpath that we're using in the snapshots

❯ javap -cp $(cs fetch -r https://maven.google.com/ 'com.airbnb.android:epoxy:4.3.1' -p) android.view.View

Error: class not found: android.view.View

The class is defined in android.jar from the SDK

❯ javap -cp $ANDROID_HOME/platforms/android-30/android.jar android.view.View | head
Compiled from "View.java"
public class android.view.View implements android.graphics.drawable.Drawable$Callback,android.view.KeyEvent$Callback,android.view.accessibility.AccessibilityEventSource {
  public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE;
  public static final int ACCESSIBILITY_LIVE_REGION_NONE;
  public static final int ACCESSIBILITY_LIVE_REGION_POLITE;
  public static final android.util.Property<android.view.View, java.lang.Float> ALPHA;
  public static final int AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
  public static final java.lang.String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE;
  public static final java.lang.String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY;

String documentation = symbolInformation.getDocumentation().getMessage();
if (!documentation.isEmpty()) {
int hoverId = writer.emitHoverResult(doc.semanticdb.getLanguage(), documentation);
markedStrings.add(new MarkedString(Semanticdb.Language.UNKNOWN_LANGUAGE, documentation));
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about adding a new Documentation.Format called SIGNATURE? We can then make the Documentation documentation = 20; field repeated (which is a binary backwards compatible change). Do you think that would make this cleaner?

@Strum355 Strum355 changed the title WIP: add signature pretty-printer to lsif-semanticdb conversion process Add signature pretty-printer to lsif-semanticdb conversion process Apr 1, 2021
@Strum355 Strum355 marked this pull request as ready for review April 1, 2021 21:35
@Strum355 Strum355 merged commit bc5151a into main Apr 1, 2021
@Strum355 Strum355 deleted the nsc/lsif-semanticdb-sigformat branch April 1, 2021 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants