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

Find references even when TypeScript sub-projects not yet open #30823

Closed
dcecile opened this issue Feb 19, 2019 · 10 comments
Closed

Find references even when TypeScript sub-projects not yet open #30823

dcecile opened this issue Feb 19, 2019 · 10 comments
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@dcecile
Copy link

dcecile commented Feb 19, 2019

From microsoft/vscode#65102...

It seems like with a multiple-tsconfig.json setup, VS Code can't find all references. (Even though technically all of them should be "joined" via a root tsconfig.json that uses project references.)

Here's a minimal repro of my setup: https://github.com/dcecile/typescript-references-test

common/
  message.ts
  tsconfig.json
server/
  hello.ts
  tsconfig.json
client/
  sharedMain.ts
  tsconfig.json
  • Both client and server reference the common project
  • "Find references" fails to find the references to the common function
  • "Rename symbol" also fails to rename the references
  • After loading files from the client and server projects, find references works
@microsoft microsoft deleted a comment from vscodebot bot Apr 9, 2019
@mjbvz mjbvz transferred this issue from microsoft/vscode Apr 9, 2019
@mjbvz mjbvz removed their assignment Apr 9, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Apr 9, 2019

Confirmed with TypeScript 3.5.0-dev.20190407

@sheetalkamat
Copy link
Member

This is currently known issue in which if the file is not open or declaration maps are not present it cannot find all references in sibling projects. #28261 is wip for this but needs more work before can be merged in since we need to be smart about when to lookup symbol in other projects(as loading projects in most common scenarios is costly and can result in delay when someone does first time find all references)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 15, 2019
@awerlang
Copy link

@RyanCavanaugh I believe the Duplicate label is a mistake here.

@hediet
Copy link
Member

hediet commented May 28, 2019

This blocks us from splitting our code into multiple smaller projects as (consistent!) renaming across the entire codebase is very important to us. We would love to have this feature!

@bajtos
Copy link

bajtos commented May 31, 2019

#28261 is wip for this but needs more work before can be merged in since we need to be smart about when to lookup symbol in other projects(as loading projects in most common scenarios is costly and can result in delay when someone does first time find all references)

Personally, I will happily trade off performance for "Find all references" and "Rename symbol" that actually works.

In https://github.com/strongloop/loopback-next, we have configured TypeScript to treat the entire monorepo as a single project, so that we can use "Find all references" and "Rename symbol".
We also don't use declaration maps, therefore cross-project imports are resolved against the original TypeScript sources, not via .d.ts and .d.ts.map files.

This setup works pretty well for us and I am not aware of any performance or memory limitation when working in VS Code. If the performance of #28261 is similar, then I would happily accept it.

Why we want to migrate from our single-project setup to project references when VS Code experience is good now? The problem is that our build times are super slow. We are building each monorepo package independently, because each package has its own outDir, e.g. packages/{name}/dist. Because cross-project imports are resolved against the original TypeScript sources, I suspect that the compiler is repeatedly parsing each TypeScript source file again and again for each top-level package depending on it.

Anyhow. Is there a way how to finish #28261 sooner, possibly without performance optimizations and perhaps behind a new feature flag?

@AnyhowStep
Copy link
Contributor

I currently have a code base that uses composite projects and has 34 sub-projects.

Having to open all 34 sub-projects to "Find all references" is a little tiring =/

@alextreppass
Copy link

alextreppass commented Oct 8, 2019

Hi @mjbvz @RyanCavanaugh apologies in advance for the direct mention. Are there any plans to prioritise this?

We've recently migrated a very large frontend codebase to sub-projects, and opening files from each before finding references isn't feasible, so we seem to be stuck with grepping for now, or switching to IntelliJ which doesn't seem to rely on TS server to do the references.


Edit: I've just been pointed at #33287 so perhaps a fix is already in progress?

@pablobirukov
Copy link

I have a similar problem in a case implementing scenario described in the project references documentation.

There is a root tsconfig.json, referencing packages which are a set of composite projects (implementation and tests). In case there is no tsconfig.json with non-empty files in a package, VS Code won't pick up the config for the files in the package.

https://github.com/pablobirukov/vs-core-project-references

@pokey
Copy link

pokey commented Mar 2, 2023

For what it's worth, in order to get this to work, we had to add a "solution" tsconfig.json at the root of our repo that references all projects, as recommended in the Typescript handbook:

Another good practice is to have a “solution” tsconfig.json file that simply has references to all of your leaf-node projects and sets files to an empty array (otherwise the solution file will cause double compilation of files). Note that starting with 3.0, it is no longer an error to have an empty files array if you have at least one reference in a tsconfig.json file.

We were able to automate generating this list using meta-updater. See our meta-updater config for more details

@aliakbarazizi
Copy link

I did all, i created a root tsconfig with references, I set tsconifg in all project with composite: true and still I need to open project to use find references.

I found a hack, I added "files": ["./project1/tsconfig.json", "./project2/tsconfig.json"] to root tsconfig and it seems it force vscode to load all tsconfig and its working very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests