You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 17, 2018. It is now read-only.
[](https://gitter.im/langserver-swift?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
8
9
-
##Overview
9
+
# Overview
10
10
11
11
A Swift implementation of the open [Language Server Protocol](https://github.com/Microsoft/language-server-protocol). The Language Server protocol is used between a tool (the client) and a language smartness provider (the server) to integrate features like auto complete, goto definition, find all references and alike into the tool.
12
12
13
13
Currently this implementation is used by [Swift for Visual Studio Code](https://github.com/RLovelett/vscode-swift).
14
14
15
-
##Prerequisites
15
+
# Prerequisites
16
16
17
-
###Swift
17
+
## Swift
18
18
19
19
* Swift version 3.1.1
20
20
* The toolchain that comes with Xcode 8.3.2 (`Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)`)
21
21
22
-
###macOS
22
+
## macOS
23
23
24
24
* macOS 10.12 (*Sierra*) or higher
25
25
* Xcode Version 8.3.2 (8E2002) or higher using one of the above toolchains (*Recommended*)
26
26
27
-
###Linux
27
+
## Linux
28
28
29
29
***Coming Soon**
30
30
31
-
##Build
31
+
# Build
32
32
33
33
```
34
34
% cd <path-to-clone>
@@ -42,9 +42,84 @@ or with Xcode
42
42
% swift package generate-xcodeproj --xcconfig-overrides settings.xcconfig
43
43
```
44
44
45
-
##Test
45
+
# Test
46
46
47
47
```
48
48
% cd <path-to-clone>
49
49
% swift test -Xswiftc -target -Xswiftc x86_64-apple-macosx10.11
50
50
```
51
+
# Debug and Development
52
+
53
+
The language server itself relies on a language server client to interact with it. [This server has been developed to work with Visual Studio Code](https://github.com/RLovelett/vscode-swift). Though it should be noted that any client that implements the protocol _should_ work and is thusly supported.
54
+
55
+
An example workflow for interactively debugging the language server while using it with the Visual Stuio Code client is provided in this section. The instructions are devided into two sections. The first section explains how to generate and configure an Xcode project for debugging. The second section explains how to configure the Visual Studio Code plugin to use the debug executable.
% swift package generate-xcodeproj --xcconfig-overrides settings.xcconfig
65
+
```
66
+
67
+
Since the language server client, e.g., VSCode, will actually launch the language server LLDB needs to be told to wait for the application to launch. This can be configured in Xcode after opening the generated project in Xcode. See the screenshot below.
68
+
69
+
<imgwidth="997"alt="screen shot 2017-02-22 at 8 55 57 am"src="https://cloud.githubusercontent.com/assets/335572/23214552/1b0afce2-f8dd-11e6-8812-370ad148ee73.png">
70
+
71
+
The next step is to build the executable and launch LLDB. Both of these steps can be performed by going to "Product > Run" or the keyboard shortcut ⌘R. After building completes, Xcode should report something like "Waiting to attach to LanguageServer : LanguageServer".
72
+
73
+
<imgwidth="844"alt="screen shot 2017-02-22 at 9 40 33 am"src="https://cloud.githubusercontent.com/assets/335572/23216177/0b0fc6a0-f8e3-11e6-9f0c-a5d71a01933a.png">
74
+
75
+
One final step is to determine the `TARGET_BUILD_DIR`. This is used to tell the VSCode extension in the next section where the debug language server is located.
76
+
77
+
From a terminal whose current working directory contains the Xcode project previously generated by SwiftPM you can get this information from `xcodebuild`.
Start the TypeScript compiler or the build task (e.g., ⇧⌘B or Tasks: Run Build Task).
96
+
97
+
Now open `src/extension.ts` and provide the value of `TARGET_BUILD_DIR` for the debug executable. The change should be similar to the patch that follows.
98
+
99
+
```
100
+
diff --git a/src/extension.ts b/src/extension.ts
101
+
index b5ad751..7970ae1 100644
102
+
--- a/src/extension.ts
103
+
+++ b/src/extension.ts
104
+
@@ -13,7 +13,7 @@ export function activate(context: ExtensionContext) {
let run: Executable = { command: executableCommand };
108
+
- let debug: Executable = run;
109
+
+ let debug: Executable = { command: "${TARGET_BUILD_DIR}/LanguageServer" };
110
+
let serverOptions: ServerOptions = {
111
+
run: run,
112
+
debug: debug
113
+
```
114
+
115
+
**NOTE:** Make sure the `${TARGET_BUILD_DIR}` is populated with the value you generated in the Xcode section. It is not an environment variable so that will not be evaluated.
116
+
117
+
Once this is complete you should be able to open the VSCode debugger and and select `Launch Extension`. This should start both the language server (Xcode/Swift) and the extension (VScode/TypeScript) in debug mode.
118
+
119
+
# Caveats
120
+
121
+
1. As noted above you might not be able to capture all the commands upon the language server initially starting up. The current hypothesis is that it takes a little bit of time for LLDB (the Swift debugger) to actually attach to the running process so a few instructions are missed.
122
+
123
+
One recommendation is to put a break-point in [`handle.swift`](https://github.com/RLovelett/langserver-swift/blob/251641da96ac1e0ae90f0ead3aa2f210fcb2c599/Sources/LanguageServer/Functions/handle.swift#L17) as this is likely where the server is getting into to trouble.
124
+
125
+
2. Messages are logged to the `Console.app` using the `me.lovelett.langserver-swift` sub-system. One place to look the raw language server JSON-RPC messages is there.
0 commit comments