From 3c47cbc9161a0fc58242181e3f5ab539b729858c Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Thu, 19 May 2022 15:44:56 -0400 Subject: [PATCH] workspace/symbol fixes --- README.md | 2 +- .../ClientCapabilities.swift | 27 +-------- .../JSONRPCLanguageServer.swift | 4 ++ .../LanguageServerProtocol.swift | 8 +++ Sources/LanguageServerProtocol/Server.swift | 8 +++ .../LanguageServerProtocol/Workspace.swift | 59 +++---------------- .../Workspace/Symbol.swift | 55 +++++++++++++++++ 7 files changed, 85 insertions(+), 78 deletions(-) create mode 100644 Sources/LanguageServerProtocol/Workspace/Symbol.swift diff --git a/README.md b/README.md index 3d7104b..92222b3 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe | Workspace Features | Supported | | -------------------|:---------:| | workspace/symbol | ✅ | -| workspaceSymbol/resolve | - | +| workspaceSymbol/resolve | ✅ | | workspace/configuration | ✅ | | workspace/didChangeConfiguration | ✅ | | workspace/workspaceFolders | ✅ | diff --git a/Sources/LanguageServerProtocol/ClientCapabilities.swift b/Sources/LanguageServerProtocol/ClientCapabilities.swift index 1f1f34f..1c78243 100644 --- a/Sources/LanguageServerProtocol/ClientCapabilities.swift +++ b/Sources/LanguageServerProtocol/ClientCapabilities.swift @@ -48,29 +48,6 @@ public typealias DidChangeConfigurationClientCapabilities = GenericDynamicRegist public typealias DidChangeWatchedFilesClientCapabilities = GenericDynamicRegistration -public struct WorkspaceClientCapabilitySymbolValueSet: Codable, Hashable { - let valueSet: [SymbolKind]? - - public init(valueSet: [SymbolKind]?) { - self.valueSet = valueSet - } -} - -public struct WorkspaceClientCapabilitySymbol: Codable, Hashable { - public let dynamicRegistration: Bool? - public let symbolKind: WorkspaceClientCapabilitySymbolValueSet? - - public init(dynamicRegistration: Bool?, symbolKind: WorkspaceClientCapabilitySymbolValueSet?) { - self.dynamicRegistration = dynamicRegistration - self.symbolKind = symbolKind - } - - public init(dynamicRegistration: Bool?, symbolKind: [SymbolKind]?) { - self.dynamicRegistration = dynamicRegistration - self.symbolKind = WorkspaceClientCapabilitySymbolValueSet(valueSet: symbolKind) - } -} - public struct ShowDocumentClientCapabilities: Hashable, Codable { public var support: Bool } @@ -260,7 +237,7 @@ public struct ClientCapabilities: Codable, Hashable { public let workspaceEdit: WorkspaceClientCapabilityEdit? public let didChangeConfiguration: DidChangeConfigurationClientCapabilities? public let didChangeWatchedFiles: GenericDynamicRegistration? - public let symbol: WorkspaceClientCapabilitySymbol? + public let symbol: WorkspaceSymbolClientCapabilities? public let executeCommand: GenericDynamicRegistration? public let workspaceFolders: Bool? public let configuration: Bool? @@ -272,7 +249,7 @@ public struct ClientCapabilities: Codable, Hashable { workspaceEdit: WorkspaceClientCapabilityEdit?, didChangeConfiguration: DidChangeConfigurationClientCapabilities?, didChangeWatchedFiles: GenericDynamicRegistration?, - symbol: WorkspaceClientCapabilitySymbol?, + symbol: WorkspaceSymbolClientCapabilities?, executeCommand: GenericDynamicRegistration?, workspaceFolders: Bool?, configuration: Bool?, diff --git a/Sources/LanguageServerProtocol/JSONRPCLanguageServer.swift b/Sources/LanguageServerProtocol/JSONRPCLanguageServer.swift index b9a0079..2e92291 100644 --- a/Sources/LanguageServerProtocol/JSONRPCLanguageServer.swift +++ b/Sources/LanguageServerProtocol/JSONRPCLanguageServer.swift @@ -397,6 +397,10 @@ extension JSONRPCLanguageServer { sendRequestWithHandler(params, method: method, handler: completionHandler) case .custom(let method, let params): sendRequestWithHandler(params, method: method, handler: completionHandler) + case .workspaceSymbol(let params): + sendRequestWithHandler(params, method: method, handler: completionHandler) + case .workspaceSymbolResolve(let params): + sendRequestWithHandler(params, method: method, handler: completionHandler) } } } diff --git a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift index d0e309a..3e93f4b 100644 --- a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift +++ b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift @@ -86,6 +86,8 @@ public enum ClientRequest { case workspaceWillCreateFiles = "workspace/willCreateFiles" case workspaceWillRenameFiles = "workspace/willRenameFiles" case workspaceWillDeleteFiles = "workspace/willDeleteFiles" + case workspaceSymbol = "workspace/symbol" + case workspaceSymbolResolve = "workspaceSymbol/resolve" case textDocumentWillSaveWaitUntil = "textDocument/willSaveWaitUntil" case textDocumentCompletion = "textDocument/completion" case completionItemResolve = "completionItem/resolve" @@ -127,6 +129,8 @@ public enum ClientRequest { case workspaceWillCreateFiles(CreateFilesParams) case workspaceWillRenameFiles(RenameFilesParams) case workspaceWillDeleteFiles(DeleteFilesParams) + case workspaceSymbol(WorkspaceSymbolParams) + case workspaceSymbolResolve(WorkspaceSymbol) case willSaveWaitUntilTextDocument(WillSaveTextDocumentParams) case completion(CompletionParams) case completionItemResolve(CompletionItem) @@ -172,6 +176,10 @@ public enum ClientRequest { return .workspaceWillRenameFiles case .workspaceWillDeleteFiles: return .workspaceWillDeleteFiles + case .workspaceSymbol: + return .workspaceSymbol + case .workspaceSymbolResolve: + return .workspaceSymbolResolve case .willSaveWaitUntilTextDocument: return .textDocumentWillSaveWaitUntil case .completion: diff --git a/Sources/LanguageServerProtocol/Server.swift b/Sources/LanguageServerProtocol/Server.swift index d5dedd4..c538257 100644 --- a/Sources/LanguageServerProtocol/Server.swift +++ b/Sources/LanguageServerProtocol/Server.swift @@ -226,6 +226,14 @@ public extension Server { func executeCommand(params: ExecuteCommandParams, block: @escaping (ServerResult) -> Void) { sendRequest(.workspaceExecuteCommand(params), completionHandler: block) } + + func workspaceSymbol(params: WorkspaceSymbolParams, block: @escaping (ServerResult) -> Void) { + sendRequest(.workspaceSymbol(params), completionHandler: block) + } + + func workspaceSymbolResolve(params: WorkspaceSymbol, block: @escaping (ServerResult) -> Void) { + sendRequest(.workspaceSymbolResolve(params), completionHandler: block) + } } // Language Features diff --git a/Sources/LanguageServerProtocol/Workspace.swift b/Sources/LanguageServerProtocol/Workspace.swift index f0656ed..cd98fca 100644 --- a/Sources/LanguageServerProtocol/Workspace.swift +++ b/Sources/LanguageServerProtocol/Workspace.swift @@ -88,62 +88,17 @@ public struct DidChangeConfigurationParams: Codable, Hashable { } } -public enum SymbolTag: Int, Codable, Hashable { +public enum SymbolTag: Int, Codable, Hashable, CaseIterable { case Deprecated = 1 } -public struct WorkspaceSymbolClientCapabilities: Codable, Hashable { - public struct Properties: Codable, Hashable { - public var properties: [String] - } - - public var dynamicRegistration: Bool? - public var symbolKind: ValueSet? - public var tagSupport: ValueSet? - public var resolveSupport: Properties? - - public init(dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, resolveSupport: [String]?) { - self.dynamicRegistration = dynamicRegistration - self.symbolKind = symbolKind.map { ValueSet(valueSet: $0) } - self.tagSupport = tagSupport.map { ValueSet(valueSet: $0) } - self.resolveSupport = resolveSupport.map { Properties(properties: $0) } - } -} - -public struct WorkspaceSymbolOptions: Codable, Hashable { - public var workDoneProgress: Bool? - public var resolveProvider: Bool? -} - -public typealias WorkspaceSymbolRegistrationOptions = WorkspaceSymbolOptions - -public struct WorkspaceSymbolParams: Codable, Hashable { - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? - public var query: String - - public init(query: String, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.query = query - } -} - -public struct WorkspaceSymbol: Codable, Hashable { - public var name: String - public var kind: SymbolKind - public var tags: [SymbolTag]? - public var location: TwoTypeOption? - public var containerName: String? -} - public struct SymbolInformation: Codable, Hashable { - public var name: String - public var kind: SymbolKind - public var tags: [SymbolTag]? - public var deprecated: Bool? - public var location: Location - public var containerName: String? + public let name: String + public let kind: SymbolKind + public let tags: [SymbolTag]? + public let deprecated: Bool? + public let location: Location + public let containerName: String? } public struct CreateFileOptions: Codable, Hashable { diff --git a/Sources/LanguageServerProtocol/Workspace/Symbol.swift b/Sources/LanguageServerProtocol/Workspace/Symbol.swift new file mode 100644 index 0000000..4c5dd12 --- /dev/null +++ b/Sources/LanguageServerProtocol/Workspace/Symbol.swift @@ -0,0 +1,55 @@ +import Foundation + +public struct WorkspaceSymbolClientCapabilities: Codable, Hashable { + public struct Properties: Codable, Hashable { + public var properties: [String] + } + + public var dynamicRegistration: Bool? + public var symbolKind: ValueSet? + public var tagSupport: ValueSet? + public var resolveSupport: Properties? + + public init(dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, resolveSupport: Properties?) { + self.dynamicRegistration = dynamicRegistration + self.symbolKind = symbolKind.map { ValueSet(valueSet: $0) } + self.tagSupport = tagSupport.map { ValueSet(valueSet: $0) } + self.resolveSupport = resolveSupport + } + + public init(dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, resolveSupport: [String]?) { + self.init(dynamicRegistration: dynamicRegistration, + symbolKind: symbolKind, + tagSupport: tagSupport, + resolveSupport: resolveSupport.map { Properties(properties: $0) }) + } +} + +public struct WorkspaceSymbolOptions: Codable, Hashable { + public var workDoneProgress: Bool? + public var resolveProvider: Bool? +} + +public typealias WorkspaceSymbolRegistrationOptions = WorkspaceSymbolOptions + +public struct WorkspaceSymbolParams: Codable, Hashable { + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? + public var query: String + + public init(query: String, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + self.query = query + } +} + +public struct WorkspaceSymbol: Codable, Hashable { + public var name: String + public var kind: SymbolKind + public var tags: [SymbolTag]? + public var location: TwoTypeOption? + public var containerName: String? +} + +public typealias WorkspaceSymbolResponse = TwoTypeOption<[SymbolInformation],[WorkspaceSymbol]>?