Description
Follow up on #34930
Search terms
- refactor / refactoring
Problem
In VS Code, I often try to extract something to a function only to discover that this is not possible for the my current selection. The current UX for this is poor, since we offer no explanation of why the selection is not extractable.
Proposal
To fix this, we would like to have TS Server return a human readable message about why a refactoring cannot be applied. Client could then surface this information to users
With this proposal, TS Server would no silently longer dropping invalid refactorings like it does today and instead always return them but with an additional error message attached..
Protocol proposal
I believe this simplest approach is to add a new errorDescription
field on ApplicableRefactorInfo
:
interface ApplicableRefactorInfo {
name: string;
description: string;
inlineable?: boolean;
actions: RefactorActionInfo[];
errorDescription?: string;
}
Client would be expected to not to try to resolve invalid refactorings.
To implement this in a way that won't break existing clients, we also need a way for a client to express that they can handle these invalid refactorings:
interface GetApplicableRefactorsRequestArgs extends FileLocationOrRangeRequestArgs {
// better name?
returnInvalidRefactorings?: boolean;
}
If returnInvalidRefactorings
is not set, the TS Server should preserve its existing behavior, i.e. drop invalid refactorings