[CodeCompletion] Move ImportDepth to its own file

This commit is contained in:
Alex Hoppen
2022-02-23 13:05:20 +01:00
parent 48179ad01e
commit 7e043159f3
5 changed files with 131 additions and 88 deletions

View File

@@ -25,6 +25,7 @@
#include "swift/IDE/CodeCompletionResult.h"
#include "swift/IDE/CodeCompletionResultSink.h"
#include "swift/IDE/CodeCompletionString.h"
#include "swift/IDE/ImportDepth.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
@@ -78,26 +79,6 @@ ArrayRef<T> copyArray(llvm::BumpPtrAllocator &Allocator,
return llvm::makeArrayRef(Buffer, Arr.size());
}
/// A utility for calculating the import depth of a given module. Direct imports
/// have depth 1, imports of those modules have depth 2, etc.
///
/// Special modules such as Playground auxiliary sources are considered depth
/// 0.
class ImportDepth {
llvm::StringMap<uint8_t> depths;
public:
ImportDepth() = default;
ImportDepth(ASTContext &context, const FrontendOptions &frontendOptions);
Optional<uint8_t> lookup(StringRef module) {
auto I = depths.find(module);
if (I == depths.end())
return None;
return I->getValue();
}
};
struct SwiftCompletionInfo {
swift::ASTContext *swiftASTContext = nullptr;
const swift::CompilerInvocation *invocation = nullptr;

View File

@@ -0,0 +1,47 @@
//===--- ImportDepth.h ----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IDE_IMPORTDEPTH_H
#define SWIFT_IDE_IMPORTDEPTH_H
#include "swift/AST/ASTContext.h"
#include "swift/Basic/LLVM.h"
#include "swift/Frontend/FrontendOptions.h"
#include "llvm/ADT/StringMap.h"
namespace swift {
namespace ide {
/// A utility for calculating the import depth of a given module. Direct imports
/// have depth 1, imports of those modules have depth 2, etc.
///
/// Special modules such as Playground auxiliary sources are considered depth
/// 0.
class ImportDepth {
llvm::StringMap<uint8_t> depths;
public:
ImportDepth() = default;
ImportDepth(ASTContext &context, const FrontendOptions &frontendOptions);
Optional<uint8_t> lookup(StringRef module) {
auto I = depths.find(module);
if (I == depths.end())
return None;
return I->getValue();
}
};
} // end namespace ide
} // end namespace swift
#endif // SWIFT_IDE_IMPORTDEPTH_H