LSPServiceKit

     

👩🏻‍🚀 这个项目仍然处于实验阶段。 欢迎贡献者和先驱者!

什么?

LSPServiceKit 帮助 Swift 应用程序使用 LSPService

Context Context

如何?

获取 LSP 服务器

LSPService 精确地反映了 LSPService API,因此这里的第一个调用将转换为 http://127.0.0.1:8080/lspservice/api/language/Swift/websocket 上的 websocket 连接请求

// Connect to Swift LSP websocket
let webSocketConnection = try LSPService.api.language("Swift").websocket.connectToLSPWebSocket()

// Create "server" with websocket connection
let server = LSP.Server(connection: webSocketConnection, languageName: "Swift")

或更快

let server = try LSPService.connectToLSPServer(forLanguageNamed: "Swift")

现在,您可能想要设置服务器的三个处理程序

await server.handleNotificationFromServer { notification in
    // handle notification
}
            
await server.handleErrorOutputFromServer { errorOutput in
    // handle errorOutput
}

await server.handleConnectionShutdown { error in
    // handle error
}

初始化 LSP 服务器

// Initialize server with codebase folder
_ = try await server.request(.initialize(folder: codebaseFolderURL))

// Notify server that we are initialized
try await server.notify(.initialized)

使用 LSP.ServerManager

以上所有操作都可以更快地实现

// Locate the codebase
let codebase = LSP.CodebaseLocation(folder: codebaseFolderURL,
                                    languageName: "Swift",
                                    codeFileEndings: ["swift"])

// Create and initialize the LSP server
let server = try await LSP.ServerManager.shared.initializeServer(for: codebase)

架构

这是代码文件夹的内部架构(组成和基本依赖项)

上面的图片是使用 Codeface 应用程序生成的。

开发状态

从 0.1.0 版本/标签开始,LSPServiceKit 遵循 语义化版本控制。 因此,在达到 1.0.0 之前,其 API 仍可能经常中断,但这将在版本更新中得到体现。

LSPServiceKit 已经在生产中使用,但 Codeface 仍然是它的主要客户端。 LSPServiceKit 将尽快迁移到 1.0.0 版本,一旦它的基本实用性和概念上的合理性通过服务多个真实世界的客户端得到验证。