Github CI

SwiftLSPClient

⚠️注意!

SwiftLSPClient 已被替换。 它被拆分为两个独立的部分。 协议级别的支持位于 LanguageServerProtocol 中。 更高级别的客户端抽象位于 LanguageClient 中,这可能是您所需要的。

这是一个(现在已弃用的)Swift 库,用于与 Language Server Protocol 实现进行交互。

LSP 服务器提供关于源代码的丰富信息。 LSP 客户端使用这些信息。 该库主要关注客户端。 它是低级别的,并且仅提供围绕客户端和服务器之间传递的类型和消息的核心抽象。

示例

import SwiftLSPClient

let executablePath = "path/to/your/lsp-server-executable"
let host = LanguageServerProcessHost(path: executablePath, arguments: [],
    environment: [/* the environment your lsp server requires e.g. PATH */])

host.start { (server) in
    guard let server = server else {
        Swift.print("unable to launch server")
        return
    }
    
    // Set-up notificationResponder to see log/error messages from LSP server
    server.notificationResponder = <object conforming to NotificationResponder>

    let processId = Int(ProcessInfo.processInfo.processIdentifier)
    let capabilities = ClientCapabilities(workspace: nil, textDocument: nil, experimental: nil)

    let params = InitializeParams(processId: processId,
                                  rootPath: nil,
                                  rootURI: nil,
                                  initializationOptions: nil,
                                  capabilities: capabilities,
                                  trace: Tracing.off,
                                  workspaceFolders: nil)

    server.initialize(params: params, block: { (result) in
        switch result {
        case .failure(let error):
            Swift.print("unable to initialize \(error)")
        case .success(let value):
            Swift.print("initialized \(value)")
        }
    })
}

支持的功能

LSP 规范 非常庞大,并且此库目前并未实现所有功能。 目的是支持 3.x 规范,但尽可能向后兼容 pre-3.0 服务器。

功能 支持
window/showMessage
window/showMessageRequest
window/showDocument -
window/logMessage
window/workDoneProgress/create -
window/workDoneProgress/cancel -
$/cancelRequest -
$/progress -
initialize
shutdown -
exit -
telemetry/event -
$/logTrace -
$/setTrace -
client/registerCapability
client/unregisterCapability
workspace/workspaceFolders -
workspace/didChangeWorkspaceFolders -
workspace/didChangeConfiguration -
workspace/configuration
workspace/didChangeWatchedFiles -
workspace/symbol -
workspace/executeCommand -
workspace/applyEdit -
workspace/willCreateFiles -
workspace/didCreateFiles -
workspace/willRenameFiles -
workspace/didRenameFiles -
workspace/willDeleteFiles -
workspace/didDeleteFiles -
textDocument/didOpen
textDocument/didChange
textDocument/willSave
textDocument/willSaveWaitUntil
textDocument/didSave
textDocument/didClose
textDocument/publishDiagnostics
textDocument/completion
completionItem/resolve -
textDocument/hover
textDocument/signatureHelp
textDocument/declaration
textDocument/definition
textDocument/typeDefinition
textDocument/implementation
textDocument/references
textDocument/documentHighlight -
textDocument/documentSymbol
textDocument/codeAction
codeLens/resolve -
textDocument/codeLens -
workspace/codeLens/refresh -
textDocument/documentLink -
documentLink/resolve -
textDocument/documentColor -
textDocument/colorPresentation -
textDocument/formatting
textDocument/rangeFormatting
textDocument/onTypeFormatting
textDocument/rename
textDocument/prepareRename
textDocument/foldingRange
textDocument/selectionRange -
textDocument/prepareCallHierarchy -
textDocument/prepareCallHierarchy -
callHierarchy/incomingCalls -
callHierarchy/outgoingCalls -
textDocument/semanticTokens/full
textDocument/semanticTokens/full/delta
textDocument/semanticTokens/range
workspace/semanticTokens/refresh
textDocument/linkedEditingRange -
textDocument/moniker -

集成

Swift 包管理器

dependencies: [
    .package(url: "https://github.com/ChimeHQ/SwiftLSPClient")
]

建议或反馈

我们很乐意听取您的意见! 通过 issue 或 pull request 联系我们。

请注意,此项目是根据 贡献者行为准则 发布的。 通过参与此项目,您同意遵守其条款。