microsoft / microsoft/TypeScript

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

Open
#40,922 1 comment 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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

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 by reading the existing TS Server commands and the getCombinedCodeFix path mentioned in the issue, then compare how VS Code invokes source.removeUnused. Done means a command removes only safe unreachable code, unused imports, and unused declarations while leaving parameters and potentially side-effectful variables untouched.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.