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.
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 requestcursorInfoindependently.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 duringresolve.To address this, we should introduce a shared
cursorInfomechanism forSwiftLanguageService.codeAction(_:), so that allSyntaxCodeActionProviders participating inallSyntaxCodeActionscan access it when needed.A possible direction is to have
SyntaxCodeActionScopeexpose a way to retrievecursorInfofor the current scope. This should be:cursorInfoshould only be requested if at least one code action actually needs it.cursorInforesult rather than issuing duplicate requests.cursorInfoinretrieveRefactorCodeActions, so it would be ideal if that result could also be reused inretrieveSyntaxCodeActions.