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

Emit SemanticDB types and signatures #126

Merged
merged 3 commits into from
Mar 24, 2021
Merged

Emit SemanticDB types and signatures #126

merged 3 commits into from
Mar 24, 2021

Conversation

Strum355
Copy link
Contributor

@Strum355 Strum355 commented Mar 19, 2021

Emit Type and Signature messages for symbol occurrences.
With this information, we can reconstruct accurate hover signatures when converting from SemanticDB to LSIF.


Footnotes

Wildcard (existential) types proved most difficult to decipher. My work here is a combination of scalameta Javacp.scala file, the semanticdb spec ("Hardlinking comes in handy in situations when an advanced type such as ... ExistentialType") and this one table entry from the semanticdb spec (in which the params are the opposite way around):
image

As wildcard params dont have a symbol emitting for them, I create a hardlink as opposed to a symlink in the declarations field of the existential type. In a mixed wildcard and non-wildcard scenario, the declarations ordering must be derived from the ExistentialType.tpe.type_arguments field, as in the case of Triplet<?, String, ? extends Integer>, the ordering of declarations would be symlink: "String", hardlinks: "local_wildcard", hardlinks: "local_wildcard"+upper_bound: "java/lang/Integer#". The relative ordering of symlinks to symlinks and hardlinks to hardlinks is preserved, just not symlinks to hardlinks and vice versa, so there should be no problem there.

I had to do some guessing as to the behaviour when theres multiple wildcard type params for a given type (as is the case with e.g. Map<?, ?>), which isn't covered in the semanticdb spec, but this seems fairly sane.

Decoded Protobuf

Link to Java source for below: https://github.com/sourcegraph/lsif-java/pull/126/files#diff-3f725eecc09c1818a18120a2d471018890dd664200b233dcbee8c14c650824aeR10

  symbols {
    symbol: "minimized/ParameterizedTypes#doStuff()."
    signature {
      method_signature {
        type_parameters {
        }
        parameter_lists {
        }
        return_type {
          existential_type {
            tpe {
              type_ref {
                symbol: "java/util/Map#"
                type_arguments {
                  type_ref {
                    symbol: "local_wildcard"
                  }
                }
                type_arguments {
                  type_ref {
                    symbol: "local_wildcard"
                  }
                }
              }
            }
            declarations {
              hardlinks {
                symbol: "local_wildcard"
                signature {
                  type_signature {
                    type_parameters {
                    }
                    upper_bound {
                      type_ref {
                        symbol: "java/lang/String#"
                      }
                    }
                  }
                }
              }
              hardlinks {
                symbol: "local_wildcard"
                signature {
                  type_signature {
                    type_parameters {
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

@Strum355 Strum355 self-assigned this Mar 19, 2021
@Strum355 Strum355 linked an issue Mar 23, 2021 that may be closed by this pull request
@Strum355 Strum355 marked this pull request as ready for review March 23, 2021 14:38
@Strum355 Strum355 requested a review from olafurpg March 23, 2021 14:55
@Strum355 Strum355 changed the title WIP: emit types and signatures emit types and signatures Mar 23, 2021
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 exciting progress! The implementation looks good to me. Just missing the pretty-printer before we can merge this. It's best to wait until the lsif-semanticdb PR is merged before we integrate the pretty-printer into LSIF hover messages

@Strum355 Strum355 requested a review from olafurpg March 23, 2021 17:50
@olafurpg olafurpg changed the title emit types and signatures Emit SemanticDB types and signatures Mar 24, 2021
@Strum355 Strum355 merged commit c6bbe47 into main Mar 24, 2021
@Strum355 Strum355 deleted the nsc/type-signatures branch March 24, 2021 14:34
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.

Type and Signatures are not emitted
2 participants