Skip to content

Add replacementSpan for string completions #29270

@mjbvz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: APIRelates to the public API for TypeScriptDomain: LS: Completion ListsThe issue relates to showing completion lists in an editorDomain: LS: TSServerIssues related to the TSServerExperience EnhancementNoncontroversial enhancementsFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions