Skip to content

Shared cursorInfo infrastructure in SwiftLanguageService.codeAction(_:) #2584

Description

@rintaro

Some code actions need type information (via cursorInfo) to determine whether they are applicable to the current selection. Today, there is no shared infrastructure for this, so each implementation would need to request cursorInfo independently.

In general, expensive work for code actions should be deferred to codeAction/resolve. However, for cases where applicability itself depends on semantic information, deferring this check can lead to a poor experience: a code action may appear applicable initially but then fail during resolve.

To address this, we should introduce a shared cursorInfo mechanism for SwiftLanguageService.codeAction(_:), so that all SyntaxCodeActionProviders participating in allSyntaxCodeActions can access it when needed.

A possible direction is to have SyntaxCodeActionScope expose a way to retrieve cursorInfo for the current scope. This should be:

  • Lazy: cursorInfo should only be requested if at least one code action actually needs it.
  • Shared: multiple providers should reuse the same cursorInfo result rather than issuing duplicate requests.
  • Composable with existing flows: we already request cursorInfo in retrieveRefactorCodeActions, so it would be ideal if that result could also be reused in retrieveSyntaxCodeActions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions