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

Let users select the file name with running the 'Move to file' refactoring #51772

Closed
octref opened this issue May 29, 2018 · 16 comments
Closed
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@octref
Copy link

octref commented May 29, 2018

microsoft/vscode#50486

Currently if the new file cannot be resolved, it would be newFile.ts. Later I would have to manually update the filename. And in the case when updateImportsOnFileMove.enabled is set to falsey, I'll have to rename the references to the new files too.
Would be better to show an input for filename when no reasonable guess for the new file name exists.

@octref octref changed the title Consider show an input box (Quick Open box or rename-like input box) for "Move to new file" Consider show a filename input box (Quick Open box or rename-like input box) for "Move to new file" May 29, 2018
@clarkio
Copy link

clarkio commented Jun 4, 2018

Maybe show this ability to name the file always?

If I'm refactoring code out of another file I'll most likely want to rename it something different than the class/function/variable name. Maybe this could be put into a setting to always prompt for file name?

@josteink
Copy link

josteink commented Aug 2, 2018

I also think this makes sense from a consistency-perspective.

When you extract a function inside a file, you're asked for a function-name - you don't have to accept a default name, and then apply the rename-refactoring.

The same should apply to this. Support for this should ideally be present in tsserver so this behaviour can easily be replicated in other editors too.

@mjbvz mjbvz added the feature-request A request for a new feature label Sep 12, 2018
@sevenryze
Copy link

I suggest one more request, that for quick refactoring and consistency, we could use a flag like - nameStrategy: [common name strategy] - to quick move function to a new file.

Also, i think for now, the new files are always located in the current folder aside as original file, could we set a different file path when using the filename open box?

@jrnail23
Copy link

jrnail23 commented Jul 3, 2019

I'm with @sevenryze here... We prefer to use kebab-casing for our file names, so I'd like to have that as a setting when moving a function to a new file.

@tommck
Copy link

tommck commented Sep 27, 2019

We could also use formatting in a setting like we do with the window-title

  "window.title": "${dirty}${activeEditorMedium}${separator}${rootPath}"

not sure exactly how we'd say stuff like "IFoo" => "foo.interface.ts" or something... would require some regex capture-style stuff with built-in functions like "table case", "camelCase", "dashify" or whatever.

Would love to have the dialog prompt minimally though. Right now I have to rename the file every time

@andreialecu
Copy link

andreialecu commented Jan 15, 2020

Would be great if this could show an input with predefined options in both pascal case and kebab case for quick picking, but also allow manual changes.

So for example, initiating a move of class SomeClassName to a new file would show a VSCode native input box (such as the command pallette one) that lets you pick from SomeClassName.ts and some-class-name.ts or allow you to type your own.

Possibly helpful:
https://www.npmjs.com/package/dasherize

@andreialecu
Copy link

Upon digging further it seems the new file name comes from typescript itself which doesn't offer the possiblity of overriding the file name. An issue might need to be opened in the TS repo as well.

https://github.com/microsoft/TypeScript/blob/master/src/services/refactors/moveToNewFile.ts#L50-L54

@hcharley
Copy link

hcharley commented Aug 4, 2021

Since it's been a while, I'd like to express my interest in having this feature. It would be a big help to me to kebab case new file names automatically.

@bobbyg603
Copy link

You might consider adding a comment/thumbs up to this issue in the TypeScript repo

@victorcrbt
Copy link

I'm currently refactoring a bunch of files in our project, and definitely having a prompt to chose the file name would be of great help.

@walidvb
Copy link

walidvb commented Dec 2, 2022

I'd love to be able to set te path to which the file will be saved, too. Couldn't find an issue open for that?

@mjbvz mjbvz added this to the Backlog milestone Dec 5, 2022
@mjbvz mjbvz changed the title Consider show a filename input box (Quick Open box or rename-like input box) for "Move to new file" Let users select the file name with running the 'Move to file' refactoring Dec 5, 2022
@mjbvz mjbvz removed this from the Backlog milestone Dec 5, 2022
@mjbvz mjbvz removed the feature-request A request for a new feature label Dec 5, 2022
@mjbvz mjbvz transferred this issue from microsoft/vscode Dec 5, 2022
@mjbvz mjbvz removed their assignment Dec 5, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Dec 5, 2022

Moving this to TS as it would require a new TSServer API to support this feature

Also somewhat related to #29988

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Dec 7, 2022
@simeyla
Copy link

simeyla commented Aug 2, 2023

This feature behaves very oddly when you have multiple symbols selected.
I selected a number of lines of code, one of which (not the first) was const NODE_ID = .....
It named the new file NODE_ID which was unexpected and not helpful.
Oddly I had previously done a search for NODE_ID which was still highlighted in my 'find' window.

@kellyrmilligan
Copy link

+1

@space11
Copy link

space11 commented Oct 27, 2023

I think now you can use refactor code: "Move to file" and from there select "Enter new file path...".
This allows you to enter a file name manually. Work good for me.

@hugoblanc
Copy link

The "Move to file" trick is not available on other language like python sadly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests