Merge pull request #100 from gmittert/SourceKitModuleWindows

Fixup SourceKit module on Windows
This commit is contained in:
Argyrios Kyrtzidis
2019-04-18 16:14:57 -07:00
committed by GitHub
2 changed files with 11 additions and 2 deletions

View File

@@ -169,8 +169,13 @@ public final class SourceKitServer: LanguageServer {
return nil
}
#if os(Windows)
let pid: Int = unsafeBitCast(GetCurrentProcess(), to: Int.self)
#else
let pid: Int = Int(getpid())
#endif
let resp = try service.sendSync(InitializeRequest(
processId: Int(getpid()),
processId: pid,
rootPath: nil,
rootURL: (workspace?.rootPath).map { URL(fileURLWithPath: $0.pathString) },
initializationOptions: InitializationOptions(),

View File

@@ -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 {
@@ -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()