Swiftpack.co - codeface-io/LSPServiceKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by codeface-io.
codeface-io/LSPServiceKit 0.2.0
Talk to LSPService in Swift
⭐️ 5
🕓 1 week ago
iOS macOS tvOS linux macOS iOS
.package(url: "https://github.com/codeface-io/LSPServiceKit.git", from: "0.2.0")

LSPServiceKit

     

👩🏻‍🚀 This project is still a tad experimental. Contributors and pioneers welcome!

What?

LSPServiceKit helps Swift apps use LSPService:

Context Context

How?

Get an LSP Server

LSPService precisely reflects the LSPService API, so the first call here translates to a websocket connection request on http://127.0.0.1:8080/lspservice/api/language/Swift/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")

Or quicker:

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

Now, you'd probably wanna set the server's three handlers:

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

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

Initialize an LSP Server

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

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

Use LSP.ServerManager

All the above can be achieved quicker:

// 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)

Architecture

Here is the internal architecture (composition and essential dependencies) of the code folder:

The above image was generated with the Codeface app.

Development Status

From version/tag 0.1.0 on, LSPServiceKit adheres to semantic versioning. So until it has reached 1.0.0, its API may still break frequently, but this will be expressed in version bumps.

LSPServiceKit is already being used in production, but Codeface is still its primary client. LSPServiceKit will move to version 1.0.0 as soon as its basic practicality and conceptual soundness have been validated by serving multiple real-world clients.

GitHub

link
Stars: 5
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Stabilize Dependency Versions
7 weeks ago

Since LSPServiceKit is intended as true open-source software, its dependency versions must be stable so it can itself be a stable dependency.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics