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

TypeScript: aggregate errors for file from all projects #20185

Open
mjbvz opened this issue Nov 21, 2017 · 18 comments
Open

TypeScript: aggregate errors for file from all projects #20185

mjbvz opened this issue Nov 21, 2017 · 18 comments
Labels
Bug A bug in TypeScript Domain: TSServer Issues related to the TSServer
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Nov 21, 2017

From @OliverJAsh on September 30, 2017 16:20

I have a project with three folders, two of which are TS projects and the third of which is shared between them:

  • shared
  • service-worker (with tsconfig.json)
  • browser (with tsconfig.json)

Both "browser" and "service-worker" depend on "shared".

However, when I open a file in "shared", I only see errors related to one of the tsconfig.jsons—usually this will be the tsconfig.json used for the file I navigated from previously.

It would be great if VSCode could aggregate all errors for the current file for all matching TS projects.

Copied from original issue: microsoft/vscode#35432

@mjbvz mjbvz self-assigned this Nov 21, 2017
@mjbvz mjbvz added Bug A bug in TypeScript typescript labels Nov 21, 2017
@mjbvz mjbvz removed Bug A bug in TypeScript typescript labels Nov 21, 2017
@mjbvz mjbvz removed their assignment Nov 21, 2017
@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 21, 2017

Related to #20184 as both involve the same file that is part of multiple tsconfig.json projects. Again, it is not clear to me what the expected experience would be in this case

@mhegazy mhegazy added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: TSServer Issues related to the TSServer labels Nov 21, 2017
@OliverJAsh
Copy link
Contributor

Another issue I just hit because of this: "find references" will not show all actual references.

Perhaps the errors and references should be grouped by the tsconfig.json path (when there are multiple projects)

@mhegazy
Copy link
Contributor

mhegazy commented Dec 4, 2017

Another issue I just hit because of this: "find references" will not show all actual references.

not sure i understand this comment, can you elaborate?

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Dec 4, 2017

When I have a file that is used in multiple TS projects, "find references" will not show references across all of those TS projects.

Steps to reproduce:

  1. create 3 TS projects: e.g. "browser", "service-worker", "shared"
  2. create a module in the "shared" project with an export
  3. depend on that module from one of the other projects, e.g. "browser"/"service-worker"
  4. navigate to the module created in "shared"
  5. use find references on the export in the "shared" module

Edit: after further testing, I've found the same occurs if shared doesn't have its own tsconfig.json.

If I navigate to the shared file from a file in one of the other projects, TS/VSCode will only show references applicable to the project of the previously viewed file.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jan 12, 2018

@mhegazy Are there any updates on this? I am just starting another project which has similar requirements: two TS projects with their own dependency graph and some shared dependencies (e.g. client and server, and some files shared by both).

Let me know if you want any more information about the problem.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 12, 2018

That sounds like a bug. I have not had a chance to invistigate though.

@mhegazy mhegazy added Bug A bug in TypeScript and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jan 12, 2018
@mhegazy mhegazy assigned ghost Jan 12, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Jan 12, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@OliverJAsh
Copy link
Contributor

This issue is really bothering me so here are some clearer steps to reproduce.

We have two TS projects, project1 and project2. (A real world use case would be server and client aka frontend and backend.) These TS projects depend on some common shared files.

.
├── project1
│   ├── index.ts
│   └── tsconfig.json
├── project2
│   ├── index.ts
│   └── tsconfig.json
└── shared
    └── index.ts
// project1/index.ts
import { foo } from "../shared/index";
// project1/tsconfig.json
{
    "files": [
        "./index.ts"
    ]
}
// project2/index.ts
import { foo } from "../shared/index";
// project2/tsconfig.json
{
    "files": [
        "./index.ts"
    ]
}
// shared/index.ts
export const foo = 1;

Finding references on a shared symbol in one of the TS projects only shows references in the TS project of the selected file—VSCode/TypeScript does not aggregate the references of all TS projects that apply to the current file.

E.g. missing references in project1:

image

Finding references on a symbol in the shared file shows no references.

