Skip to content

Add replacementSpan for string completions #29270

Closed

Description

@mjbvz

TypeScript Version: 3.3.0-dev.2019010

From microsoft/vscode#53962

Search Terms:

  • completions / suggestions
  • replacementSpan

Problem

For code such as:

interface TFunction {
    (_: 'login.title', __?: {}): string;
    (_: 'login.description', __?: {}): string;
    (_: 'login.sendEmailAgree', __?: {}): string;
    (_: 'login.termsOfUse', __?: {}): string;
    (_: 'login.privacyPolicy', __?: {}): string;
    (_: 'login.sendEmailButton', __?: {}): string;
    (_: 'login.emailInputPlaceholder', __?: {}): string;
    (_: 'login.errorWrongEmailTitle', __?: {}): string;
    (_: 'login.errorWrongEmailDescription', __?: {}): string;
    (_: 'login.errorGeneralEmailTitle', __?: {}): string;
    (_: 'login.errorGeneralEmailDescription', __?: {}): string;
    (_: 'login.loginErrorTitle', __?: {}): string;
    (_: 'login.loginErrorDescription', __?: {}): string;
    (_: 'login.openEmailAppErrorTitle', __?: {}): string;
    (_: 'login.openEmailAppErrorDescription', __?: {}): string;
    (_: 'login.openEmailAppErrorConfirm', __?: {}): string;
  }

const f: TFunction = (() => {}) as any;

f('login.email|')

Where a completion is being triggered at the | in the f call. VS code currently manually tries to compute the span to replace within the string. This is not very reliable because we are only have the text content of the document.

Proposal:
For strings completions, it would be helpful if TS could return the entire range to be replaced with the replacementSpan property on the completion item. This should be more reliable than having VS code try to compute it.

In the above case, the replacement span would cover the range of login.email

Activity

  1. added
    Domain: API
    Domain: LS: Completion Lists
    Domain: LS: TSServer
    Experience Enhancement
    on Jan 7, 2019
  2. Kingwl commented on Mar 23, 2020

    @Kingwl
    Contributor

    I have founded setting editor.suggest.insertMode is already existed in vscode.
    And replacementSpan is already existed in completion entry.
    Is that mean we just need to fill the replacementSpan in the ts side?
    And should we always fill that in all of request even editor.suggest.insertMode is turn on?

  3. DanielRosenwasser commented on Apr 2, 2020

    @DanielRosenwasser
    Member
  4. added
    Fixed
    on Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: APIDomain: LS: Completion ListsDomain: LS: TSServerExperience EnhancementFixedSuggestion

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy