Skip to content

[5.1] Update swift-5.1-branch to match the swiftpm branch point #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3fd959a
Update recommended toolchain to 2019-02-14-a
benlangmuir Feb 16, 2019
48b602e
Update status of clangd in the toolchain
benlangmuir Feb 16, 2019
3b8aec6
[swiftpm] Update to latest master
benlangmuir Feb 16, 2019
5c0ac9d
Merge pull request #84 from benlangmuir/tcup
benlangmuir Feb 16, 2019
4ee3761
Undo optimisim around requiring clangd during testing
benlangmuir Feb 16, 2019
9f044b9
Merge pull request #85 from benlangmuir/undo-optimism
shahmishal Feb 16, 2019
59a5bf7
[test] Make swiftpm test robust against host triple differences
benlangmuir Mar 1, 2019
6a634a0
Merge pull request #87 from benlangmuir/power
benlangmuir Mar 1, 2019
0299247
[editors] Add alternative swift syntax spec to sublime config
benlangmuir Mar 1, 2019
079057f
Merge pull request #88 from benlangmuir/decency
benlangmuir Mar 1, 2019
2b930e5
Workaround perf test running too many iterations
benlangmuir Mar 7, 2019
dbd474e
Merge pull request #90 from benlangmuir/perf-slow
benlangmuir Mar 7, 2019
4526413
Update package depenencies
benlangmuir Mar 7, 2019
3a69aef
Remove Package.resolved and move to HEAD
benlangmuir Mar 7, 2019
49e5f39
[readme] Update recommended toolchain to 'latest'
benlangmuir Mar 7, 2019
b6e9182
[readme] Mention swift-package-update workflow
benlangmuir Mar 7, 2019
4278f97
Merge pull request #91 from benlangmuir/head-deps
benlangmuir Mar 7, 2019
6c970e0
Add how to add code cmd in the terminal
mackoj Mar 13, 2019
8fc6030
Merge pull request #92 from mackoj/patch-1
benlangmuir Mar 13, 2019
5afd361
Move sourcekit-lsp off of SwiftPM's POSIX
aciidgh Mar 24, 2019
3ba4c1a
Merge pull request #95 from aciidb0mb3r/minimize-posix
benlangmuir Mar 25, 2019
e4c3574
Must include full path to `Block.h`
chiroptical Apr 4, 2019
2b695f0
Merge pull request #96 from barrymoo/patch-1
benlangmuir Apr 4, 2019
116389b
[test] Fix rare failure in LineTable editing test
benlangmuir Apr 12, 2019
6d6f899
Merge pull request #97 from benlangmuir/rand-delete
benlangmuir Apr 12, 2019
0868c5f
Fixup SourceKit module on Windows
gmittert Apr 18, 2019
2dbc232
Merge pull request #100 from gmittert/SourceKitModuleWindows
akyrtzi Apr 18, 2019
b84b387
Get the pid of the current process using Foundation
gmittert Apr 22, 2019
31fea30
Merge pull request #101 from gmittert/UseFoundation
akyrtzi Apr 22, 2019
bdcbb11
Merge remote-tracking branch 'origin/master' into swift-5.1-branch
benlangmuir May 1, 2019
d28ec89
[deps] Fix dependency branches on swift-5.1
benlangmuir May 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.DS_Store
default.profraw
Package.resolved
/.build
/Packages
/*.xcodeproj
/*.sublime-project
/*.sublime-workspace
/.swiftpm
1 change: 1 addition & 0 deletions Editors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You will need the path to the `sourcekit-lsp` executable and the Swift toolchain
"scopes": ["source.swift"],
"syntaxes": [
"Packages/Swift/Syntaxes/Swift.tmLanguage",
"Packages/Decent Swift Syntax/Swift.sublime-syntax",
],
"languageId": "swift"
},
Expand Down
2 changes: 1 addition & 1 deletion Editors/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ cd Editors/vscode
$ npm run createDevPackage
```

You can install the package from the command-line if you have the `code` executable on your `PATH`:
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)).

```
code --install-extension out/sourcekit-lsp-vscode-dev.vsix
Expand Down
34 changes: 0 additions & 34 deletions Package.resolved

This file was deleted.

28 changes: 26 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ let package = Package(
products: [
],
dependencies: [
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
.package(url: "https://github.com/apple/indexstore-db.git", .branch("master")),
// See 'Dependencies' below.
],
targets: [
.target(
Expand Down Expand Up @@ -82,3 +81,28 @@ let package = Package(
dependencies: ["SKSupport", "SKTestSupport"]),
]
)

// MARK: Dependencies

// When building with the swift build-script, use local dependencies whose contents are controlled
// by the external environment. This allows sourcekit-lsp to take advantage of the automation used
// for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests.

#if os(Linux)
import Glibc
#else
import Darwin.C
#endif

if getenv("SWIFTCI_USE_LOCAL_DEPS") == nil {
// Building standalone.
package.dependencies += [
.package(url: "https://github.com/apple/indexstore-db.git", .branch("swift-5.1-branch")),
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("swift-5.1-branch")),
]
} else {
package.dependencies += [
.package(path: "../indexstore-db"),
.package(path: "../swiftpm"),
]
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SourceKit-LSP is an implementation of the [Language Server Protocol](https://mic

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.

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.
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.

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

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

```sh
$ swift package update
$ swift build
```

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.

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`.

### Building on Linux

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.

```sh
$ swift build -Xcxx -I<path_to_swift_toolchain>/usr/lib/swift
$ swift build -Xcxx -I<path_to_swift_toolchain>/usr/lib/swift -I<path_to_swift_toolchain>/usr/lib/swift/Block
```

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

### Recommended Toolchain

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.
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.

### Selecting the Toolchain

Expand Down Expand Up @@ -104,7 +107,7 @@ SourceKit-LSP is still in early development, so you may run into rough edges wit
| Feature | Status | Notes |
|---------|:------:|-------|
| Swift | ✅ | |
| 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`.
| 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.
| Code completion | ✅ | |
| Quick Help (Hover) | ✅ | |
| Diagnostics | ✅ | |
Expand Down
7 changes: 3 additions & 4 deletions Sources/SKCore/ToolchainRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import SKSupport
import Basic
import SPMUtility
import Dispatch
import POSIX
import Foundation

/// Set of known toolchains.
Expand Down Expand Up @@ -43,7 +42,7 @@ public final class ToolchainRegistry {

/// The currently selected toolchain identifier on Darwin.
public internal(set) lazy var darwinToolchainOverride: String? = {
if let id = getenv("TOOLCHAINS"), !id.isEmpty, id != "default" {
if let id = ProcessEnv.vars["TOOLCHAINS"], !id.isEmpty, id != "default" {
return id
}
return nil
Expand Down Expand Up @@ -278,7 +277,7 @@ extension ToolchainRegistry {
{
var shouldSetDefault = setDefault
for envVar in environmentVariables {
if let pathStr = getenv(envVar),
if let pathStr = ProcessEnv.vars[envVar],
let path = try? AbsolutePath(validating: pathStr),
let toolchain = try? _registerToolchain(path, fileSystem),
shouldSetDefault
Expand All @@ -301,7 +300,7 @@ extension ToolchainRegistry {

func _scanForToolchains(pathVariables: [String], _ fileSystem: FileSystem) {
pathVariables.lazy.flatMap { envVar in
getEnvSearchPaths(pathString: getenv(envVar), currentWorkingDirectory: nil)
getEnvSearchPaths(pathString: ProcessEnv.vars[envVar], currentWorkingDirectory: nil)
}
.forEach { path in
_ = try? _registerToolchain(path, fileSystem)
Expand Down
3 changes: 2 additions & 1 deletion Sources/SourceKit/SourceKitServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ public final class SourceKitServer: LanguageServer {
return nil
}

let pid = Int(ProcessInfo.processInfo.processIdentifier)
let resp = try service.sendSync(InitializeRequest(
processId: Int(getpid()),
processId: pid,
rootPath: nil,
rootURL: (workspace?.rootPath).map { URL(fileURLWithPath: $0.pathString) },
initializationOptions: InitializationOptions(),
Expand Down
6 changes: 5 additions & 1 deletion Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ final class SwiftSourceKitFramework {

init(dylib path: AbsolutePath) throws {
self.path = path
#if os(Windows)
self.dylib = try dlopen(path.pathString, mode: [])
#else
self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind])
#endif

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

Expand Down
11 changes: 5 additions & 6 deletions Tests/SKCoreTests/ToolchainRegistryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import Basic
import SPMUtility
import XCTest
import POSIX

final class ToolchainRegistryTests: XCTestCase {
func testDefaultBasic() {
Expand Down Expand Up @@ -186,8 +185,8 @@ final class ToolchainRegistryTests: XCTestCase {
XCTAssertNil(tr.default)
XCTAssert(tr.toolchains.isEmpty)

try! setenv("SOURCEKIT_PATH", value: "/bogus:\(binPath):/bogus2")
defer { try! setenv("SOURCEKIT_PATH", value: "") }
try! ProcessEnv.setVar("SOURCEKIT_PATH", value: "/bogus:\(binPath):/bogus2")
defer { try! ProcessEnv.setVar("SOURCEKIT_PATH", value: "") }

tr.scanForToolchains(fs)

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

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

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

try! setenv("TEST_SOURCEKIT_TOOLCHAIN_PATH_1", value: binPath.parentDirectory.pathString)
try! ProcessEnv.setVar("TEST_SOURCEKIT_TOOLCHAIN_PATH_1", value: binPath.parentDirectory.pathString)

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

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

try! setenv("TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH_2", value: binPath.parentDirectory.pathString)
try! ProcessEnv.setVar("TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH_2", value: binPath.parentDirectory.pathString)

tr.scanForToolchains(
environmentVariables: ["TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH_2"],
Expand Down
14 changes: 5 additions & 9 deletions Tests/SKSupportTests/SupportPerfTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@testable import SKSupport
import SKTestSupport
import Basic
import POSIX
import XCTest

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

// The debug performance is shockingly bad.
#if DEBUG
#if DEBUG || !ENABLE_PERF_TESTS
let iterations = 1_000
#else
let iterations = 10_000
Expand All @@ -49,13 +47,11 @@ final class SupportPerfTests: PerfTestCase {
}

func testLineTableSingleCharEditPerf() {

let characters: [Character] = [
"\t", "\n"
] + (32...126).map { Character(UnicodeScalar($0)) }

// The debug performance is shockingly bad.
#if DEBUG
#if DEBUG || !ENABLE_PERF_TESTS
let iterations = 1_000
let size = 1_000
#else
Expand All @@ -75,9 +71,9 @@ final class SupportPerfTests: PerfTestCase {
self.startMeasuring()

for _ in 1...iterations {
let line = (0..<(t.count-1)).randomElement(using: &lcg)!
let col = (0 ..< t[line].utf16.count).randomElement(using: &lcg)!
let len = Bool.random() ? 1 : 0
let line = (0 ..< (t.count-1)).randomElement(using: &lcg) ?? 0
let col = (0 ..< t[line].utf16.count).randomElement(using: &lcg) ?? 0
let len = t[line].isEmpty ? 0 : Bool.random() ? 1 : 0
var newText = String(characters.randomElement(using: &lcg)!)
if len == 1 && Bool.random(using: &lcg) {
newText = "" // deletion
Expand Down
19 changes: 9 additions & 10 deletions Tests/SKSupportTests/SupportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import XCTest
@testable import SKSupport
import Basic
import POSIX

final class SupportTests: XCTestCase {

Expand Down Expand Up @@ -184,8 +183,8 @@ final class SupportTests: XCTestCase {

testLogger.currentLevel = .default

try! setenv("TEST_ENV_LOGGGING_1", value: "1")
try! setenv("TEST_ENV_LOGGGING_0", value: "0")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_1", value: "1")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_0", value: "0")
// .warning
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_1")

Expand Down Expand Up @@ -221,7 +220,7 @@ final class SupportTests: XCTestCase {
])

// invalid - no change
try! setenv("TEST_ENV_LOGGGING_err", value: "")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_err", value: "")
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_err")

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

// invalid - no change
try! setenv("TEST_ENV_LOGGGING_err", value: "a3")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_err", value: "a3")
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_err")

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

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

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

// By string.
try! setenv("TEST_ENV_LOGGGING_string", value: "error")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "error")
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
XCTAssertEqual(testLogger.currentLevel, .error)
try! setenv("TEST_ENV_LOGGGING_string", value: "warning")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "warning")
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
XCTAssertEqual(testLogger.currentLevel, .warning)
try! setenv("TEST_ENV_LOGGGING_string", value: "info")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "info")
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
XCTAssertEqual(testLogger.currentLevel, .info)
try! setenv("TEST_ENV_LOGGGING_string", value: "debug")
try! ProcessEnv.setVar("TEST_ENV_LOGGGING_string", value: "debug")
testLogger.setLogLevel(environmentVariable: "TEST_ENV_LOGGGING_string")
XCTAssertEqual(testLogger.currentLevel, .debug)

Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitTests/LocalClangTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
final class LocalClangTests: XCTestCase {

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

/// Whether clangd exists in the toolchain.
var haveClangd: Bool = false
Expand Down
Loading