Skip to content

Conversation

@loveucifer
Copy link
Contributor

@loveucifer loveucifer commented Jan 4, 2026

Summary

fixes #2382

Maps SourceKit semantic refactoring action strings to specific LSP CodeActionKind values instead of using the generic refactor kind. This enables standard refactoring keybindings and code action filtering to work properly for Swift.

Images After The Change

test1 test2

Changes

  • Added lspKind computed property to SemanticRefactorCommand that maps:
    • Actions containing .extract.refactor.extract
    • Actions containing .inline.refactor.inline
    • Others → refactor (fallback)
  • Updated retrieveRefactorCodeActions to use the new lspKind property

@loveucifer loveucifer marked this pull request as ready for review January 4, 2026 15:34
Copilot AI review requested due to automatic review settings January 4, 2026 15:34
@loveucifer loveucifer requested a review from rintaro as a code owner January 4, 2026 15:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Maps SourceKit semantic refactoring action strings to specific LSP CodeActionKind values instead of using the generic refactor kind, enabling proper filtering and keybinding support for Swift refactoring actions.

  • Added lspKind computed property to SemanticRefactorCommand that intelligently maps SourceKit action strings to LSP kinds
  • Updated code action creation to use the new specific lspKind property
  • Updated test expectations to verify correct refactor.extract kind

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Sources/SwiftLanguageService/SemanticRefactorCommand.swift Added lspKind computed property with mapping logic for extract/inline/default refactoring kinds
Sources/SwiftLanguageService/SwiftLanguageService.swift Updated code action creation to use lspKind instead of generic .refactor
Tests/SourceKitLSPTests/CodeActionTests.swift Updated test assertion to expect .refactorExtract kind

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, nice and simple scraping of the sourcekitd action ID. I like it 🙂

Should we also map .convert. to refactorRewrite and .move. to refactorExtract? Just looked through the list of sourcekitd refactorings in https://github.com/swiftlang/swift/blob/9b452820367ccc7b5d9effbc1565bcd945c81768/include/swift/Refactoring/RefactoringKinds.def#L21-L92.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍🏽

@ahoppen
Copy link
Member

ahoppen commented Jan 5, 2026

@swift-ci Please test

@ahoppen ahoppen merged commit 5c0e7f2 into swiftlang:main Jan 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support 'refactor.extract.variable' refactoring

2 participants