microsoft / microsoft/TypeScript

Add TS server command for removing all unused code in a file

未关闭
#40,922 1 条评论 8 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Domain: LS: Quick Fixes Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

Search terms

  • code action
  • source action
  • getCombinedCodeFix

Feature request

Add a new TS Server command that removes all unused code in a file. This should only perform 'safe' removals, such as:

  • Unreachable code
  • Unused imports
  • Unused declarations

We should likely not remove unused parameters. Not sure about removing unused variable since removing them can also have side effects

Use case

VS Code allows users to configure code actions that are run on save. One of the supported code actions is source.removeUnused which attempts to remove unused code in a file

On the VS Code side, we can't implement this very well since unused code often ends up overlapping with other unused code and we don't have much insight into what is "safe" to remove and what is not

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读现有的 TS Server 命令和 issue 中提到的 getCombinedCodeFix 路径,然后比较 VS Code 如何调用 source.removeUnused。完成的标准是:某个命令只移除安全的不可达代码、未使用的 import 和未使用的声明,同时保留参数和可能具有副作用的变量不变。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。