Add opt-in user preference for prefix and suffix text on renames#29314
Add opt-in user preference for prefix and suffix text on renames#29314uniqueiniquity merged 21 commits intomicrosoft:masterfrom
Conversation
src/server/session.ts
Outdated
There was a problem hiding this comment.
this.getHostPreferences().usePrefixAndSuffixTextForRename || false [](start = 16, length = 66)
Since there may be multiple preferences affecting rename behavior (e.g. #28677), would it make more sense to pass in the entire preferences object (e.g. as in getEditsForFileRename)?
There was a problem hiding this comment.
Switched to passing entire preferences object.
However I only passed it as deep as this call; any deeper would require an API change, so I didn't want to do that unless absolutely necessary.
|
Do you have a plan for when and how to remove this code? It's pretty ugly and I think it will only be needed for another 6 months or so. (Maybe more, depending on how long we ship new versions of TS to old versions of VS). |
|
@sandersn Don't we have to keep this until the newest version of VS without the opt-in is deprecated? I'm guessing that will be longer than 6 months. |
|
@amcasey Per our in-person discussion, we'll want to ship new TS servers to VS versions that shipped at least 2 years ago. (Plus we haven't done the work to make VS work with the new API anyway.) |
sandersn
left a comment
There was a problem hiding this comment.
I take it you figured out how to make this work without changing getTypeAtLocation at all? If so, then sounds good. :)
|
@sandersn yep, it was a red herring. |
|
@amcasey Can you take another look? I attempted to consolidate conditions like we discussed. |
amcasey
left a comment
There was a problem hiding this comment.
Still a few questions but generally LGTM.
|
Does this being a config setting mean it'll count as fixing #29238? |
|
@weswigham It means editors will have the option of exposing that as a setting but, arguably, it won't be fixed until they do. |
|
Since we've had a number of asks for #29238, we should try to make sure it's exposed as a setting in VS and VSCode, at least. |
|
@weswigham we can certainly plan to make it optional in VS. AFAIK @mjbvz has already made it the default in VS Code |
|
@amcasey Correct on your first comment, in no case do we want to rename the identifier |
* origin/master: (64 commits) Fix resolution of properties from prototype assignment in JS (microsoft#29302) Include all flow nodes made within `try` blocks as antecedents for `catch` or `finally` blocks (microsoft#29466) Don't treat interfaces as implementations Make the relationship between partial mapped types and the empty object not apply for subtype relationship (microsoft#29384) Add missing arity check on second inference pass (microsoft#29386) renames add missing type annotation PR feedback Illustrate a case that isn't handled correctly Add fourslash tests Consider JSX namespace imports when moving statements between files Fix gulp builds not building some targets Update user baselines (microsoft#29444) Add opt-in user preference for prefix and suffix text on renames (microsoft#29314) Fake up value declaration for synthetic jsx children symbol so they get excess property checked (microsoft#29359) Add regression test. (microsoft#29433) Elaborate jsx children elementwise (microsoft#29264) Add regression test PR feedback Fix trailing whitespace ...
* origin/master: (64 commits) Fix resolution of properties from prototype assignment in JS (microsoft#29302) Include all flow nodes made within `try` blocks as antecedents for `catch` or `finally` blocks (microsoft#29466) Don't treat interfaces as implementations Make the relationship between partial mapped types and the empty object not apply for subtype relationship (microsoft#29384) Add missing arity check on second inference pass (microsoft#29386) renames add missing type annotation PR feedback Illustrate a case that isn't handled correctly Add fourslash tests Consider JSX namespace imports when moving statements between files Fix gulp builds not building some targets Update user baselines (microsoft#29444) Add opt-in user preference for prefix and suffix text on renames (microsoft#29314) Fake up value declaration for synthetic jsx children symbol so they get excess property checked (microsoft#29359) Add regression test. (microsoft#29433) Elaborate jsx children elementwise (microsoft#29264) Add regression test PR feedback Fix trailing whitespace ...
<!-- Thank you for submitting a pull request! Here's a checklist you might find useful. * [ ] There is an associated issue that is labeled 'Bug' or 'help wanted' or is in the Community milestone * [ ] Code is up-to-date with the `master` branch * [ ] You've successfully run `jake runtests` locally * [ ] You've signed the CLA * [ ] There are new or updated unit tests validating the change Refer to CONTRIBUTING.MD for more details. https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md --> 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 - I just tried this new feature for the first time (thank you so much for building it!) and I was surprised that renaming a property of a named, destructured export wouldn't rename the symbol when it's imported in another file. Is this expected? I'll file a separate issue if not expected. Here's the repro:
type ReadonlyAndNotUndefined<T> = { readonly [P in keyof T]: string; }
export const {
APP_NAME,
MONGODB_CONNECTION_URI,
SENDGRID_API_KEY,
NOTIFICATION_URL_BASE,
NOTIFICATION_FROM_EMAIL,
} = process.env as ReadonlyAndNotUndefined<typeof process.env>;
import { NOTIFICATION_URL_BASE, SENDGRID_API_KEY, NOTIFICATION_FROM_EMAIL } from './env';
Expected: name is also changed in Note that if you export individual variables (not via destructuring export) the rename works fine, e.g. |
Fixes #28679
This PR adds a user preference which, if not set, returns the rename behavior on shorthand properties and import/export specifiers to its state in 3.1.