Skip to content

API that allows code action providers to reliably get the current selection #49024

@mjbvz

Description

@mjbvz

Problem
Extensions that use CodeActionProvider to return refactorings almost always want to compute refactorings based on the current selection. The range current passed to a CodeActionProvider may be the selection or it may be the range of a diagnostic within the current document.

As a workaround, extensions have to try getting the selection from activeTextEditor

Proposal

Add a selection property to CodeActionContext. This optional property would have the current selection in the document.

Alternative designs

  • Introduce a CodeActionProvider2 that has more deterministic behavior for range.
  • When registering a CodeActionProvider, allow extensions to request that range should always be the current selection

/cc @kieferrm

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions