Files
sourcekit-lsp/Sources/SKCore/BuildSystemList.swift
Alex Hoppen 5c839f8640 Add support for non-URL URIs
According to the LSP specification, arbitrary URIs can be used as
document identifiers. Instead of internally assuming that all URIs are
URLs, use a DocumentURI enum to represent URIs. These can either be file
URLs or other URIs whose value as treated as an opaque string.
2019-11-20 09:41:48 -08:00

78 lines
2.9 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 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
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import TSCBasic
import BuildServerProtocol
import LanguageServerProtocol
/// Provides build settings from a list of build systems in priority order.
public final class BuildSystemList {
/// Delegate to handle any build system events.
public var delegate: BuildSystemDelegate? {
get { return providers.first?.delegate }
set { providers.first?.delegate = newValue }
}
/// The build systems to try (in order).
public var providers: [BuildSystem] = [
FallbackBuildSystem()
]
public init() {}
}
extension BuildSystemList: BuildSystem {
public var indexStorePath: AbsolutePath? { return providers.first?.indexStorePath }
public var indexDatabasePath: AbsolutePath? { return providers.first?.indexDatabasePath }
public func settings(for uri: DocumentURI, _ language: Language) -> FileBuildSettings? {
for provider in providers {
if let settings = provider.settings(for: uri, language) {
return settings
}
}
return nil
}
/// Register the given file for build-system level change notifications, such as command
/// line flag changes, dependency changes, etc.
public func registerForChangeNotifications(for uri: DocumentURI) {
// Only register with the primary build system, since we only use its delegate.
providers.first?.registerForChangeNotifications(for: uri)
}
/// Unregister the given file for build-system level change notifications, such as command
/// line flag changes, dependency changes, etc.
public func unregisterForChangeNotifications(for uri: DocumentURI) {
// Only unregister with the primary build system, since we only use its delegate.
providers.first?.unregisterForChangeNotifications(for: uri)
}
public func toolchain(for uri: DocumentURI, _ language: Language) -> Toolchain? {
return providers.first?.toolchain(for: uri, language)
}
public func buildTargets(reply: @escaping (LSPResult<[BuildTarget]>) -> Void) {
providers.first?.buildTargets(reply: reply)
}
public func buildTargetSources(targets: [BuildTargetIdentifier], reply: @escaping (LSPResult<[SourcesItem]>) -> Void) {
providers.first?.buildTargetSources(targets: targets, reply: reply)
}
public func buildTargetOutputPaths(targets: [BuildTargetIdentifier], reply: @escaping (LSPResult<[OutputsItem]>) -> Void) {
providers.first?.buildTargetOutputPaths(targets: targets, reply: reply)
}
}