microsoft / microsoft/TypeScript
Extract to constant in enclosing scope should optionally also replace later usage
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
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 😉
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 TypeScript 仓库中找到 extract-to-constant 重构的实现及其测试。复现所示的 TypeScript 示例,然后跟踪选择边界和后续出现位置的处理方式。完成的标准是:可选的外层作用域提取只有在后续使用位置被选中时,才能包含这些后续使用位置,并将启发式命名单独考虑。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100