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

"Open Symbol By Name" is not working properly in multipy typescript projects. #8081

Closed
heroboy opened this issue Jun 24, 2016 · 11 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug typescript Typescript support issues verified Verification succeeded
Milestone

Comments

@heroboy
Copy link

heroboy commented Jun 24, 2016

  • VSCode Version:1.2.1
  • OS Version: windows 8.1

Steps to Reproduce:

  1. create a project like:
a/a.ts
a/tsconfig.json   => files:["a.ts"]
b/b.ts
b/tsconfig.json   => files:["b.ts"]
c.ts
  1. Ctrl+P and type "#" to search some symbols in "a.ts" "b.ts" or "c.ts". You will expect they will be seached. But the search result is depend on which file is currently opening or something else maybe open file order.

For exmaple:
open "c.ts" and insert:

import "./b.ts"

Then you can search symbols in "b.ts". Then comment it, and if symbols in "b.ts" can be searched is undetermined, sometime can and sometime can't.

And in my another project, only symbols in ".d.ts" can be searched.

And another problem is I can't search variable names in global scope, even I export it.

@zhengbli
Copy link

zhengbli commented Jun 24, 2016

We do only build projects for opened files in tsserver. However, after you commenting of the import clause, you shouldn't be able to search for the symbols in b.ts, and this should be consistent. The "undetermined" behavior you described is problematic.

What is the setup of your other project which only ".d.ts" symbols can be searched? We recently added test infrastructure for the project system, this should be able to help us eliminate problems.

@zhengbli
Copy link

In addition, the order in which the files are opened matters by design. When one file belongs to multiple projects, we try to resolve the conflict by determining which types of project has a higher priority. But sometimes there are no ways to know which one the file is "intended" to belong to. So in cases like these, it goes to the first project created.

@heroboy
Copy link
Author

heroboy commented Jun 24, 2016

@zhengbli
My another project layout is just like the above project I described.
I setup another project to test:

a/a.ts => function afunc(){}
a/main.ts => import "./a.ts"
b/b.ts => function bfunc(){}
b/main.ts => import "./b.ts"

Then I tried several times, each time I close all working files and restart vscode.

  1. open "a/main.ts".
  2. "afunc" found, and "bfunc" not. It's ok.
  3. open "b/main.ts"
  4. "afunc" found, and "bfunc" not. I think "bfunc" should be found.
  5. close all files
  6. "afunc" and "bfunc" not found. It's ok
  7. open "b/main.ts"
  8. "bfunc" found, and "afunc" not. It's ok.
  9. open "a/main.ts"
  10. "bfunc" found, and "afunc" not. I think "afunc" should be found.

@heroboy
Copy link
Author

heroboy commented Jun 24, 2016

When "bfunc" can't be found, even I opened "b.ts", it still can't be found.

@zhengbli
Copy link

Thanks for the detailed repro procedure! Indeed I see this on my machine too. I'll dig deeper tomorrow, it could be either the project system or the navBar APIs.

@heroboy
Copy link
Author

heroboy commented Jun 24, 2016

"We do only build projects for opened files in tsserver."

If I don't open the project entry ts files, tsserver will not known "all files" in the project. And can't implment a reasonable "Open Symbol By Name".For exmaple, if I close all files,and create a new ts file in the project. Then no symbol will found. It looks not good.

Will tsserver search all tsconfig.json to build projects? I think this is the right way.

@zhengbli
Copy link

Indeed this is not ideal for features like "Go to anything" in sublime. We are working on supporting the "Open Project" api, which will keep the project alive regardless of the opening files, though it will likely land after 2.0 release.

Actively searching for all tsconfig.json by default can be resource-intensive, because for each project we have to open all the files and watch the files and directories etc, we want to be efficient about the resource allocation. Currently in most cases users open the editor at one project root, so it may not be worth it to eagerly build everything by default. Though we can think about adding configuration to enable such scenarios if the user really wants to. This also align to the suggestion we had about extend our definition of projects on tsserver to support "mid-sized" scenarios (microsoft/TypeScript#3469).

@dbaeumer dbaeumer self-assigned this Jun 24, 2016
@dbaeumer dbaeumer added the typescript Typescript support issues label Jun 24, 2016
@zhengbli
Copy link

So I took a further look of the request / response records, and it seems that VSCode is not sending the correct file name for the navto command:

[open a/main.ts, and try to search the afunc symbol]

Sending request: navto (33). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "c:/Users/zhengbli/Documents/playground/testMultipleProjects/a/main.ts",
    "searchValue": "afun"
}

This is the correct behavior.

[Then open b/main.ts, and try to search the bfunc symbol]

Sending request: navto (37). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "c:/Users/zhengbli/Documents/playground/testMultipleProjects/a/main.ts",
    "searchValue": "bfun"
}

This doesn't seem right, as the file argument is still the a/main.ts instead of the current file. Then the symbol search won't be in the right project.

@dbaeumer dbaeumer added this to the July 2016 milestone Jun 27, 2016
@dbaeumer
Copy link
Member

@zhengbli thanks. I will have a look.

@isidorn isidorn modified the milestones: August 2016, July 2016 Jul 26, 2016
@dbaeumer dbaeumer added the bug Issue identified by VS Code Team member as probable bug label Aug 26, 2016
@dbaeumer
Copy link
Member

I fix this by taking the active document as the context. However TS still doesn't provide a global workspace search. The search is always limited to a TS project.

@dbaeumer
Copy link
Member

Opened #11026 to see if we can fake this.

@jrieken jrieken added the verified Verification succeeded label Sep 1, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug typescript Typescript support issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants