Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Support cross-repository references #9

Closed
2 of 4 tasks
felixfbecker opened this issue Nov 9, 2018 · 1 comment
Closed
2 of 4 tasks

Support cross-repository references #9

felixfbecker opened this issue Nov 9, 2018 · 1 comment
Labels

Comments

@felixfbecker
Copy link
Contributor

felixfbecker commented Nov 9, 2018

Flow

  • Extension makes go-to-definition request to find canonical source location. Remember definition URL
  • Extension uses npm API to find all packages depending on the containing package (from closest package.json, discover this through the extension or raw API).
  • For each dependent
    • Extension maps package name to repository clone URL and rev from repository and gitHead fields (gitHead requires an npm registry request to work around support gitHead property in package.json yarnpkg/yarn#2978)
    • Extension resolves clone URL + rev to Sourcegraph raw root URI (TODO: add API for this)
    • Extension authenticates root URI with access token
    • Extension creates language server connection for that root URI
    • Extension sends find-references request on the definition URL
      • Server recognizes definition URL is an out-of-workspace URL
      • Server uses raw API to find and get closest package.json to definition URL (walking parent directories of definition URL upwards)
      • Server parses out the package name
      • Server searches for **/node_modules/${packageName} in workspace
      • Server resolves package-root-relative URL for source file from package root (package.json location)
      • Server searches for **/*.d.ts.map declaration maps in package root in node_modules
      • Server finds the .d.ts.map that maps to the package-root-relative URL
      • Server reverse-maps the source definition position to the .d.ts position (line+character) using source-map library
      • Server rewrites the TextDocumentPositionParams of the find-references request with the file: URI of the .d.ts and the .d.ts position
      • Server forwards the request to the language server
  • Extension concatenates results from all the dependents and returns them to Sourcegraph

Status

Implemented in branch. To test:

  • TypeScript projects with single root package.json
  • Multiple package.json in monorepo
  • Typings in DefinitelyTyped (without declaration map)
  • Single typings file (without declaration map) published in package
@slimsag
Copy link
Member

slimsag commented Nov 9, 2018

TODO: how to map clone URL to Sourcegraph URL

There is a really nice recently-added API to do this, but it's not exposed via graphql or anything yet: https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+reposource%5C.CloneURLToRepoName

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants