From dc41f548b0ba9a42636087c39891ecd55cedb650 Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Thu, 11 Apr 2019 16:31:57 +0200 Subject: [PATCH] Sourcekit-lsp and documentation improvements #39 --- CHANGELOG.md | 7 +++++++ README.md | 30 +++++++++++++++++++++++++----- package.json | 15 ++++++++++++--- src/clientMain.ts | 29 ++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1930673..7450c4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.7.0 + +- Latest sourcekite is now compatible with Swift 5. +- Added options for sourcekit-lsp: `sourcekit-lsp.serverPath` and `sourcekit-lsp.toolchainPath`. [#39](https://github.com/vknabel/vscode-swift-development-environment/issues/39) +- `sde.languageServerMode` now explicitly offers `sourcekit-lsp`. +- Updated installation instructions with a stronger emphasize on sourcekit-lsp. + ## 2.6.0 - Add support for alternative language servers like [RLovelett/langserver-swift](https://github.com/RLovelett/langserver-swift) #21 diff --git a/README.md b/README.md index 30e439e..cd48988 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,19 @@ ## Installation -1. Install the [extension](https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swift-development-environment) itself. +You have the choice between three different language server implementations. + +| `sde.languageServerMode` | Comments | Swift Versions | Install | +| ------------------------ | ----------------------------------------- | -------------------------- | -------------------------------------------------- | +| `sourcekit-lsp` | Apple's official one. Activley developed. | 4 and 5 | [#Using sourcekite](#Using-sourcekite) | +| `sourcekite` _default_ | SDE's one. Actively maintained. | 4, 5 and older version 3.1 | [#Using sourcekit-lsp](#Using-sourcekit-lsp) | +| `langserver` | RLovelett's LSP. Not maintained. | 4.1, macOS only | [#Using Langserver Swift](#Using-Langserver-Swift) | + +sourcekit-lsp is easier to install and will be updated more frequently. On the other hand sourcekite treats standalone files, Xcode projects and SwiftPM modules differently and is more configurable. If you can't decide, you can install both and swap out the used LSP by setting `sde.languageServerMode` to `sourcekite`, `sourcekit-lsp` or `langserver`. + +### Using sourcekite + +1. sourcekite does only work with [SDE](https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swift-development-environment). Make sure you have it installed. 2. Install the companion project [sourcekite](https://github.com/vknabel/sourcekite). ```bash @@ -25,22 +37,30 @@ $ swift build -Xlinker -l:sourcekitdInProc -c release # For macOS (when using swiftenv or multiple Toolchains) - $ swift build -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib -c release + $ make install LIB_DIR=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib # For macOS (using Xcode's Toolchain) - $ swift build -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -c release + $ make install LIB_DIR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib ``` 3. Add the _absolute_ path to your compiled sourcekite binary `swift.path.sourcekite` to your vscode settings as `/path/to/your/sourcekite-bin/.build/release/sourcekite`. If you experience any problems during installation, file an issue or write me an [email](mailto:dev@vknabel.com). All kind of feedback helps especially when trying to automate this. -## Alternative Language Server +### Using sourcekit-lsp -SDE allows you to use an alternative Language Server like [RLovelett/langserver-swift](https://github.com/RLovelett/langserver-swift) or Apple's [offically announced LSP](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024). +1. Install [SDE](https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swift-development-environment). +2. [Install sourcekite-lsp](https://github.com/apple/sourcekit-lsp#building-sourcekit-lsp). +3. Add the _absolute_ path to your compiled sourcekite binary `sourcekit-lsp.serverPath`, optionally to your toolchain `sourcekit-lsp.toolchainPath` and tell SDE to use sourcekit-lsp `"sde.languageServerMode": "sourcekit-lsp"`. + +### Using Langserver Swift + +Besides sourcekit-lsp and sourcekite SDE allows you to use [RLovelett/langserver-swift](https://github.com/RLovelett/langserver-swift). If you prefer using an alternative language server, set set `sde.languageServerMode` to `langserver` and let `swift.languageServerPath` point to your installed language server. +Though in most cases sourcekit-lsp and sourcekite should produce better results and performance. + ## Debugging SDE has a built-in Swift debugger which has been deprecated. Instead use [LLDB Debugger](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) which powers more features and is more stable. diff --git a/package.json b/package.json index 9a65608..283730f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/vknabel" }, "license": "Apache-2.0", - "version": "2.6.0", + "version": "2.7.0", "publisher": "vknabel", "icon": "icons/icon.png", "galleryBanner": { @@ -57,6 +57,14 @@ "type": "object", "title": "Swift Development Environment Configuration", "properties": { + "sourcekit-lsp.serverPath": { + "type": "string", + "description": "The path of the sourcekit-lsp executable" + }, + "sourcekit-lsp.toolchainPath": { + "type": "string", + "description": "The path of the swift toolchain" + }, "swift.languageServerPath": { "type": "string", "default": "/usr/local/bin/langserver-swift", @@ -138,9 +146,10 @@ "default": "sourcekite", "enum": [ "sourcekite", - "langserver" + "langserver", + "sourcekit-lsp" ], - "description": "Decides which language server should be used." + "description": "Decides which language server should be used. `sourcekite` is the default LSP for SDE, `sourcekit-lsp` is Apple's official one and `langserver` is RLovelett's Langserver." }, "sde.enableTracing.client": { "type": "boolean", diff --git a/src/clientMain.ts b/src/clientMain.ts index 4847784..2be9c72 100644 --- a/src/clientMain.ts +++ b/src/clientMain.ts @@ -85,8 +85,35 @@ function currentServerOptions(context: ExtensionContext) { return serverOptions; } + function sourcekitLspServerOptions() { + // Load the path to the language server from settings + const executableCommand = + workspace + .getConfiguration("sourcekit-lsp") + .get("sourcekit-lsp.serverPath") || + workspace + .getConfiguration("swift") + .get("languageServerPath", "/usr/local/bin/sourcekit-lsp"); + const toolchain = workspace + .getConfiguration("sourcekit-lsp") + .get("toolchainPath"); + const env = toolchain + ? { env: { ...process.env, SOURCEKIT_TOOLCHAIN_PATH: toolchain } } + : { env: process.env }; + + const run: Executable = { command: executableCommand, options: { env } }; + const debug: Executable = run; + const serverOptions: ServerOptions = { + run: run, + debug: debug + }; + return serverOptions; + } + const lspMode = workspace.getConfiguration("sde").get("languageServerMode"); - if (lspMode === "langserver") { + if (lspMode === "sourcekit-lsp") { + return sourcekitLspServerOptions(); + } else if (lspMode === "langserver") { return lspServerOptions(); } else { return sourcekiteServerOptions();