{"id":13871915,"url":"https://github.com/codeface-io/SwiftLSP","last_synced_at":"2025-07-16T01:32:12.935Z","repository":{"id":40505797,"uuid":"308195211","full_name":"codeface-io/SwiftLSP","owner":"codeface-io","description":"The Language Server Protocol in Swift","archived":false,"fork":false,"pushed_at":"2023-08-06T21:55:55.000Z","size":13038,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-16T22:48:02.378Z","etag":null,"topics":["language-server-protocol","lsp","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeface-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-29T02:24:38.000Z","updated_at":"2023-12-21T22:03:29.000Z","dependencies_parsed_at":"2023-02-14T07:46:25.428Z","dependency_job_id":null,"html_url":"https://github.com/codeface-io/SwiftLSP","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeface-io%2FSwiftLSP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeface-io%2FSwiftLSP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeface-io%2FSwiftLSP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeface-io%2FSwiftLSP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeface-io","download_url":"https://codeload.github.com/codeface-io/SwiftLSP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225990436,"owners_count":17556154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["language-server-protocol","lsp","swift"],"created_at":"2024-08-05T23:00:30.212Z","updated_at":"2024-11-23T19:31:24.851Z","avatar_url":"https://github.com/codeface-io.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# SwiftLSP\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcodeface-io%2FSwiftLSP%2Fbadge%3Ftype%3Dswift-versions\u0026style=flat-square)](https://swiftpackageindex.com/codeface-io/SwiftLSP) \u0026nbsp;[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcodeface-io%2FSwiftLSP%2Fbadge%3Ftype%3Dplatforms\u0026style=flat-square)](https://swiftpackageindex.com/codeface-io/SwiftLSP) \u0026nbsp;[![](https://img.shields.io/badge/Documentation-DocC-blue.svg?style=flat-square)](https://swiftpackageindex.com/codeface-io/SwiftLSP/documentation) \u0026nbsp;[![](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat-square)](LICENSE)\n\n👩🏻‍🚀 *This project [is still a tad experimental](#development-status). Contributors and pioneers welcome!*\n\n## What?\n\nSwiftLSP offers a quite dynamic Swift representation of the [LSP (Language Server Protocol)](https://microsoft.github.io/language-server-protocol) and helps with many related use cases. It is foundational for [LSPService](https://github.com/codeface-io/LSPService) and [LSPServiceKit](https://github.com/codeface-io/LSPServiceKit).\n\nSince the LSP standard defines a complex amorphous multitude of valid JSON objects, it doesn't exactly lend itself to being represented as a strict type system that would mirror the standard down to every permutation and property. So SwiftLSP is strictly typed at the higher level of LSP messages but falls back onto a more dynamic and flexible JSON representation for the details. The strict typing can easily be expanded on client demand.\n\n## How?\n\nSome of these examples build upon preceding ones, so it's best to read them from the beginning.\n\n### Create Messages\n\n```swift\nlet myRequest = LSP.Request(method: \"myMethod\", params: nil)\nlet myRequestMessage = LSP.Message.request(myRequest)\n\nlet myNotification = LSP.Notification(method: \"myMethod\", params: nil)\nlet myNotificationMessage = LSP.Message.notification(myNotification)\n```\n\n### Encode and Decode Messages\n\nSwiftLSP encodes LSP messages with the [LSP-conform JSON-RPC encoding](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#abstractMessage).\n\n```swift\nlet myRequestMessageEncoded = try myRequestMessage.encode()  // Data\nlet myRequestMessageDecoded = try LSP.Message(myRequestMessageEncoded)\n```\n\n### Wrap Messages in Packets\n\nTo send LSP messages via data channels, the standard defines how to [wrap each message](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#baseProtocol) in what we call an `LSP.Packet`, which holds the `Data`  of its `header`- and `content` part.\n\n```swift\nlet myRequestMessagePacket = try LSP.Packet(myRequestMessage)\nlet packetHeader = myRequestMessagePacket.header     // Data\nlet packetContent = myRequestMessagePacket.content   // Data\nlet packetTotalData = myRequestMessagePacket.data    // Data\n```\n\n### Extract Messages From Packets\n\n```swift\nlet myRequestMessageUnpacked = try myRequestMessagePacket.message()  // LSP.Message\n```\n\n### Extract Packets From Data\n\nA client talking to an LSP server might need to extract `LSP.Packet`s from the server's output `Data` stream.\n\nSwiftLSP can parse an `LSP.Packet` from the beginning of a `Data` instance:\n\n```swift\nlet dataStartingWithPacket = packetTotalData + \"Some other data\".data(using: .utf8)!\nlet detectedPacket = try LSP.Packet(parsingPrefixOf: dataStartingWithPacket)\n\n// now detectedPacket == myRequestMessagePacket\n```\n\nSwiftLSP also offers the `LSP.PacketDetector` for parsing a stream of `Data` incrementally:\n\n```swift\nvar streamedPacket: LSP.Packet? = nil\n        \nlet detector = LSP.PacketDetector { packet in\n    streamedPacket = packet\n}\n\nfor byte in dataStartingWithPacket {\n    detector.read(byte)\n}\n\n// now streamedPacket == myRequestMessagePacket\n```\n\n## More Use Cases\n\nBeyond what the examples above have touched, SwiftLSP also helps with:\n\n* Creating messages for specific use cases (initialize server, request symbols, request references ...) \n* Launching an LSP server executable\n* Matching response messages to request messages\n* Making requests to an LSP Server through `async` functions\n* Using an LSP Server via WebSocket\n\n## Architecture\n\nSome context and essential types:\n\n![architecture](Documentation/architecture_dark.png#gh-dark-mode-only)\n![architecture](Documentation/architecture_light.png#gh-light-mode-only)\n\nInternal architecture (composition and essential dependencies) of the top-level source folder:\n\n![](Documentation/SwiftLSP.png)\n\nThe above image was generated with [Codeface](https://codeface.io).\n\n## Development Status\n\nFrom version/tag 0.1.0 on, SwiftLSP adheres to [semantic versioning](https://semver.org). So until it has reached 1.0.0, its API may still break frequently, but this will be expressed in version bumps.\n\nSwiftLSP is already being used in production, but [Codeface](https://codeface.io) is still its primary client. SwiftLSP 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.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeface-io%2FSwiftLSP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeface-io%2FSwiftLSP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeface-io%2FSwiftLSP/lists"}