-
Notifications
You must be signed in to change notification settings - Fork 285
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
Add Local Refactoring support #70
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Request from the server to the client to modify resources on the client side. | ||
/// | ||
/// - Parameters: | ||
/// - label: An optional label of the workspace edit. | ||
/// - edit: The edits to apply. | ||
public struct ApplyEditRequest: RequestType { | ||
public static let method: String = "workspace/applyEdit" | ||
public typealias Response = ApplyEditResponse? | ||
|
||
/// An optional label of the workspace edit. | ||
/// Used by the client's user interface for things such as | ||
/// the stack to undo the workspace edit. | ||
public var label: String? | ||
|
||
/// The edits to apply. | ||
public var edit: WorkspaceEdit | ||
|
||
public init(label: String?, edit: WorkspaceEdit) { | ||
self.label = label | ||
self.edit = edit | ||
} | ||
} | ||
|
||
public struct ApplyEditResponse: Codable, Hashable, ResponseType { | ||
/// Indicates whether the edit was applied or not. | ||
public var applied: Bool | ||
|
||
/// An optional textual description for why the edit was not applied. | ||
public var failureReason: String? | ||
|
||
public init(applied: Bool, failureReason: String?) { | ||
self.applied = applied | ||
self.failureReason = failureReason | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
|
||
/// Request sent from the client to to trigger command execution on the server. | ||
/// | ||
/// The execution of this request can be the result of a request that returns a command, | ||
/// such as CodeActionsRequest and CodeLensRequest. In most cases, the server creates a WorkspaceEdit | ||
/// structure and applies the changes to the workspace using the ApplyEditRequest. | ||
/// | ||
/// Servers that provide command execution should set the `executeCommand` server capability. | ||
/// | ||
/// - Parameters: | ||
/// - command: The command to be executed. | ||
/// - arguments: The arguments to use when executing the command. | ||
public struct ExecuteCommandRequest: RequestType { | ||
public static let method: String = "workspace/executeCommand" | ||
|
||
// Note: The LSP type for this response is `Any?`. | ||
public typealias Response = CommandArgumentType? | ||
|
||
/// The command to be executed. | ||
public var command: String | ||
|
||
/// Arguments that the command should be invoked with. | ||
public var arguments: [CommandArgumentType]? | ||
|
||
/// The document in which the command was invoked. | ||
public var textDocument: TextDocumentIdentifier? { | ||
return metadata?.textDocument | ||
} | ||
|
||
/// Optional metadata containing SourceKit-LSP infomration about this command. | ||
public var metadata: SourceKitLSPCommandMetadata? { | ||
guard case .dictionary(let dictionary)? = arguments?.last else { | ||
return nil | ||
} | ||
guard let data = try? JSONEncoder().encode(dictionary) else { | ||
return nil | ||
} | ||
return try? JSONDecoder().decode(SourceKitLSPCommandMetadata.self, from: data) | ||
} | ||
|
||
public init(command: String, arguments: [CommandArgumentType]?) { | ||
self.command = command | ||
self.arguments = arguments | ||
} | ||
} | ||
|
||
/// Represents metadata that SourceKit-LSP injects at every command returned by code actions. | ||
/// The ExecuteCommand is not a TextDocumentRequest, so metadata is injected to allow SourceKit-LSP | ||
/// to determine where a command should be executed. | ||
public struct SourceKitLSPCommandMetadata: Codable, Hashable { | ||
public var textDocument: TextDocumentIdentifier | ||
|
||
public init(textDocument: TextDocumentIdentifier) { | ||
self.textDocument = textDocument | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// A workspace edit represents changes to many resources managed in the workspace. | ||
public struct WorkspaceEdit: Codable, Hashable, ResponseType { | ||
|
||
/// The edits to be applied to existing resources. | ||
public var changes: [String: [TextEdit]]? | ||
|
||
public init(changes: [URL: [TextEdit]]?) { | ||
guard let changes = changes else { | ||
return | ||
} | ||
let changesArray = changes.map { ($0.key.absoluteString, $0.value) } | ||
self.changes = Dictionary(uniqueKeysWithValues: changesArray) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a duplicate "to" here