LSPServiceKit

0.1.1

Talk to LSPService in Swift
codeface-io/LSPServiceKit

What's New

Stabilize Dependency Versions

2022-10-10T20:09:31Z

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

LSPServiceKit

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

What?

LSPServiceKit helps Swift apps use LSPService:

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

// Get the process ID of LSPService
let processID = try await LSPService.api.processID.get()

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

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

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 18:13:21 GMT-0900 (Hawaii-Aleutian Daylight Time)