Skip to content

Commit bdcbb11

Browse files
committed
Merge remote-tracking branch 'origin/master' into swift-5.1-branch
Semantically, we want our branch point to match swiftpm, but all of the changes since then also look good to take into the branch, so just do one last merge from master.
2 parents c2f720d + 31fea30 commit bdcbb11

File tree

14 files changed

+75
-78
lines changed

14 files changed

+75
-78
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.DS_Store
22
default.profraw
3+
Package.resolved
34
/.build
45
/Packages
56
/*.xcodeproj
67
/*.sublime-project
78
/*.sublime-workspace
9+
/.swiftpm

Editors/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ You will need the path to the `sourcekit-lsp` executable and the Swift toolchain
3939
"scopes": ["source.swift"],
4040
"syntaxes": [
4141
"Packages/Swift/Syntaxes/Swift.tmLanguage",
42+
"Packages/Decent Swift Syntax/Swift.sublime-syntax",
4243
],
4344
"languageId": "swift"
4445
},

Editors/vscode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $ cd Editors/vscode
2222
$ npm run createDevPackage
2323
```
2424

25-
You can install the package from the command-line if you have the `code` executable on your `PATH`:
25+
You can install the package from the command-line using the `code` command if available (see [Launching from the command line](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)).
2626

2727
```
2828
code --install-extension out/sourcekit-lsp-vscode-dev.vsix

Package.resolved

Lines changed: 0 additions & 34 deletions
This file was deleted.

Package.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ let package = Package(
77
products: [
88
],
99
dependencies: [
10-
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
11-
.package(url: "https://github.com/apple/indexstore-db.git", .branch("master")),
10+
// See 'Dependencies' below.
1211
],
1312
targets: [
1413
.target(
@@ -82,3 +81,28 @@ let package = Package(
8281
dependencies: ["SKSupport", "SKTestSupport"]),
8382
]
8483
)
84+
85+
// MARK: Dependencies
86+
87+
// When building with the swift build-script, use local dependencies whose contents are controlled
88+
// by the external environment. This allows sourcekit-lsp to take advantage of the automation used
89+
// for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests.
90+
91+
#if os(Linux)
92+
import Glibc
93+
#else
94+
import Darwin.C
95+
#endif
96+
97+
if getenv("SWIFTCI_USE_LOCAL_DEPS") == nil {
98+
// Building standalone.
99+
package.dependencies += [
100+
.package(url: "https://github.com/apple/indexstore-db.git", .branch("master")),
101+
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
102+
]
103+
} else {
104+
package.dependencies += [
105+
.package(path: "../indexstore-db"),
106+
.package(path: "../swiftpm"),
107+
]
108+
}

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SourceKit-LSP is an implementation of the [Language Server Protocol](https://mic
77

88
SourceKit-LSP is under heavy development! The best way to try it out is to build it from source. You will also need a Swift development toolchain and an editor that supports LSP.
99

10-
1. Install the `swift-DEVELOPMENT-SNAPSHOT-2019-01-22-a` toolchain snapshot from https://swift.org/download/#snapshots. Set the environment variable `SOURCEKIT_TOOLCHAIN_PATH` to the absolute path to the toolchain or otherwise configure your editor to use this toolchain. See [Toolchains](#toolchains) for more information.
10+
1. Install the latest master toolchain snapshot from https://swift.org/download/#snapshots. Set the environment variable `SOURCEKIT_TOOLCHAIN_PATH` to the absolute path to the toolchain or otherwise configure your editor to use this toolchain. See [Toolchains](#toolchains) for more information.
1111

1212
2. Build the language server executable `sourcekit-lsp` using `swift build`. See [Building](#building-sourcekit-lsp) for more information.
1313

@@ -23,17 +23,20 @@ SourceKit-LSP is built using the [Swift Package Manager](https://github.com/appl
2323
For a standard debug build:
2424

2525
```sh
26+
$ swift package update
2627
$ swift build
2728
```
2829

2930
After building, the server will be located at `.build/debug/sourcekit-lsp`, or a similar path, if you passed any custom options to `swift build`. Editors will generally need to be provided with this path in order to run the newly built server - see [Editors](Editors) for more information about configuration.
3031

32+
SourceKit-LSP is designed to build against the latest SwiftPM, so if you run into any issue make sure you have the most up-to-date dependencies by running `swift package update`.
33+
3134
### Building on Linux
3235

3336
The C++ code in the index requires `libdispatch`, but unlike Swift code, it cannot find it automatically on Linux. You can work around this by adding a search path manually.
3437

3538
```sh
36-
$ swift build -Xcxx -I<path_to_swift_toolchain>/usr/lib/swift
39+
$ swift build -Xcxx -I<path_to_swift_toolchain>/usr/lib/swift -I<path_to_swift_toolchain>/usr/lib/swift/Block
3740
```
3841

3942
### Using the Generated Xcode Project
@@ -73,7 +76,7 @@ SourceKit-LSP depends on tools such as `sourcekitd` and `clangd`, which it loads
7376

7477
### Recommended Toolchain
7578

76-
Use the `swift-DEVELOPMENT-SNAPSHOT-2019-01-22-a` toolchain snapshot from https://swift.org/download/#snapshots. SourceKit-LSP is still early in its development and we are actively adding functionality to the toolchain to support it.
79+
Use the latest master toolchain snapshot from https://swift.org/download/#snapshots. SourceKit-LSP is still early in its development and we are actively adding functionality to the toolchain to support it.
7780

7881
### Selecting the Toolchain
7982

@@ -104,7 +107,7 @@ SourceKit-LSP is still in early development, so you may run into rough edges wit
104107
| Feature | Status | Notes |
105108
|---------|:------:|-------|
106109
| Swift || |
107-
| C/C++/ObjC | ❌ | [clangd](https://clang.llvm.org/extra/clangd.html) is not available in the recommended toolchain. You can try out C/C++/ObjC support by building clangd from source and putting it in `PATH`.
110+
| C/C++/ObjC | ❌ | As of `swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a` [clangd](https://clang.llvm.org/extra/clangd.html) is available but hitting frequent assertion failures.
108111
| Code completion || |
109112
| Quick Help (Hover) || |
110113
| Diagnostics || |

Sources/SKCore/ToolchainRegistry.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import SKSupport
1414
import Basic
1515
import SPMUtility
1616
import Dispatch
17-
import POSIX
1817
import Foundation
1918

2019
/// Set of known toolchains.
@@ -43,7 +42,7 @@ public final class ToolchainRegistry {
4342

4443
/// The currently selected toolchain identifier on Darwin.
4544
public internal(set) lazy var darwinToolchainOverride: String? = {
46-
if let id = getenv("TOOLCHAINS"), !id.isEmpty, id != "default" {
45+
if let id = ProcessEnv.vars["TOOLCHAINS"], !id.isEmpty, id != "default" {
4746
return id
4847
}
4948
return nil
@@ -278,7 +277,7 @@ extension ToolchainRegistry {
278277
{
279278
var shouldSetDefault = setDefault
280279
for envVar in environmentVariables {
281-
if let pathStr = getenv(envVar),
280+
if let pathStr = ProcessEnv.vars[envVar],
282281
let path = try? AbsolutePath(validating: pathStr),
283282
let toolchain = try? _registerToolchain(path, fileSystem),
284283
shouldSetDefault
@@ -301,7 +300,7 @@ extension ToolchainRegistry {
301300

302301
func _scanForToolchains(pathVariables: [String], _ fileSystem: FileSystem) {
303302
pathVariables.lazy.flatMap { envVar in
304-
getEnvSearchPaths(pathString: getenv(envVar), currentWorkingDirectory: nil)
303+
getEnvSearchPaths(pathString: ProcessEnv.vars[envVar], currentWorkingDirectory: nil)
305304
}
306305
.forEach { path in
307306
_ = try? _registerToolchain(path, fileSystem)

Sources/SourceKit/SourceKitServer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ public final class SourceKitServer: LanguageServer {
169169
return nil
170170
}
171171

172+
let pid = Int(ProcessInfo.processInfo.processIdentifier)
172173
let resp = try service.sendSync(InitializeRequest(
173-
processId: Int(getpid()),
174+
processId: pid,
174175
rootPath: nil,
175176
rootURL: (workspace?.rootPath).map { URL(fileURLWithPath: $0.pathString) },
176177
initializationOptions: InitializationOptions(),

Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ final class SwiftSourceKitFramework {
4242

4343
init(dylib path: AbsolutePath) throws {
4444
self.path = path
45+
#if os(Windows)
46+
self.dylib = try dlopen(path.pathString, mode: [])
47+
#else
4548
self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind])
49+
#endif
4650

4751
func dlsym_required<T>(_ handle: DLHandle, symbol: String) throws -> T {
4852
guard let sym: T = dlsym(handle, symbol: symbol) else {
@@ -54,7 +58,7 @@ final class SwiftSourceKitFramework {
5458
// Workaround rdar://problem/43656704 by not constructing the value directly.
5559
// self.api = sourcekitd_functions_t(
5660
let ptr = UnsafeMutablePointer<sourcekitd_functions_t>.allocate(capacity: 1)
57-
bzero(UnsafeMutableRawPointer(ptr), MemoryLayout<sourcekitd_functions_t>.stride)
61+
memset(UnsafeMutableRawPointer(ptr), 0, MemoryLayout<sourcekitd_functions_t>.stride)
5862
var api = ptr.pointee
5963
ptr.deallocate()
6064

Tests/SKCoreTests/ToolchainRegistryTests.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import Basic
1515
import SPMUtility
1616
import XCTest
17-
import POSIX
1817

1918
final class ToolchainRegistryTests: XCTestCase {
2019
func testDefaultBasic() {
@@ -186,8 +185,8 @@ final class ToolchainRegistryTests: XCTestCase {
186185
XCTAssertNil(tr.default)
187186
XCTAssert(tr.toolchains.isEmpty)
188187

189-
try! setenv("SOURCEKIT_PATH", value: "/bogus:\(binPath):/bogus2")
190-
defer { try! setenv("SOURCEKIT_PATH", value: "") }
188+
try! ProcessEnv.setVar("SOURCEKIT_PATH", value: "/bogus:\(binPath):/bogus2")
189+
defer { try! ProcessEnv.setVar("SOURCEKIT_PATH", value: "") }
191190

192191
tr.scanForToolchains(fs)
193192

@@ -205,7 +204,7 @@ final class ToolchainRegistryTests: XCTestCase {
205204
XCTAssertNil(tc.libIndexStore)
206205

207206
let binPath2 = AbsolutePath("/other/my_toolchain/bin")
208-
try! setenv("SOME_TEST_ENV_PATH", value: "/bogus:\(binPath2):/bogus2")
207+
try! ProcessEnv.setVar("SOME_TEST_ENV_PATH", value: "/bogus:\(binPath2):/bogus2")
209208
makeToolchain(binPath: binPath2, fs, sourcekitd: true)
210209
tr.scanForToolchains(pathVariables: ["NOPE", "SOME_TEST_ENV_PATH", "MORE_NOPE"], fs)
211210

@@ -228,7 +227,7 @@ final class ToolchainRegistryTests: XCTestCase {
228227
XCTAssertNil(tr.default)
229228
XCTAssert(tr.toolchains.isEmpty)
230229

231-
try! setenv("TEST_SOURCEKIT_TOOLCHAIN_PATH_1", value: binPath.parentDirectory.pathString)
230+
try! ProcessEnv.setVar("TEST_SOURCEKIT_TOOLCHAIN_PATH_1", value: binPath.parentDirectory.pathString)
232231

233232
tr.scanForToolchains(environmentVariables: ["TEST_SOURCEKIT_TOOLCHAIN_PATH_1"], fs)
234233

@@ -255,7 +254,7 @@ final class ToolchainRegistryTests: XCTestCase {
255254
XCTAssertNil(tr.default)
256255
XCTAssert(tr.toolchains.isEmpty)
257256

258-
try! setenv("TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH_2", value: binPath.parentDirectory.pathString)
257+
try! ProcessEnv.setVar("TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH_2", value: binPath.parentDirectory.pathString)
259258

260259
tr.scanForToolchains(
261260
environmentVariables: ["TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH_2"],

Tests/SKSupportTests/SupportPerfTests.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
@testable import SKSupport
1414
import SKTestSupport
1515
import Basic
16-
import POSIX
1716
import XCTest
1817

1918
final class SupportPerfTests: PerfTestCase {
@@ -24,8 +23,7 @@ final class SupportPerfTests: PerfTestCase {
2423
"\t", "\n"
2524
] + (32...126).map { Character(UnicodeScalar($0)) }
2625

27-
// The debug performance is shockingly bad.
28-
#if DEBUG
26+
#if DEBUG || !ENABLE_PERF_TESTS
2927
let iterations = 1_000
3028
#else
3129
let iterations = 10_000
@@ -49,13 +47,11 @@ final class SupportPerfTests: PerfTestCase {
4947
}
5048

5149
func testLineTableSingleCharEditPerf() {
52-
5350
let characters: [Character] = [
5451
"\t", "\n"
5552
] + (32...126).map { Character(UnicodeScalar($0)) }
5653

57-
// The debug performance is shockingly bad.
58-
#if DEBUG
54+
#if DEBUG || !ENABLE_PERF_TESTS
5955
let iterations = 1_000
6056
let size = 1_000
6157
#else
@@ -75,9 +71,9 @@ final class SupportPerfTests: PerfTestCase {
7571
self.startMeasuring()
7672

7773
for _ in 1...iterations {
78-
let line = (0..<(t.count-1)).randomElement(using: &lcg)!
79-
let col = (0 ..< t[line].utf16.count).randomElement(using: &lcg)!
80-
let len = Bool.random() ? 1 : 0
74+
let line = (0 ..< (t.count-1)).randomElement(using: &lcg) ?? 0
75+
let col = (0 ..< t[line].utf16.count).randomElement(using: &lcg) ?? 0
76+
let len = t[line].isEmpty ? 0 : Bool.random() ? 1 : 0
8177
var newText = String(characters.randomElement(using: &lcg)!)
8278
if len == 1 && Bool.random(using: &lcg) {
8379
newText = "" // deletion

Tests/SKSupportTests/SupportTests.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import XCTest
1414
@testable import SKSupport
1515
import Basic
16-
import POSIX
1716

1817
final class SupportTests: XCTestCase {
1918

@@ -184,8 +183,8 @@ final class SupportTests: XCTestCase {
184183

185184
testLogger.currentLevel = .default
186185

187-
try! setenv("TEST_ENV_LOGGGING_1", value: "1")
188-
try! setenv("TEST_ENV_LOGGGING_0", value: "0")
186+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_1", value: "1")
187+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_0", value: "0")
189188
// .warning
190189
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_1")
191190

@@ -221,7 +220,7 @@ final class SupportTests: XCTestCase {
221220
])
222221

223222
// invalid - no change
224-
try! setenv("TEST_ENV_LOGGGING_err", value: "")
223+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_err", value: "")
225224
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_err")
226225

227226
log("d", level: .error)
@@ -233,7 +232,7 @@ final class SupportTests: XCTestCase {
233232
])
234233

235234
// invalid - no change
236-
try! setenv("TEST_ENV_LOGGGING_err", value: "a3")
235+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_err", value: "a3")
237236
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_err")
238237

239238
log("d", level: .error)
@@ -245,7 +244,7 @@ final class SupportTests: XCTestCase {
245244
])
246245

247246
// too high - max out at .debug
248-
try! setenv("TEST_ENV_LOGGGING_err", value: "1000")
247+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_err", value: "1000")
249248
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_err")
250249

251250
log("d", level: .error)
@@ -260,16 +259,16 @@ final class SupportTests: XCTestCase {
260259
])
261260

262261
// By string.
263-
try! setenv("TEST_ENV_LOGGGING_string", value: "error")
262+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "error")
264263
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
265264
XCTAssertEqual(testLogger.currentLevel, .error)
266-
try! setenv("TEST_ENV_LOGGGING_string", value: "warning")
265+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "warning")
267266
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
268267
XCTAssertEqual(testLogger.currentLevel, .warning)
269-
try! setenv("TEST_ENV_LOGGGING_string", value: "info")
268+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "info")
270269
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
271270
XCTAssertEqual(testLogger.currentLevel, .info)
272-
try! setenv("TEST_ENV_LOGGGING_string", value: "debug")
271+
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "debug")
273272
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
274273
XCTAssertEqual(testLogger.currentLevel, .debug)
275274

Tests/SourceKitTests/LocalClangTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import XCTest
2020
final class LocalClangTests: XCTestCase {
2121

2222
/// Whether to fail tests if clangd cannot be found.
23-
static let requireClangd: Bool = false
23+
static let requireClangd: Bool = false // Note: Swift CI doesn't build clangd on all jobs
2424

2525
/// Whether clangd exists in the toolchain.
2626
var haveClangd: Bool = false

0 commit comments

Comments
 (0)