Skip to content

codeface-io/LSPServiceKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.