-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
303 additions
and
43 deletions.
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,110 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2018 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 `CommandData` represents the underlying data of a custom `Command`. | ||
public protocol CommandData: Codable { | ||
static var identifier: String { get } | ||
} | ||
|
||
/// Represents a reference to a command identified by a string. Used as the result of | ||
/// requests that returns actions to the user, later used as the parameter of | ||
/// workspace/executeCommand if the user wishes to execute said command. | ||
public struct Command<Data: CommandData> { | ||
|
||
/// Title of the command, like `save`. | ||
public var title: String | ||
|
||
/// The internal identifier for this command. | ||
public var command: String { | ||
return type(of: data).identifier | ||
} | ||
|
||
/// The data related to this command. | ||
public var data: Data | ||
|
||
public init(title: String = "", data: Data) { | ||
self.title = title | ||
self.data = data | ||
} | ||
} | ||
|
||
/// Type-erased container of a generic `Command`, used for (de)serialization of commands. | ||
public struct AnyCommand { | ||
private let command: Any | ||
|
||
public init<T>(_ command: Command<T>) { | ||
self.command = command | ||
} | ||
|
||
public func getAs<T: CommandData>(commandData: Command<T>.Type) -> Command<T>? { | ||
return command as? Command<T> | ||
} | ||
} | ||
|
||
extension AnyCommand: Codable { | ||
public enum CodingKeys: String, CodingKey { | ||
case title | ||
case command | ||
case arguments | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let command: String = try container.decode(String.self, forKey: .command) | ||
switch command { | ||
case SemanticRefactorCommandData.identifier: | ||
let data = try container.decode([SemanticRefactorCommandData].self, forKey: .arguments) | ||
let command = Command(data: data[0]) | ||
self.init(command) | ||
default: | ||
fatalError() | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
if let command = command as? Command<SemanticRefactorCommandData> { | ||
try container.encode(command.title, forKey: .title) | ||
try container.encode(command.command, forKey: .command) | ||
try container.encode([command.data], forKey: .arguments) | ||
} else { | ||
fatalError() | ||
} | ||
} | ||
} | ||
|
||
public struct SemanticRefactorCommandData: CommandData { | ||
public static let identifier = "sourcekit.lsp.semantic.refactoring.command" | ||
|
||
/// The document URL to refactor. | ||
public var urlString: String | ||
|
||
/// The identifier of the refactoring action. | ||
public var actionString: String | ||
|
||
/// The starting line of the range to refactor. | ||
public var line: Int | ||
|
||
/// The starting column of the range to refactor. | ||
public var column: Int | ||
|
||
/// The length of the range to refactor. | ||
public var length: Int | ||
|
||
public init(url: URL, actionString: String, line: Int, column: Int, length: Int) { | ||
self.urlString = url.path | ||
self.actionString = actionString | ||
self.line = line | ||
self.column = column | ||
self.length = length | ||
} | ||
} |
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,43 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2018 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 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: TextDocumentRequest { | ||
public static let method: String = "workspace/executeCommand" | ||
// FIXME: A response isn't expected for this request. There's probably a better way | ||
// to handle this. | ||
public typealias Response = ExecuteCommandResponse? | ||
|
||
/// The command to be executed. | ||
public var command: AnyCommand | ||
|
||
public var textDocument: TextDocumentIdentifier { | ||
return TextDocumentIdentifier(URL(fileURLWithPath: "/Users/bruno.rocha/Desktop/never.swift")) | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
command = try container.decode(AnyCommand.self) | ||
} | ||
} | ||
|
||
public struct ExecuteCommandResponse: Codable, Hashable, ResponseType {} |
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,20 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2018 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. | ||
/// The edit should either provide changes or documentChanges. If the client can handle versioned document | ||
/// edits and if documentChanges are present, the latter are preferred over changes. | ||
public struct WorkspaceEdit: Codable, Hashable { | ||
|
||
/// The edits to be applied to existing resources. | ||
public var changes: [TextEdit]? | ||
} |
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,18 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2018 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 LanguageServerProtocol | ||
import Basic | ||
import sourcekitd | ||
|
||
struct SemanticRefactoring { | ||
} |
Oops, something went wrong.