microsoft / microsoft/TypeScript

Extend tsserver interface to allow refactoring failure reporting

Open
#28,410 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Search Terms

refactoring report failure fail

Suggestion

I would like a way to report refactoring failures similar to rename fail report ("You cannot rename this element").
This change improves transparency.

Edit: This might imply changes in VS Code language server extension as well. I'm not familiar with it though.

Use Cases

This would be useful to allow refactorings to initially show the refactoring, but when invoking it, an error message should be shown, instead of just not showing the refactoring. This would be confusing to the user.

Examples

Let's say we want to inline a variable, that is not initialized. This should not be possible. But it is still useful to show the refactoring initially, since the user may be confused why the option doesn't show up.
Then, if the user wants to invoke the refactoring, they get the error message "Cannot inline uninitialized variable."

let notInitialized; // should not allow inlining, but tell user why

foo(notInitialized);

Checklist

My suggestion meets these guidelines:

  • [*] This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • [*] This wouldn't change the runtime behavior of existing JavaScript code
  • [*] This could be implemented without emitting different JS based on the types of the expressions
  • [*] This isn't a runtime feature (e.g. new expression-level syntax)

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 tracing the tsserver interface used for refactorings and compare it with the existing rename failure reporting. Check how the VS Code language server extension consumes these responses. Done means a failed refactoring returns a reason that the client can display instead of silently hiding the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.