Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Sourcekit-lsp and documentation improvements #39
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Apr 11, 2019
1 parent e14697f commit dc41f54
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:[email protected]). 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.
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
29 changes: 28 additions & 1 deletion src/clientMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("sourcekit-lsp.serverPath") ||
workspace
.getConfiguration("swift")
.get("languageServerPath", "/usr/local/bin/sourcekit-lsp");
const toolchain = workspace
.getConfiguration("sourcekit-lsp")
.get<string>("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();
Expand Down

0 comments on commit dc41f54

Please sign in to comment.