-
Notifications
You must be signed in to change notification settings - Fork 381
Add refactoring action to convert stored to computed properties #2622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,27 +16,87 @@ package import SourceKitLSP | |
| import SwiftRefactor | ||
| package import SwiftSyntax | ||
|
|
||
| /// Data that is included in a `CodeAction` response for which the client should resolve the edit lazily using a `codeAction/resolve` request. | ||
| /// | ||
| /// This data allows us to re-construct the `SyntaxCodeActionScope`. | ||
| package struct UnresolvedCodeActionData: Codable, LSPAnyCodable { | ||
| /// A string representation of the syntax refactoring action's type. | ||
| package let action: String | ||
|
|
||
| /// The document on which the code action should be applied. | ||
| package let document: VersionedTextDocumentIdentifier | ||
|
|
||
| /// The range at which the code action was originally requested. | ||
| package let range: Range<Position> | ||
|
|
||
| /// Action-specific data describing what data needs to be resolved asynchronously during the resolve request. | ||
| package let data: LSPAny | ||
|
|
||
| init<Metatype: ResolvableSyntaxRefactoringCodeActionProvider>( | ||
| actionType: Metatype.Type, | ||
| document: VersionedTextDocumentIdentifier, | ||
| range: Range<Position>, | ||
| data: LSPAny | ||
| ) { | ||
| self.action = "\(Metatype.self)" | ||
| self.document = document | ||
| self.range = range | ||
| self.data = data | ||
| } | ||
| } | ||
|
|
||
| /// Describes types that provide one or more code actions based on purely | ||
| /// syntactic information. | ||
| package protocol SyntaxCodeActionProvider: SendableMetatype { | ||
| /// Produce code actions within the given scope. Each code action | ||
| /// corresponds to one syntactic transformation that can be performed, such | ||
| /// as adding or removing separators from an integer literal. | ||
| static func codeActions(in scope: SyntaxCodeActionScope) -> [CodeAction] | ||
|
|
||
| /// Resolve semantic information for a code action. | ||
| static func resolve( | ||
| _ codeAction: CodeAction, | ||
| in scope: SyntaxCodeActionScope, | ||
| unresolvedData: LSPAny, | ||
| symbolInfo: (_ position: Position) async throws -> [SymbolDetails] | ||
| ) async throws -> CodeAction | ||
| } | ||
|
|
||
| extension SyntaxCodeActionProvider { | ||
| package static func resolve( | ||
| _ codeAction: CodeAction, | ||
| in scope: SyntaxCodeActionScope, | ||
| unresolvedData: LSPAny, | ||
| symbolInfo: (_ position: Position) async throws -> [SymbolDetails] | ||
| ) async throws -> CodeAction { | ||
| throw ResponseError.internalError("Resolve not implemented for '\(Self.self)'") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should return Or, make
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to return
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this change (i.e. this is still throwing an error). |
||
| } | ||
| } | ||
|
|
||
| extension TextDocumentClientCapabilities.CodeAction.ResolveSupportProperties { | ||
| var canResolveEdit: Bool { | ||
| return self.properties.contains("edit") | ||
| } | ||
| } | ||
|
|
||
| /// Defines the scope in which a syntactic code action occurs. | ||
| package struct SyntaxCodeActionScope { | ||
| /// Whether the client supports the codeAction/resolve request. | ||
| /// | ||
| /// This allows code actions to use a syntactic fallback if semantic information cannot be resolved using the `codeAction/resolve` request. | ||
| package var resolveSupport: TextDocumentClientCapabilities.CodeAction.ResolveSupportProperties? | ||
|
|
||
| /// The snapshot of the document on which the code actions will be evaluated. | ||
| package var snapshot: DocumentSnapshot | ||
|
|
||
| /// The actual code action request, which can specify additional parameters | ||
| /// to guide the code actions. | ||
| package var request: CodeActionRequest | ||
|
|
||
| /// The source file in which the syntactic code action will operate. | ||
| package var file: SourceFileSyntax | ||
|
|
||
| /// The originally requested range in the original code action request. | ||
| /// | ||
| /// Generally, `range` should be preferred because it performs useful adjustments to extend the range to the start and end of tokens. | ||
| var requestedRange: Range<Position> | ||
|
|
||
| /// The UTF-8 byte range in the source file in which code actions should be | ||
| /// considered, i.e., where the cursor or selection is. | ||
| package var range: Range<AbsolutePosition> | ||
|
|
@@ -45,16 +105,18 @@ package struct SyntaxCodeActionScope { | |
| package var innermostNodeContainingRange: Syntax? | ||
|
|
||
| package init?( | ||
| resolveSupport: TextDocumentClientCapabilities.CodeAction.ResolveSupportProperties?, | ||
| snapshot: DocumentSnapshot, | ||
| syntaxTree file: SourceFileSyntax, | ||
| request: CodeActionRequest | ||
| requestedRange: Range<Position>, | ||
| ) { | ||
| self.resolveSupport = resolveSupport | ||
| self.snapshot = snapshot | ||
| self.request = request | ||
| self.requestedRange = requestedRange | ||
| self.file = file | ||
|
|
||
| guard let left = tokenForRefactoring(at: request.range.lowerBound, snapshot: snapshot, syntaxTree: file), | ||
| let right = tokenForRefactoring(at: request.range.upperBound, snapshot: snapshot, syntaxTree: file) | ||
| guard let left = tokenForRefactoring(at: requestedRange.lowerBound, snapshot: snapshot, syntaxTree: file), | ||
| let right = tokenForRefactoring(at: requestedRange.upperBound, snapshot: snapshot, syntaxTree: file) | ||
| else { | ||
| return nil | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.