FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add 'renameFile' command to services · Pull Request #23573 · microsoft/TypeScript · GitHub

Add 'renameFile' command to services - #23573

Merged
3 commits merged into
masterfrom
renameFile
Apr 20, 2018
Merged

Add 'renameFile' command to services#23573
3 commits merged into
masterfrom
renameFile

Conversation

Deleted user (ghost) commented Apr 20, 2018
edited by ghost
Loading

Copy link
Copy Markdown

Here's how I think it would work:

  • First, the user renames a file normally using the file explorer in their editor.
  • Tsserver will pick up on this change and update the project (which will break a lot of imports to the old location).
  • After the rename, the editor will offer the user to update references to the file.
  • If the user says yes, it will then ask tsserver to get code edits, passing in the old and new paths to the file.
  • Tsserver will walk all imports, see which ones are unresolved now and could have resolved to the old path (but don't since that's been moved now), and update them to the new path instead, and send these edits to the editor.
  • The editor will apply the edits to all files. (Hopefully with undo functionality if the user decides against renaming the file.)

This is a bit tricky on the tsserver side since we need to be able to figure out what unresolved imports could have resolved to. This meant I had to leave moduleResolutionCache around so we could look at the failed lookup locations for failed imports.

Fully expecting to need a lot of revision on this. CC Matt Bierner (@mjbvz) for protocol review.

Copy link
Copy Markdown
Contributor

//cc Matt Bierner (@mjbvz)

Copy link
Copy Markdown
Contributor

We also need to consider /// <reference path="..." /> comments. bonus point for tsconfig.json "files" entries.

ghost force-pushed the renameFile branch from 95525be to 505189f Compare April 20, 2018 17:37

Copy link
Copy Markdown

Ok, I think this flow makes sense and the api looks good.

We may also need an api to check if any renames are necessary so we can avoid prompting the user in cases with loose files

Comment thread src/services/tsconfig.json Outdated
"navigateTo.ts",
"navigationBar.ts",
"organizeImports.ts",
"../services/renameFile.ts",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

jsut renameFile.ts

Comment thread src/services/services.ts Outdated
return OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences);
}

function renameFile(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray<FileTextChanges> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

the name makes me think there is will rename the file as well.. how about getEditsForFileRename

Copy link
Copy Markdown
Author

Sheetal Nandi (@sheetalkamat) What's a good way to get access to the tsconfig.json source file given a Program object, so that we can make edits for it?

ghost merged commit 5c94bef into master Apr 20, 2018
ghost deleted the renameFile branch April 20, 2018 20:43

Mohamed Hegazy (mhegazy) commented Apr 20, 2018
edited
Loading

Copy link
Copy Markdown
Contributor

Andy (Andrewkraft) (@Andy-MS) the soruceFile for the tsconfig.json is stored in options.configFile, assuming one exists.

Copy link
Copy Markdown

FWIW: most IDEs I’ve used, asked me – before the file was actually moved: “Do you also want to update references?”
Naively, it seems like that could simplify the algorithm.

Copy link
Copy Markdown

Is this supposed to work for renaming folders as well? It doesn't seem to in VS Code 1.24 / TypeScript 2.9.1.

Copy link
Copy Markdown
Contributor

Folder rename should be working in typescript@2.9.2 and next VSCode release.

Copy link
Copy Markdown
Contributor

Filed #24904 to track folder renames.

This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL