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

Support cross-repository references #9

@felixfbecker

Description

@felixfbecker

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions