Skip to content

Commit dd0b724

Browse files
authored
Merge pull request swiftlang#145 from benlangmuir/merge-51
[5.1] Update with changes from master
2 parents 3bd5835 + 940c447 commit dd0b724

File tree

97 files changed

+4257
-2331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4257
-2331
lines changed

Documentation/Development.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Development
2+
3+
This document contains notes about development and testing of SourceKit-LSP.
4+
5+
## Table of Contents
6+
7+
* [Debugging](#debugging)
8+
* [Writing Tests](#writing-tests)
9+
10+
## Debugging
11+
12+
You can attach LLDB to SourceKit-LSP and set breakpoints to debug. You may want to instruct LLDB to wait for the sourcekit-lsp process to launch and then start your editor, which will typically launch
13+
SourceKit-LSP as soon as you open a Swift file:
14+
15+
```sh
16+
$ lldb -w -n sourcekit-lsp
17+
```
18+
19+
If you are using the Xcode project, go to Debug, Attach to Process by PID or Name.
20+
21+
### Print SourceKit Logs
22+
23+
You can configure SourceKit-LSP to print log information from SourceKit to stderr by setting the following environment variable:
24+
25+
```sh
26+
SOURCEKIT_LOGGING="N"
27+
```
28+
29+
Where "N" configures the log verbosity and is one of the following numbers: 0 (error), 1 (warning), 2 (info), or 3 (debug).
30+
31+
## Writing Tests
32+
33+
As much as is practical, all code should be covered by tests. New tests can be added under the `Tests` directory and should use `XCTest`. The rest of this section will describe the additional tools available in the `SKTestSupport` module to make it easier to write good and efficient tests.
34+
35+
### Test Projects (Fixtures)
36+
37+
SourceKit test projects should be put in the `Tests/INPUTS` directory. Generally, they should use the [Tibs](#tibs) build system to define their sources and targets. An exception is for tests that need to specifically test the interaction with the Swift Package Manager. An example Tibs test project might look like:
38+
39+
```
40+
Tests/
41+
INPUTS/
42+
MyTestProj/
43+
a.swift
44+
b.swift
45+
c.cpp
46+
```
47+
48+
Where `project.json` describes the project's targets, for example
49+
50+
```
51+
{ "sources": ["a.swift", "b.swift", "c.cpp"] }
52+
```
53+
54+
Tibs supports more advanced project configurations, such as multiple swift modules with dependencies, etc. For much more information about Tibs, including what features it supports and how it works, see [Tibs](#tibs).
55+
56+
### SKTibsTestWorkspace
57+
58+
The `SKTibsTestWorkspace` pulls together the various pieces needed for working with tests, including opening a connection to the language server, building the project to produce index data, loading source code into open documents, etc.
59+
60+
To create a `SKTibsTestWorkspace`, use the `staticSourceKitTibsWorkspace` method (the intent is to provide a `mutableSourceKitTibsWorkspace` method in the future for tests that mutate source code).
61+
62+
```swift
63+
func testFoo() {
64+
// Create the workspace, including opening a connection to the TestServer.
65+
guard let ws = try staticSourceKitTibsWorkspace(name: "MyTestProj") else { return }
66+
let loc = ws.testLoc("myLocation")
67+
68+
// Build the project and populate the index.
69+
try ws.buildAndIndex()
70+
71+
// Open a document from the test project sources.
72+
try ws.openDocument(loc.url, language: .swift)
73+
74+
// Send requests to the server.
75+
let response = try ws.sk.sendSync(...)
76+
}
77+
```
78+
79+
#### Source Locations
80+
81+
It is common to want to refer to specific locations in the source code of a test project. This is supported using inline comment syntax.
82+
83+
```swift
84+
Test.swift:
85+
func /*myFuncDef*/myFunc() {
86+
/*myFuncCall*/myFunc()
87+
}
88+
```
89+
90+
In a test, these locations can be referenced by name. The named location is immediately after the comment.
91+
92+
```swift
93+
94+
let loc = ws.testLoc("myFuncDef")
95+
// TestLocation(url: ..., line: 1, column: 19)
96+
```
97+
98+
`TestLocation`s can be easily converted to LSP `Location` and `Position`s.
99+
100+
```swift
101+
Location(ws.testLoc("aaa:call"))
102+
Position(ws.testLoc("aaa:call"))
103+
```
104+
105+
## Tibs
106+
107+
We use Tibs, the "Test Index Build System" from the IndexStoreDB project to provide build system support for test projects, including getting compiler arguments and building an index.
108+
For much more information about Tibs, see [IndexStoreDB/Documentation/Tibs.md](https://github.com/apple/indexstore-db/blob/master/Documentation/Tibs.md).

Editors/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ autocmd FileType swift setlocal omnifunc=lsp#complete
102102

103103
With this added in `.vimrc`, you can use `<c-x><c-o>` in insert mode to trigger sourcekit-lsp completion.
104104

105+
## Theia Cloud IDE
106+
107+
You can use SourceKit-LSP with Theia by using the `theiaide/theia-swift` image. To use the image you need to have [Docker](https://docs.docker.com/get-started/) installed first.
108+
109+
The following command pulls the image and runs Theia IDE on http://localhost:3000 with the current directory as a workspace.
110+
111+
docker run -it -p 3000:3000 -v "$(pwd):/home/project:cached" theiaide/theia-swift:next
112+
113+
You can pass additional arguments to Theia after the image name, for example to enable debugging:
114+
115+
docker run -it -p 3000:3000 --expose 9229 -p 9229:9229 -v "$(pwd):/home/project:cached" theiaide/theia-swift:next --inspect=0.0.0.0:9229
116+
117+
Image Variants
118+
119+
`theiaide/theia-swift:latest`
120+
This image is based on the latest stable released version.
121+
122+
`theiaide/theia-swift:next`
123+
This image is based on the nightly published version.
124+
125+
theia-swift-docker source [theia-apps](https://github.com/theia-ide/theia-apps)
126+
127+
105128
## Other Editors
106129

107130
SourceKit-LSP should work with any editor that supports the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/)

0 commit comments

Comments
 (0)