File tree Expand file tree Collapse file tree 4 files changed +26
-12
lines changed Expand file tree Collapse file tree 4 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -58,13 +58,10 @@ public protocol CompilationDatabase {
58
58
/// Loads the compilation database located in `directory`, if any.
59
59
public func tryLoadCompilationDatabase(
60
60
directory: AbsolutePath ,
61
- fileSystem: FileSystem = localFileSystem
61
+ _ fileSystem: FileSystem = localFileSystem
62
62
) -> CompilationDatabase ? {
63
-
64
- return orLog ( " could not open compilation database for \( directory. asString) " , level: . error) {
65
- try JSONCompilationDatabase ( directory: directory, fileSystem: fileSystem)
66
- }
67
63
// TODO: Support fixed compilation database (compile_flags.txt).
64
+ return try ? JSONCompilationDatabase ( directory: directory, fileSystem)
68
65
}
69
66
70
67
/// The JSON clang-compatible compilation database.
@@ -128,7 +125,7 @@ extension JSONCompilationDatabase: Codable {
128
125
}
129
126
130
127
extension JSONCompilationDatabase {
131
- public init ( directory: AbsolutePath , fileSystem: FileSystem = localFileSystem) throws {
128
+ public init ( directory: AbsolutePath , _ fileSystem: FileSystem = localFileSystem) throws {
132
129
let path = directory. appending ( component: " compile_commands.json " )
133
130
let bytes = try fileSystem. readFileContents ( path)
134
131
try bytes. withUnsafeData { data in
Original file line number Diff line number Diff line change 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ import SKSupport
13
14
import Basic
14
15
import LanguageServerProtocol
15
16
@@ -27,7 +28,7 @@ public final class CompilationDatabaseBuildSystem: BuildSettingsProvider {
27
28
public init ( projectRoot: AbsolutePath ? = nil , fileSystem: FileSystem = localFileSystem) {
28
29
self . fileSystem = fileSystem
29
30
if let path = projectRoot {
30
- self . compdb = tryLoadCompilationDatabase ( directory: path, fileSystem: fileSystem )
31
+ self . compdb = tryLoadCompilationDatabase ( directory: path, fileSystem)
31
32
}
32
33
}
33
34
@@ -53,12 +54,17 @@ public final class CompilationDatabaseBuildSystem: BuildSettingsProvider {
53
54
var dir = path
54
55
while !dir. isRoot {
55
56
dir = dir. parentDirectory
56
- if let db = tryLoadCompilationDatabase ( directory: dir, fileSystem: fileSystem ) {
57
+ if let db = tryLoadCompilationDatabase ( directory: dir, fileSystem) {
57
58
compdb = db
58
59
break
59
60
}
60
61
}
61
62
}
63
+
64
+ if compdb == nil {
65
+ log ( " could not open compilation database for \( path. asString) " , level: . warning)
66
+ }
67
+
62
68
return compdb
63
69
}
64
70
}
Original file line number Diff line number Diff line change @@ -129,8 +129,9 @@ public final class SwiftPMWorkspace {
129
129
130
130
// FIXME: the rest of this should be done asynchronously.
131
131
132
- // FIXME: connect to logging?
133
- let diags = DiagnosticsEngine ( )
132
+ let diags = DiagnosticsEngine ( handlers: [ { diag in
133
+ log ( diag. localizedDescription, level: diag. behavior. asLogLevel)
134
+ } ] )
134
135
135
136
self . packageGraph = self . workspace. loadPackageGraph ( root: PackageGraphRootInput ( packages: [ packageRoot] ) , diagnostics: diags)
136
137
@@ -399,3 +400,13 @@ public final class BuildSettingProviderWorkspaceDelegate: WorkspaceDelegate {
399
400
public func managedDependenciesDidUpdate( _ dependencies: AnySequence < ManagedDependency > ) {
400
401
}
401
402
}
403
+
404
+ extension Basic . Diagnostic . Behavior {
405
+ var asLogLevel : LogLevel {
406
+ switch self {
407
+ case . error: return . error
408
+ case . warning: return . warning
409
+ default : return . info
410
+ }
411
+ }
412
+ }
Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ final class CompilationDatabaseTests: XCTestCase {
169
169
func testJSONCompilationDatabaseFromDirectory( ) {
170
170
let fs = InMemoryFileSystem ( )
171
171
try ! fs. createDirectory ( AbsolutePath ( " /a " ) )
172
- XCTAssertNil ( tryLoadCompilationDatabase ( directory: AbsolutePath ( " /a " ) , fileSystem : fs) )
172
+ XCTAssertNil ( tryLoadCompilationDatabase ( directory: AbsolutePath ( " /a " ) , fs) )
173
173
174
174
try ! fs. writeFileContents ( AbsolutePath ( " /a/compile_commands.json " ) , bytes: """
175
175
[
@@ -181,7 +181,7 @@ final class CompilationDatabaseTests: XCTestCase {
181
181
]
182
182
""" )
183
183
184
- XCTAssertNotNil ( tryLoadCompilationDatabase ( directory: AbsolutePath ( " /a " ) , fileSystem : fs) )
184
+ XCTAssertNotNil ( tryLoadCompilationDatabase ( directory: AbsolutePath ( " /a " ) , fs) )
185
185
}
186
186
187
187
func testCompilationDatabaseBuildSystem( ) {
You can’t perform that action at this time.
0 commit comments