Skip to content

Commit

Permalink
workspace/symbol fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed May 19, 2022
1 parent c294061 commit 3c47cbc
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 78 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
27 changes: 2 additions & 25 deletions Sources/LanguageServerProtocol/ClientCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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?
Expand All @@ -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?,
Expand Down
4 changes: 4 additions & 0 deletions Sources/LanguageServerProtocol/JSONRPCLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions Sources/LanguageServerProtocol/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ public extension Server {
func executeCommand(params: ExecuteCommandParams, block: @escaping (ServerResult<ExecuteCommandResponse>) -> Void) {
sendRequest(.workspaceExecuteCommand(params), completionHandler: block)
}

func workspaceSymbol(params: WorkspaceSymbolParams, block: @escaping (ServerResult<WorkspaceSymbolResponse>) -> Void) {
sendRequest(.workspaceSymbol(params), completionHandler: block)
}

func workspaceSymbolResolve(params: WorkspaceSymbol, block: @escaping (ServerResult<WorkspaceSymbolResponse>) -> Void) {
sendRequest(.workspaceSymbolResolve(params), completionHandler: block)
}
}

// Language Features
Expand Down
59 changes: 7 additions & 52 deletions Sources/LanguageServerProtocol/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymbolKind>?
public var tagSupport: ValueSet<SymbolTag>?
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<Location, TextDocumentIdentifier>?
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 {
Expand Down
55 changes: 55 additions & 0 deletions Sources/LanguageServerProtocol/Workspace/Symbol.swift
Original file line number Diff line number Diff line change
@@ -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<SymbolKind>?
public var tagSupport: ValueSet<SymbolTag>?
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<Location, TextDocumentIdentifier>?
public var containerName: String?
}

public typealias WorkspaceSymbolResponse = TwoTypeOption<[SymbolInformation],[WorkspaceSymbol]>?

0 comments on commit 3c47cbc

Please sign in to comment.