diff --git a/Sources/SKCore/BuildServerBuildSystem.swift b/Sources/SKCore/BuildServerBuildSystem.swift index fc35d488..a6c9bcfe 100644 --- a/Sources/SKCore/BuildServerBuildSystem.swift +++ b/Sources/SKCore/BuildServerBuildSystem.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -171,7 +171,10 @@ extension BuildServerBuildSystem: BuildSystem { public func settings(for uri: DocumentURI, _ language: Language) -> FileBuildSettings? { if let response = try? self.buildServer?.sendSync(SourceKitOptions(uri: uri)) { - return FileBuildSettings(compilerArguments: response.options, workingDirectory: response.workingDirectory) + return FileBuildSettings( + compilerArguments: response.options, + workingDirectory: response.workingDirectory, + language: language) } return nil } diff --git a/Sources/SKCore/CompilationDatabaseBuildSystem.swift b/Sources/SKCore/CompilationDatabaseBuildSystem.swift index ff481e06..4ba5d618 100644 --- a/Sources/SKCore/CompilationDatabaseBuildSystem.swift +++ b/Sources/SKCore/CompilationDatabaseBuildSystem.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -68,8 +68,8 @@ extension CompilationDatabaseBuildSystem: BuildSystem { let cmd = db[url].first else { return nil } return FileBuildSettings( compilerArguments: Array(cmd.commandLine.dropFirst()), - workingDirectory: cmd.directory - ) + workingDirectory: cmd.directory, + language: language) } public func toolchain(for: DocumentURI, _ language: Language) -> Toolchain? { return nil } diff --git a/Sources/SKCore/FallbackBuildSystem.swift b/Sources/SKCore/FallbackBuildSystem.swift index 134a3c4f..84beda83 100644 --- a/Sources/SKCore/FallbackBuildSystem.swift +++ b/Sources/SKCore/FallbackBuildSystem.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -79,7 +79,7 @@ public final class FallbackBuildSystem: BuildSystem { ] } args.append(file) - return FileBuildSettings(compilerArguments: args) + return FileBuildSettings(compilerArguments: args, language: .swift) } func settingsClang(_ file: String, _ language: Language) -> FileBuildSettings { @@ -91,6 +91,6 @@ public final class FallbackBuildSystem: BuildSystem { ] } args.append(file) - return FileBuildSettings(compilerArguments: args) + return FileBuildSettings(compilerArguments: args, language: language) } } diff --git a/Sources/SKCore/FileBuildSettings.swift b/Sources/SKCore/FileBuildSettings.swift index 1d505227..2f84e5d2 100644 --- a/Sources/SKCore/FileBuildSettings.swift +++ b/Sources/SKCore/FileBuildSettings.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +import LanguageServerProtocol + /// Build settings for a single file. /// /// Encapsulates all the settings needed to compile a single file, including the compiler arguments @@ -22,11 +24,16 @@ public struct FileBuildSettings: Equatable { /// The working directory to resolve any relative paths in `compilerArguments`. public var workingDirectory: String? = nil + /// The language of this file. + public var language: Language + public init( compilerArguments: [String], - workingDirectory: String? = nil) + workingDirectory: String? = nil, + language: Language) { self.compilerArguments = compilerArguments self.workingDirectory = workingDirectory + self.language = language } } diff --git a/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift b/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift index f3cdab9a..6a5d77e5 100644 --- a/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift +++ b/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -294,7 +294,7 @@ extension SwiftPMWorkspace { func impl(_ path: AbsolutePath) -> FileBuildSettings? { for package in packageGraph.packages where path == package.manifest.path { let compilerArgs = workspace.interpreterFlags(for: package.path) + [path.pathString] - return FileBuildSettings(compilerArguments: compilerArgs) + return FileBuildSettings(compilerArguments: compilerArgs, language: .swift) } return nil } @@ -354,7 +354,8 @@ extension SwiftPMWorkspace { return FileBuildSettings( compilerArguments: args, - workingDirectory: workspacePath.pathString) + workingDirectory: workspacePath.pathString, + language: .swift) } /// Retrieve settings for the given C-family language file, which is part of a known target build @@ -416,7 +417,8 @@ extension SwiftPMWorkspace { return FileBuildSettings( compilerArguments: args, - workingDirectory: workspacePath.pathString) + workingDirectory: workspacePath.pathString, + language: language) } } diff --git a/Tests/SourceKitTests/BuildSystemTests.swift b/Tests/SourceKitTests/BuildSystemTests.swift index 96d2fb96..27efd8e1 100644 --- a/Tests/SourceKitTests/BuildSystemTests.swift +++ b/Tests/SourceKitTests/BuildSystemTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -132,7 +132,8 @@ final class BuildSystemTests: XCTestCase { } """ - buildSystem.buildSettingsByFile[DocumentURI(url)] = FileBuildSettings(compilerArguments: args) + buildSystem.buildSettingsByFile[DocumentURI(url)] = + FileBuildSettings(compilerArguments: args, language: .objective_c) sk.allowUnexpectedNotification = false @@ -148,7 +149,8 @@ final class BuildSystemTests: XCTestCase { // Modify the build settings and inform the delegate. // This should trigger a new publish diagnostics and we should no longer have errors. - buildSystem.buildSettingsByFile[DocumentURI(url)] = FileBuildSettings(compilerArguments: args + ["-DFOO"]) + buildSystem.buildSettingsByFile[DocumentURI(url)] = + FileBuildSettings(compilerArguments: args + ["-DFOO"], language: .objective_c) testServer.server?.fileBuildSettingsChanged([DocumentURI(url)]) let expectation = XCTestExpectation(description: "refresh") @@ -168,7 +170,8 @@ final class BuildSystemTests: XCTestCase { let url = URL(fileURLWithPath: "/a.swift") let args = FallbackBuildSystem().settings(for: DocumentURI(url), .swift)!.compilerArguments - buildSystem.buildSettingsByFile[DocumentURI(url)] = FileBuildSettings(compilerArguments: args) + buildSystem.buildSettingsByFile[DocumentURI(url)] = + FileBuildSettings(compilerArguments: args, language: .swift) let text = """ #if FOO @@ -196,7 +199,8 @@ final class BuildSystemTests: XCTestCase { // Modify the build settings and inform the delegate. // This should trigger a new publish diagnostics and we should no longer have errors. - buildSystem.buildSettingsByFile[DocumentURI(url)] = FileBuildSettings(compilerArguments: args + ["-DFOO"]) + buildSystem.buildSettingsByFile[DocumentURI(url)] = + FileBuildSettings(compilerArguments: args + ["-DFOO"], language: .swift) let expectation = XCTestExpectation(description: "refresh") expectation.expectedFulfillmentCount = 2