Description
openedon Dec 18, 2018
Background
VS Code has proposed a smart selection API (microsoft/vscode#63935) that allows language extensions to intelligently control how selections are expanded and collapsed.
Just as an example, consider a simple class:
class Foo {
bar(a, b) {
if (a === b) {
return true
}
return false;
}
}
If the user starts with their cursor in the a
in a === b
expression, progressively running expand selection
may result in the following selections:
- The identifier
a
- The expression
a === b
- The body of the
bar
method - The entire
bar
method declaration - The entire
Foo
class
The exact selections we want may differ.
You can find the current state of the VS Code API proposal in vscode.proposed.d.ts
under the name selection range provider
Proposal
I think we should investigate supporting smart select for JavaScript and TypeScript users, but do so in a cross editor compatible way. The current proposal is derived from VS Code's needs so we should make sure it will work for other editors too
The current VS Code smart selection API proposal takes a position in a document and returns a list of potential expansion ranges. Each returned range also has some metadata about the range's kind (class, expression, statement, interface, ...)
On the TS Server side, a possible API would be:
interface SelectionRangeRequest extends FileLocationRequest {
command: "selectionRanges";
arguments: SelectionRangeRequestArgs;
}
interface SelectionRangeRequestArgs extends FileLocationRequestArgs { }
interface SelectionRangeResponse {
body?: ReadOnlyArray<SelectionRange>;
}
interface SelectionRange {
textSpan: TextSpan;
kind: SelectionKind;
}
// Either enum or string?
// VS Code has proposed a dot separated scope: expression.identifier, statement.if
enum SelectionKind {
Expression,
Statement,
Class
}
We also need to determine which selection ranges we should target for a first iteration. A few basic ones:
- Whole expression
- Statement line
- Class / interface
- Function
- Literal