Skip to content

Commit

Permalink
codeAction/resolve support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jul 18, 2023
1 parent 6f05c1b commit 159c183
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe
| callHierarchy/outgoingCalls ||
| client/registerCapability ||
| client/unregisterCapability ||
| codeAction/resolve | - |
| codeAction/resolve | |
| codeLens/resolve ||
| completionItem/resolve ||
| documentLink/resolve ||
Expand Down
2 changes: 2 additions & 0 deletions Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public actor JSONRPCServer: Server {
return try await session.response(to: method, params: params)
case .codeAction(let params):
return try await session.response(to: method, params: params)
case .codeActionResolve(let params):
return try await session.response(to: method, params: params)
case .codeLens(let params):
return try await session.response(to: method, params: params)
case .codeLensResolve(let params):
Expand Down
12 changes: 8 additions & 4 deletions Sources/LanguageServerProtocol/Additions/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ public extension Server {
try await sendRequest(.documentSymbol(params))
}

func codeAction(params: CodeActionParams) async throws -> CodeActionResponse {
try await sendRequest(.codeAction(params))
}

func prepareCallHierarchy(params: CallHierarchyPrepareParams) async throws -> CallHierarchyPrepareResponse {
try await sendRequest(.prepareCallHierarchy(params))
}
Expand Down Expand Up @@ -223,6 +219,14 @@ public extension Server {
try await sendRequest(.documentHighlight(params))
}

func codeAction(params: CodeActionParams) async throws -> CodeActionResponse {
try await sendRequest(.codeAction(params))
}

func codeActionResolve(params: CodeAction) async throws -> CodeAction {
try await sendRequest(.codeActionResolve(params))
}

func codeLens(params: CodeLensParams) async throws -> CodeLensResponse {
try await sendRequest(.codeLens(params))
}
Expand Down
22 changes: 21 additions & 1 deletion Sources/LanguageServerProtocol/LanguageFeatures/CodeAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension CodeActionKind {
public static let RefactorRewrite: CodeActionKind = "refactor.rewrite"
public static let Source: CodeActionKind = "source"
public static let SourceOrganizeImports: CodeActionKind = "source.organizeImports"
public static let SourceFixAll: CodeActionKind = "source.fixAll"
}

public struct CodeActionClientCapabilities: Codable, Hashable, Sendable {
Expand Down Expand Up @@ -55,13 +56,32 @@ public struct CodeActionClientCapabilities: Codable, Hashable, Sendable {
}
}

public struct CodeActionOptions: Codable, Hashable, Sendable {
public var workDoneProgress: Bool?
public var codeActionKinds: [CodeActionKind]?
public var resolveProvider: Bool?

public init(workDoneProgress: Bool?, codeActionKinds: [CodeActionKind]?, resolveProvider: Bool) {
self.workDoneProgress = workDoneProgress
self.codeActionKinds = codeActionKinds
self.resolveProvider = resolveProvider
}
}

public enum CodeActionTriggerKind: Int, Codable, Hashable, Sendable {
case invoked = 1
case automatic = 2
}

public struct CodeActionContext: Codable, Hashable, Sendable {
public let diagnostics: [Diagnostic]
public let only: [CodeActionKind]?
public let triggerKind: CodeActionTriggerKind?

public init(diagnostics: [Diagnostic] = [], only: [CodeActionKind]? = nil) {
public init(diagnostics: [Diagnostic], only: [CodeActionKind]?, triggerKind: CodeActionTriggerKind? = nil) {
self.diagnostics = diagnostics
self.only = only
self.triggerKind = triggerKind
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public enum ClientRequest: Sendable, Hashable {
case textDocumentDocumentHighlight = "textDocument/documentHighlight"
case textDocumentDocumentSymbol = "textDocument/documentSymbol"
case textDocumentCodeAction = "textDocument/codeAction"
case codeActionResolve = "codeAction/resolve"
case codeLensResolve = "codeLens/resolve"
case textDocumentCodeLens = "textDocument/codeLens"
case textDocumentDocumentLink = "textDocument/documentLink"
Expand Down Expand Up @@ -149,6 +150,7 @@ public enum ClientRequest: Sendable, Hashable {
case documentHighlight(DocumentHighlightParams)
case documentSymbol(DocumentSymbolParams)
case codeAction(CodeActionParams)
case codeActionResolve(CodeAction)
case codeLens(CodeLensParams)
case codeLensResolve(CodeLens)
case selectionRange(SelectionRangeParams)
Expand Down Expand Up @@ -213,6 +215,8 @@ public enum ClientRequest: Sendable, Hashable {
return .textDocumentDocumentSymbol
case .codeAction:
return .textDocumentCodeAction
case .codeActionResolve:
return .codeActionResolve
case .codeLens:
return .textDocumentCodeLens
case .codeLensResolve:
Expand Down
6 changes: 0 additions & 6 deletions Sources/LanguageServerProtocol/ServerCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ public struct DocumentSymbolOptions: Codable, Hashable, Sendable {
public var label: String?
}

public struct CodeActionOptions: Codable, Hashable, Sendable {
public var workDoneProgress: Bool?
public var codeActionKinds: [CodeActionKind]?
public var resolveProvider: Bool?
}

public typealias DocumentColorOptions = WorkDoneProgressOptions

public typealias DocumentColorRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions
Expand Down

0 comments on commit 159c183

Please sign in to comment.