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

Stop looking for the default configured project at node_modules #35011

Merged
merged 3 commits into from
Mar 3, 2020

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented Nov 8, 2019

Should help with #34843.

Basically, if go-to-defintion causes a node_modules file to be opened, it should probably not trigger loading of a new project (typically, the one at the project root, since that's where node_modules is).

@amcasey amcasey requested a review from sheetalkamat November 8, 2019 23:29
@amcasey
Copy link
Member Author

amcasey commented Nov 8, 2019

The tests pass - it's just a lint error.

@@ -1536,7 +1549,7 @@ namespace ts.server {
/*@internal*/
findDefaultConfiguredProject(info: ScriptInfo) {
if (!info.isScriptOpen()) return undefined;
const configFileName = this.getConfigFileNameForFile(info);
const configFileName = this.getConfigFileNameForFile(info, /*stopAtNodeModules*/ false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheetalkamat Would it be better to just always stop at node_modules? I couldn't figure out whether introducing this inconsistency to maintain back compat would cause problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of changing how we look for default config file name, we should change assignProjectToOpenedScriptInfo to not create configured project if default configured project is not loaded and script info has /node_modules/ in its path and its not orphan

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I passed false here to retain the old behavior. assignProjectToOpenedScriptInfo passes true, as does reloadConfiguredProjectForFiles.

I'm not sure I understand the orphan check in general or how it applies to this case. I think, roughly, you mean that we might want to do it if the node_modules file isn't in some other project, but I'm not sure I agree - it seems like we never want to load a configured project for a node_modules file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if that's the case why look for default configured project for such script infos in first place That is if block completely at https://github.com/microsoft/TypeScript/blob/master/src/server/editorServices.ts#L2670 completely?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I made the change at a lower level than assignProjectToOpenedScriptInfo was because I thought other consumers of getConfigFileNameForFile might need to be updated as well. For example, it seems like reloadConfiguredProjectForFiles should also not consider the default configured project.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheetalkamat I don't feel strongly about how this should be implemented. If you have a different approach in mind, please let me know and I'll do my best to adopt it.

@amcasey amcasey force-pushed the NodeModulesProjectRoot branch from 8d35b16 to 6515d37 Compare February 28, 2020 01:56
@amcasey
Copy link
Member Author

amcasey commented Feb 28, 2020

Just hit the same issue in material-ui, so rebasing and promoting from draft.

@amcasey amcasey marked this pull request as ready for review February 28, 2020 01:58
@amcasey
Copy link
Member Author

amcasey commented Feb 28, 2020

FYI @ahejlsberg, this was the pause we saw when we invoked go-to-def on CSS.Properties.

@amcasey amcasey changed the title Optionally stop looking for the default configured project at node_modules Stop looking for the default configured project at node_modules Mar 2, 2020
@amcasey amcasey merged commit dd6811f into microsoft:master Mar 3, 2020
@amcasey amcasey deleted the NodeModulesProjectRoot branch March 3, 2020 00:52
@@ -1664,6 +1664,13 @@ namespace ts.server {
const jsconfigFileName = asNormalizedPath(combinePaths(searchPath, "jsconfig.json"));
result = action(jsconfigFileName, combinePaths(canonicalSearchPath, "jsconfig.json"));
if (result) return jsconfigFileName;

// If we started within node_modules, don't look outside node_modules.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add tests so we have coverage for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was originally a draft PR to get feedback and I forgot to add them when I promoted it. Will do.

amcasey added a commit to amcasey/TypeScript that referenced this pull request Mar 10, 2020
When searching for a default configured project, stop at
`node_modules`.
amcasey added a commit that referenced this pull request Mar 25, 2020
* Add test for #35011

When searching for a default configured project, stop at
`node_modules`.

* Be more explicit about inferred projects

* Move test into tsserver/projects.ts

* Use existing helpers to simplify tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants