Vscode: TypeScript Rename File Refactoring

Created on 26 Jan 2017  路  16Comments  路  Source: microsoft/vscode

When moving a file (drag'n drop), we then have to manually change every path where we used that file.

It would be nice to update all the import where we used that file.

feature-request file-explorer on-testplan typescript upstream

Most helpful comment

Hi, any news?

All 16 comments

Cool idea!

cc @bpasero @dbaeumer @mjbvz

@waderyan this would best require some support from TypeScript to find all places where the file to be moved is referenced.

The change file location refactoring required to implement this is tracked by https://github.com/Microsoft/TypeScript/issues/6487

I believe webstorm has this functionality already, which would mean this is possible without needing changes to typescript? Unless this issue is specifically for refactoring typescript and not ES6 javascript?

this would be nice!

Is this issue only about TypeScript? If something was implemented upstream for this, would it also benefit JavaScript files? And what about all other file types? What if we used an implementation that would work for all files?

Anytime a file is renamed/moved, search all files in workplace for references to that file, and update the references. For each folder in the workspace, we calculate what a relative path to the renamed file would look like. Then search all files in that folder for a string that matches that relative path, and update any that were found. Or something along those lines...

@AdenFlorian I also think this is not limited to Typescript.
Language server protocol have rename request in specification (https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#rename-request)
But that is just used for notifying renaming from editor. I guess we need some specification in language server protocol to fetch what will be occur after renaming the file.
Such a specification seems in discussion at this issue(https://github.com/Microsoft/language-server-protocol/issues/272).

Hi, any news?

Need this feature too

I think this would be exceptionally useful!

Coming to VS Code from WebStorm this is the only feature I found myself seriously missing!

Not just for TypeScript, but for ES6 and every other language. I'm not sure how JetBrains implements it, but I wonder if it would be possible to recognize path strings in the code and when a file within the project is moved or renamed, all path strings affected by the change could be updated.

Edit: I missed @AdenFlorian comment above somehow. +1

How can people code without this feature?! This is the only reason stopping me from switching over to VSCode from WebStorm.

Hello @webberwang,

while I also miss this feature a lot, this extension helps (even it's not as comfortable as Webstorm): https://marketplace.visualstudio.com/items?itemName=stringham.move-ts

(tbh for larger refactorings I still temporarily switch back to Webstorm)

@nilshartmann thanks for the suggestion, I'll check out that extension

Seems implemented and just merged in Typescript - https://github.com/Microsoft/TypeScript/pull/23726
Looking forward to the integration to vscode!!

Fixed by #50074

However the feature only works if you are using the latest typescript@next build (the current typescript 2.9 version bundled in VS Code insiders is missing a few required fixes). We'll pick up a new typescript build with the fix sometime this week and it will also be included with VS Code 1.24

The initial version also only support single file moves/renames. Extending this to whole directory moves/renames is tracked by #50244

Was this page helpful?
0 / 5 - 0 ratings

Related issues

v-pavanp picture v-pavanp  路  3Comments

lukehoban picture lukehoban  路  3Comments

trstringer picture trstringer  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments

omidgolparvar picture omidgolparvar  路  3Comments