Skip to content

TSServer: Smart select API #29071

Closed

Description

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:

  1. The identifier a
  2. The expression a === b
  3. The body of the bar method
  4. The entire bar method declaration
  5. 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

/cc @DanielRosenwasser, @jrieken, @amcasey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

APIRelates to the public API for TypeScriptDomain: TSServerIssues related to the TSServerIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScriptVS Code PriorityCritical issues that VS Code needs fixed in the current TypeScript milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions