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

Allow per-file setting for rename default behavior preferences #29593

Merged

Conversation

uniqueiniquity
Copy link
Contributor

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.

@uniqueiniquity
Copy link
Contributor Author

FYI @mjbvz

@mjbvz
Copy link
Contributor

mjbvz commented Jan 26, 2019

Thanks for the heads up @uniqueiniquity. Are you planning to take this in for 3.3.1?

@@ -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) };
Copy link
Member

@weswigham weswigham Jan 26, 2019

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)

Copy link
Contributor Author

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.

@@ -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) };
Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@RyanCavanaugh
Copy link
Member

Can we add a couple fourslash tests?

@uniqueiniquity
Copy link
Contributor Author

@RyanCavanaugh relevant fourslash test are in the PRs mentioned above (particularly #29314).

@uniqueiniquity
Copy link
Contributor Author

@sheetalkamat @weswigham I've addressed your comments; let me know if there's anything else.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

❤️

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.

5 participants