microsoft / microsoft/TypeScript

Rename file when renaming default export

Open
#29,294 0 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: LS: Refactorings Needs Proposal Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Currently we can use the rename symbol command and that will rename the symbol and its usages (exports, imports, usages in other files, etc.). That's a great start, but I'd love to see this feature expanded to do the following:

  • Many times a file name will coincide with the symbol being refactored. The refactor option should be available when renaming the file, so everything can be done at once.

  • In addition to the refactor changing symbol references across all files, it'd be nice to have the ability to also update comments, strings, etc. that refer to that symbol.

Code Example:

Shape.js

class Shape {}
export default Shape;

Circle.js - We reference Shape as an import, extends, inside a comment, and inside a string. They should all be refactored.

import Shape from "./Shape";

// Shape subclass
class Circle extends Shape {
  constructor() {
    super();
    console.log('A circle is a Shape.');
  }
}

export default Circle;

WebStorm Examples

screen shot 2019-01-04 at 8 36 22 pm screen shot 2019-01-04 at 8 37 02 pm

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing rename symbol command and trace how it updates exports, imports, and usages across files. Use the Shape.js and Circle.js example as the acceptance case: renaming the default export should also rename the matching file and update the shown import, comment, and string references.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.