Skip to content

Add inserting/replacing range to suggestion items #35602

@mjbvz

Description

@mjbvz

From microsoft/vscode#10266

Search Terms

  • suggest / suggestion / complete / completions
  • TSServer

Background

Currently VS Code leaves it up to each extension/language to determine how completions work. Some languages implement completions so that selecting a completion replaces the current word:

c|onsole.log
// accept suggestion for `const` for cursor at pipe character
const.log

While other languages instead opt to insert the selected completion at the current position without replacement:

c|onsole.log
// accept suggestion for `const` for cursor at pipe character
constonsole.log

With microsoft/vscode#10266, VS Code is considering adding a setting that lets users pick between using the replace vs insert behavior for suggestion

Proposal

To support this new setting, VS Code needs two ranges for each suggestion item:

  • The range when in replacement mode
  • The range when in insert mode

As we let the user dynamically select with type of insertion to use with a keybinding, both of these ranges need to be provided up front.

On the VS Code side, we can do a fairly reasonable job guessing at what the insert/replace range should be, but in order to be more reliable we'd need this information from the TS Server

Discussion

  • Would this API proposal work for JS/TS?
  • How does VS handle completions today (insert vs replace)? Is there any way to control this behavior?
  • What are the cases where the insert/replace ranges would be different from what VS Code could compute itself? (bracket accessors or string literals for example) Maybe we only need to return additional range info in those cases?

/cc @minestarks @amcasey for VS
/cc @jrieken From VS Code

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions