Skip to content

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

Merged
uniqueiniquity merged 5 commits intomicrosoft:masterfrom
uniqueiniquity:filePreferenceForRenames
Jan 31, 2019
Merged

Allow per-file setting for rename default behavior preferences#29593
uniqueiniquity merged 5 commits intomicrosoft:masterfrom
uniqueiniquity:filePreferenceForRenames

Conversation

@uniqueiniquity
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

FYI @mjbvz

@mjbvz
Copy link
Copy Markdown
Contributor

mjbvz commented Jan 26, 2019

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

Comment thread src/server/session.ts Outdated
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/server/session.ts Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Can we add a couple fourslash tests?

@uniqueiniquity
Copy link
Copy Markdown
Contributor Author

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

@uniqueiniquity
Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants