microsoft / microsoft/TypeScript
Extract to constant in enclosing scope should optionally also replace later usage
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Given this code:
public setParts(lineNumber: number, parts: GhostTextPart[]): void {
const foreground = this.themeService.getColorTheme().getColor(ghostTextForeground);
let opacity: string | undefined = undefined;
let color: string | undefined = undefined;
if (foreground) {
opacity = String(foreground.rgba.a);
color = Color.Format.CSS.format(opaque(foreground))!;
}
const borderColor = this.themeService.getColorTheme().getColor(ghostTextBorder);
let border: string | undefined = undefined;
if (borderColor) {
border = `2px dashed ${borderColor}`;
}
I would like to factor our this.themeService.getColorTheme() and extract it into its own constant. This should include all later usages.
Since there could be side effects in between, I suggest to do it only if later occurences are also selected.
This is my current workflow and I don't feel smart doing it like that. Multicursors don't really help here.

Also, it would be nice if the name of the new local is heuristically derived from the expression ((...).getFooBar(...) -> fooBar`).
I'm willing to do a PR if I get some pointers.
Let's make the editing experience in VS Code even more amazing 😉
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the extract-to-constant refactoring implementation and its tests in the TypeScript repository. Reproduce the shown TypeScript example, then trace how selection boundaries and later occurrences are handled. Done means an optional enclosing-scope extraction can include later uses only when selected, with heuristic naming considered separately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100