SwiftLSPClient
This is a Swift library for interacting with Language Server Protocol implementations.
An LSP server provides rich information about source code. An LSP client consumes this information. This library is all about the client side.
Example
import SwiftLSPClient
let executablePath = "path/to/your/lsp-server-executable"
let host = LanguageServerProcessHost(path: executablePath, arguments: [],
environment: [/* the environment your lsp server requires e.g. PATH */])
host.start { (server) in
guard let server = server else {
Swift.print("unable to launch server")
return
}
// Set-up notificationResponder to see log/error messages from LSP server
server.notificationResponder = <object conforming to NotificationResponder>
let processId = Int(ProcessInfo.processInfo.processIdentifier)
let capabilities = ClientCapabilities(workspace: nil, textDocument: nil, experimental: nil)
let params = InitializeParams(processId: processId,
rootPath: nil,
rootURI: nil,
initializationOptions: nil,
capabilities: capabilities,
trace: Tracing.off,
workspaceFolders: nil)
server.initialize(params: params, block: { (result) in
switch result {
case .failure(let error):
Swift.print("unable to initialize \(error)")
case .success(let value):
Swift.print("initialized \(value)")
}
})
}
Supported Features
The LSP specification is large, and this library currently does not implement it all. The intention is to support the 3.x specification, but be as backwards-compatible as possible with pre-3.0 servers.
Feature | Supported |
---|---|
window/showMessage | ✅ |
window/showMessageRequest | ✅ |
window/logMessage | ✅ |
window/workDoneProgress/create | - |
window/workDoneProgress/cancel | - |
telemetry/event | - |
client/registerCapability | - |
client/unregisterCapability | - |
workspace/workspaceFolders | - |
workspace/didChangeWorkspaceFolders | - |
workspace/didChangeConfiguration | - |
workspace/configuration | - |
workspace/didChangeWatchedFiles | - |
workspace/symbol | - |
workspace/executeCommand | - |
workspace/applyEdit | - |
textDocument/didOpen | ✅ |
textDocument/didChange | ✅ |
textDocument/willSave | ✅ |
textDocument/willSaveWaitUntil | ✅ |
textDocument/didSave | ✅ |
textDocument/didClose | ✅ |
textDocument/publishDiagnostics | ✅ |
textDocument/completion | ✅ |
completionItem/resolve | - |
textDocument/hover | ✅ |
textDocument/signatureHelp | ✅ |
textDocument/declaration | ✅ |
textDocument/definition | ✅ |
textDocument/typeDefinition | ✅ |
textDocument/implementation | ✅ |
textDocument/references | ✅ |
textDocument/documentHighlight | - |
textDocument/documentSymbol | ✅ |
textDocument/codeAction | ✅ |
textDocument/codeLens | - |
codeLens/resolve | - |
textDocument/documentLink | - |
documentLink/resolve | - |
textDocument/documentColor | - |
textDocument/colorPresentation | - |
textDocument/formatting | ✅ |
textDocument/rangeFormatting | ✅ |
textDocument/onTypeFormatting | ✅ |
textDocument/rename | - |
textDocument/prepareRename | - |
textDocument/foldingRange | ✅ |
textDocument/selectionRange | - |
Integration
Swift Package Manager
dependencies: [
.package(url: "https://github.com/ChimeHQ/SwiftLSPClient.git")
]
Carthage
github "ChimeHQ/SwiftLSPClient"
CocoaPods
pod 'SwiftLSPClient'
Suggestions or Feedback
We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Github
link |
Stars: 83 |
You may find interesting
Releases
v0.8.4 - 2020-06-24T20:02:47
- Improved support for Diagnostics
- Fixed some small warnings
v0.8.3 - 2020-03-24T00:23:14
codeAction support
v0.8.2 - 2019-11-03T01:41:15
- expanded LanguageIdentifier.fileExtensions
- support for foldingRange
v0.8.1 - 2019-10-31T00:36:29
- Includes support for textDocument/references
- Adds some convenience methods for a few parameter types
- Resolves a serious thread safety issue with
ProtocolTransport
Huge thanks to @johnno1962 for all the work getting these things done!
v0.8.0 - 2019-09-10T16:56:21
- Support for the various "go to" source navigation features
- Improved diagnostic capabilities with LanguageServerError
v0.7.1 - 2019-09-03T17:25:48
Support for showMessageRequest
v0.7.0 - 2019-08-22T11:30:04
Support for SwiftPM and Swift 5.0
v0.6.5 - 2019-03-14T18:44:52
Includes a quick fix for writes that occur after a host is shutdown
v0.6.4 - 2019-02-18T17:15:09
- documentSymbol support
- fix for notification callback
v0.6.3 - 2019-02-13T16:24:40
- fix bug in workspace initialization type
- add support for willSave* functions
v0.6.2 - 2019-02-09T19:22:19
documentSymbol support
v0.6.1 - 2019-01-31T01:50:17
Just a version bump to prepare for the first CocoaPods release
v0.6.0 - 2019-01-28T01:57:36
- Expanded protocol support
- Fixes a critical bug that can occur when more than one message is delivered at the same time
- Improved ability to capture server errors and relay them correctly
- Notification support
v0.5.5 - 2019-01-16T16:06:35
Moves some core LSP types out into dedicated files, and adds Equatable and CustomStringConvertible
0.5.4 - 2019-01-08T20:03:07
v0.5.3 - 2018-12-13T17:20:16
Adds in some more graceful behavior should the underlying hosted server process crash.
v0.5.2 - 2018-12-08T01:49:00
- Support for signatureHelp
- A helper class to host local server processes