This repository was archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
This repository was archived by the owner on Jun 7, 2022. It is now read-only.
Support cross-repository references #9
Copy link
Copy link
Closed
Labels
Description
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
andgitHead
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 innode_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) usingsource-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 maps package name to repository clone URL and rev from
- 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