这是一个 Swift 库,用于与 Language Server Protocol 进行交互。 它包含类型定义和实用程序,可用于服务器端和客户端项目。
需要与服务器交互吗? 您可能需要查看 LanguageClient。 想要构建服务器吗? 看看 LanguageServer。
在可能的情况下,该库与 LSP 规范相匹配。 但是,此库中存在一些规范中没有的附加类型。 这是由于使用了匿名结构造成的。
该库使用嵌套结构和/或 TwoTypeOption
和 ThreeTypeOption
类型来建模这些情况。
dependencies: [
.package(url: "https://github.com/ChimeHQ/LanguageServerProtocol", from: "0.11.0")
]
在很大程度上,这个库致力于成为 Swift 中规范的直接版本。 但是,在某些地方,引入一些额外的功能是有意义的。
Snippet
:使解释完成结果的内容更容易TokenRepresentation
:维护文档的语义令牌状态DataChannel.withMessageFraming
:使用基于 HTTP 标头的消息框架包装现有的 JSONRPC DataChannel如果您需要支持其他通信通道,则必须使用来自 JSONRPC 包的 DataChannel
类型。 在 LanguageClient 中已经定义了一些专门的通道。
目前,在这个库中仍然有一些对客户端支持有用的部分
MockServer
:一个占位符,可用于模拟真实服务器Server
:一个描述基本服务器功能的协议目的是将所有这些迁移到 LanguageClient 中,使该库纯粹专注于协议级别的支持。
您可以使用 eventSequence
响应服务器事件。 在这里要小心,因为某些服务器需要对某些请求做出响应。 还有可能并非所有请求类型都已映射到 ServerRequest
类型中。 规范很大! 如果您发现问题,请提出 issue!
Task {
for await event in server.eventSequence {
print("receieved event:", event)
switch event {
case let .request(id: id, request: request):
request.relyWithError(MyError.unsupported)
default:
print("dropping notification/error")
}
}
}
LSP 规范很大,目前该库并未完全实现它。 目的是支持 3.x 规范,但尽可能向后兼容 3.0 之前的服务器。
消息 | 已支持 |
---|---|
$/cancelRequest | ✅ |
$/logTrace | ✅ |
$/progress | ✅ |
$/setTrace | ✅ |
callHierarchy/incomingCalls | ✅ |
callHierarchy/outgoingCalls | ✅ |
client/registerCapability | ✅ |
client/unregisterCapability | ✅ |
codeAction/resolve | ✅ |
codeLens/resolve | ✅ |
completionItem/resolve | ✅ |
documentLink/resolve | ✅ |
exit | ✅ |
initialize | ✅ |
initialized | ✅ |
inlayHint/resolve | ✅ |
notebookDocument/didChange | - |
notebookDocument/didClose | - |
notebookDocument/didOpen | - |
notebookDocument/didSave | - |
server-defined | ✅ |
shutdown | ✅ |
telemetry/event | ✅ |
textDocument/codeAction | ✅ |
textDocument/codeLens | ✅ |
textDocument/colorPresentation | ✅ |
textDocument/completion | ✅ |
textDocument/declaration | ✅ |
textDocument/definition | ✅ |
textDocument/diagnostic | ✅ |
textDocument/didChange | ✅ |
textDocument/didClose | ✅ |
textDocument/didOpen | ✅ |
textDocument/didSave | ✅ |
textDocument/documentColor | ✅ |
textDocument/documentHighlight | ✅ |
textDocument/documentLink | ✅ |
textDocument/documentSymbol | ✅ |
textDocument/foldingRange | ✅ |
textDocument/formatting | ✅ |
textDocument/hover | ✅ |
textDocument/implementation | ✅ |
textDocument/inlayHint | ✅ |
textDocument/inlineValue | - |
textDocument/linkedEditingRange | ✅ |
textDocument/moniker | ✅ |
textDocument/onTypeFormatting | ✅ |
textDocument/prepareCallHierarchy | ✅ |
textDocument/prepareRename | ✅ |
textDocument/prepareTypeHierarchy | ✅ |
textDocument/publishDiagnostics | ✅ |
textDocument/rangeFormatting | ✅ |
textDocument/references | ✅ |
textDocument/rename | ✅ |
textDocument/selectionRange | ✅ |
textDocument/semanticTokens/full | ✅ |
textDocument/semanticTokens/full/delta | ✅ |
textDocument/semanticTokens/range | ✅ |
textDocument/signatureHelp | ✅ |
textDocument/typeDefinition | ✅ |
textDocument/willSave | ✅ |
textDocument/willSaveWaitUntil | ✅ |
typeHierarchy/subtypes | ✅ |
typeHierarchy/supertypes | ✅ |
window/logMessage | ✅ |
window/showDocument | ✅ |
window/showMessage | ✅ |
window/showMessageRequest | ✅ |
window/workDoneProgress/cancel | ✅ |
window/workDoneProgress/create | ✅ |
workspace/applyEdit | ✅ |
workspace/codeLens/refresh | ✅ |
workspace/configuration | ✅ |
workspace/diagnostic | - |
workspace/diagnostic/refresh | - |
workspace/didChangeConfiguration | ✅ |
workspace/didChangeWatchedFiles | ✅ |
workspace/didChangeWorkspaceFolders | ✅ |
workspace/didCreateFiles | ✅ |
workspace/didDeleteFiles | ✅ |
workspace/didRenameFiles | ✅ |
workspace/executeCommand | ✅ |
workspace/inlayHint/refresh | ✅ |
workspace/inlineValue/refresh | - |
workspace/semanticTokens/refresh | ✅ |
workspace/symbol | ✅ |
workspace/willCreateFiles | ✅ |
workspace/willDeleteFiles | ✅ |
workspace/willRenameFiles | ✅ |
workspace/workspaceFolders | ✅ |
workspaceSymbol/resolve | ✅ |
我很乐意收到您的来信! Issues 或 pull requests 都可以。 还可以使用 Discord 服务器获得实时帮助,但我强烈倾向于以文档的形式回答。
我更喜欢协作,如果您有类似的项目,我很乐意找到合作的方式。
我更喜欢使用制表符进行缩进,以提高可访问性。 但是,我宁愿您使用您想要的系统并提出 PR,也不愿您因为空格而犹豫。
参与此项目即表示您同意遵守 贡献者行为准则。