-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Allow per-file setting for rename default behavior preferences #29593
Allow per-file setting for rename default behavior preferences #29593
Conversation
FYI @mjbvz |
Thanks for the heads up @uniqueiniquity. Are you planning to take this in for 3.3.1? |
src/server/session.ts
Outdated
@@ -1178,7 +1178,7 @@ namespace ts.server { | |||
private getRenameInfo(args: protocol.FileLocationRequestArgs): RenameInfo { | |||
const { file, project } = this.getFileAndProject(args); | |||
const position = this.getPositionInFile(args, file); | |||
const preferences = this.getHostPreferences(); | |||
const preferences = { ...this.getHostPreferences(), ...this.getPreferences(file) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we shouldn't just change
getPreferences(file: NormalizedPath): protocol.UserPreferences {
const info = this.getScriptInfoForNormalizedPath(file);
return info && info.getPreferences() || this.hostConfiguration.preferences;
}
in editorServices.ts
into
getPreferences(file: NormalizedPath): protocol.UserPreferences {
const info = this.getScriptInfoForNormalizedPath(file);
return { ...this.hostConfiguration.preferences, ...info && info.getPreferences()};
}
? (And just use this.getPreferences(file)
here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Changed to that.
src/server/session.ts
Outdated
@@ -1178,7 +1178,7 @@ namespace ts.server { | |||
private getRenameInfo(args: protocol.FileLocationRequestArgs): RenameInfo { | |||
const { file, project } = this.getFileAndProject(args); | |||
const position = this.getPositionInFile(args, file); | |||
const preferences = this.getHostPreferences(); | |||
const preferences = { ...this.getHostPreferences(), ...this.getPreferences(file) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure whats the intent here with preference per file? Rename is an operation that affects multiple files. So even though rename originated in say file A (whose preferences we are checking as per this PR), what happens to rename locations in B.. Shouldn't we prefer rename preferences of B for the locations in that file instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjbvz, what do you think? I agree that this setup is a bit odd for this particular operation, but it would definitely be more complicated to give each file the agency to decide for itself which rename location strategy to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with @mjbvz offline. He was in favor of the originating file determining the behavior of the whole operation. I've added a test and comment to make this clear.
Can we add a couple fourslash tests? |
@RyanCavanaugh relevant fourslash test are in the PRs mentioned above (particularly #29314). |
@sheetalkamat @weswigham I've addressed your comments; let me know if there's anything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Fixes #29585.
#29314 and #29385 made it so their respective settings are only recognized when provided to the host as a whole.
This PR makes it so that the relevant settings for the preferences on the file override those of the preferences on the host.