E.g. missing references in project1 and project2:

image

… unless VSCode/TypeScript has also opened a file from one of the other TS projects, in which case only references from that TS project will be shown.

E.g. missing references in project2:

image

I am only demonstrating the behaviour of references, but the same behaviour extends to error reporting, refactors like renaming, etc.

Ideally VSCode/TypeScript would aggregate all TS projects for the current file.

Alternatively, is there a better way to structure the project?

Potentially related issues:

@sheetalkamat
Copy link
Member

When you open shared.ts the context matters, since its not directly referenced in any of the tsconfig file in its directory hierarchy ... tsserver will have the information of project/projects it was opened/used in earlier. If project1 is open, there is no way to know that it would also be referenced in project2 unless it is open and hence the behaviour you see. For any file we only look in its hierarchy for the tsconfig file.

@sheetalkamat
Copy link
Member

That sounds like a bug. I have not had a chance to invistigate though.

This is not bug @mhegazy . unless the project is open there is no really default config project for shared file to be able to deduce its being referenced in those other projects whose tsconfig's are not even in directory chain.

@mhegazy
Copy link
Contributor

mhegazy commented May 17, 2018

this is about having the file in multiple contexts. we already do something similar for find all refs for instance where we repeat the process for every containing project.

@OliverJAsh
Copy link
Contributor

@sheetalkamat That explains the current behaviour.

@mhegazy Do you think there's anything TypeScript/VSCode could offer to make the user experience better here? It's quite common to have multiple TS projects with overlapping dependency graphs, e.g. server and client. When those "shared" files are viewed, the ideal experience would be for TypeScript/VSCode to aggregate errors from all TS projects that file appears within. Similarly, both projects would be used when refactoring or finding references.

I think it's clear that this is the ideal/intuitive user experience, but what are the challenges involved with getting there?

@OliverJAsh
Copy link
Contributor

OliverJAsh commented May 18, 2018

unless the project is open there is no really default config project for shared file to be able to deduce its being referenced in those other projects whose tsconfig's are not even in directory chain.

Could TypeScript/VSCode not check whether a file appears in all TS projects (in the root folder)? I presume this has performance challenges though?

@mhegazy
Copy link
Contributor

mhegazy commented May 18, 2018

Could TypeScript/VSCode not check whether a file appears in all TS projects (in the root folder)? I presume this has performance challenges though?

yes. the server only knows about open files/projects. a file can be referenced from any where on disk, and it is not manageable to search for possible incoming references everywhere.

I think a better solution for your scenario is #3469

@OliverJAsh
Copy link
Contributor

I think a better solution for your scenario is #3469

How do you imagine this (composite projects?) helping the situation? I guess we would have two TS projects, client and server—and then a composite project that depends on both of them? Would that then mean VSCode/TypeScript would show aggregate all errors (across potentially many TS projects) for a given file?

@mhegazy
Copy link
Contributor

mhegazy commented May 19, 2018

you would have a tsconfig.josn at the root that is empty, but has a set of project references to both projects, the server would load that one if it happened to be on the root of your project directory (the folder you used to open vscode code <folder>), and that will force all your projects to be loaded in memory.
this is still work in progress, so that is not available now.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented May 19, 2018

That makes sense! In that case, we can close this in favour of #3469

@OliverJAsh
Copy link
Contributor

Fixed by #3469

@OliverJAsh OliverJAsh unassigned ghost Apr 17, 2019
@OliverJAsh
Copy link
Contributor

@mhegazy

Re. #20185 (comment)

you would have a tsconfig.josn at the root that is empty, but has a set of project references to both projects, the server would load that one if it happened to be on the root of your project directory (the folder you used to open vscode code <folder>), and that will force all your projects to be loaded in memory.
this is still work in progress, so that is not available now.

This idea works with tsc --build, but I'm having a lot of teething issues getting it to play nicely in VS Code. Is this a problem with VS Code or TS server?

microsoft/vscode#80438
microsoft/vscode#80423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: TSServer Issues related to the TSServer
Projects
None yet
Development

No branches or pull requests

4 participants