Skip to content

Fix renaming of node_modules #49568

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

Merged
merged 12 commits into from
Jun 17, 2022
Merged

Fix renaming of node_modules #49568

merged 12 commits into from
Jun 17, 2022

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Jun 15, 2022

Fixes #45668.
I think it also fixes #48681.

The rule I'm trying to implement is the following:

  1. If we try to rename from a project, and that would cause us to rename something in node_modules/, don't allow that rename.
  2. If we try to rename from inside a node_modules package, only allow renames that would not affect a different package.

I'd like some feedback on the wording in the diagnostic message.
I'll update the tests' verify.renameInfoFails() calls once there's a definitive diagnostic message.

Note: I had to change getRenameInfo to take a user preferences parameter, because I needed to know if providePrefixAndSuffixTextForRename (surfaced as "Use Aliases For Renames" in vscode) is set or not. Since that function was already taking as parameter another option that comes from user preferences, it made sense to me to change that. A lot of the diff is refactoring related to that change.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jun 15, 2022
@gabritto gabritto requested review from amcasey and andrewbranch June 15, 2022 23:06
@@ -8822,6 +8822,7 @@ namespace ts {
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
readonly includeInlayEnumMemberValueHints?: boolean;
readonly allowRenameOfImportPath?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Ironically, I think this always belonged in UserPreferences, and providePrefixAndSuffixTextForRename always should have been a per-request option. 🙃 Baby steps in the right direction...

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

Minor suggestions, plus some thoughts on avoiding the breaking change, if we think that's worthwhile.

@@ -5877,6 +5877,8 @@ declare namespace ts {
getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined;
getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined;
getRenameInfo(fileName: string, position: number, preferences: UserPreferences): RenameInfo;
/** @deprecated */
Copy link
Member

Choose a reason for hiding this comment

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

Comment about using the other overload?

@@ -6255,6 +6257,7 @@ declare namespace ts {
Insert = "insert",
Remove = "remove"
}
/** @deprecated - consider using EditorSettings instead */
Copy link
Member

Choose a reason for hiding this comment

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

Could be a bad diff, but I'm seeing EditorOptions deprecated? What changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was marked deprecated before, but with a normal comment (/* */) as opposed to JSDoc (/** */), just a drive-by fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rename typescript default import will modify types under node_modules F2 renaming can cascade into node_modules .d.ts files for objects
4 participants