Revert "[CodeCompletion] Provide known module source file information"

This effectively reverts commit f8751d466e.
This commit is contained in:
Rintaro Ishizaki
2021-09-21 14:40:16 -07:00
parent 9fb54e95ae
commit 1656eed597
14 changed files with 20 additions and 338 deletions

View File

@@ -686,7 +686,6 @@ public:
private: private:
CodeCompletionString *CompletionString; CodeCompletionString *CompletionString;
StringRef ModuleName; StringRef ModuleName;
StringRef SourceFilePath;
StringRef BriefDocComment; StringRef BriefDocComment;
ArrayRef<StringRef> AssociatedUSRs; ArrayRef<StringRef> AssociatedUSRs;
unsigned TypeDistance : 3; unsigned TypeDistance : 3;
@@ -797,7 +796,7 @@ public:
CodeCompletionFlair Flair, unsigned NumBytesToErase, CodeCompletionFlair Flair, unsigned NumBytesToErase,
CodeCompletionString *CompletionString, CodeCompletionString *CompletionString,
CodeCompletionDeclKind DeclKind, bool IsSystem, CodeCompletionDeclKind DeclKind, bool IsSystem,
StringRef ModuleName, StringRef SourceFilePath, StringRef ModuleName,
CodeCompletionResult::NotRecommendedReason NotRecReason, CodeCompletionResult::NotRecommendedReason NotRecReason,
CodeCompletionDiagnosticSeverity diagSeverity, CodeCompletionDiagnosticSeverity diagSeverity,
StringRef DiagnosticMessage, StringRef BriefDocComment, StringRef DiagnosticMessage, StringRef BriefDocComment,
@@ -806,10 +805,10 @@ public:
CodeCompletionOperatorKind KnownOperatorKind) CodeCompletionOperatorKind KnownOperatorKind)
: Kind(ResultKind::Declaration), : Kind(ResultKind::Declaration),
KnownOperatorKind(unsigned(KnownOperatorKind)), KnownOperatorKind(unsigned(KnownOperatorKind)),
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())), SemanticContext(unsigned(SemanticContext)),
NotRecommended(unsigned(NotRecReason)), IsSystem(IsSystem), Flair(unsigned(Flair.toRaw())), NotRecommended(unsigned(NotRecReason)),
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString), IsSystem(IsSystem), NumBytesToErase(NumBytesToErase),
ModuleName(ModuleName), SourceFilePath(SourceFilePath), CompletionString(CompletionString), ModuleName(ModuleName),
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs), BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
TypeDistance(TypeDistance), DiagnosticSeverity(unsigned(diagSeverity)), TypeDistance(TypeDistance), DiagnosticSeverity(unsigned(diagSeverity)),
DiagnosticMessage(DiagnosticMessage) { DiagnosticMessage(DiagnosticMessage) {
@@ -907,10 +906,6 @@ public:
return AssociatedUSRs; return AssociatedUSRs;
} }
void setSourceFilePath(StringRef value) {
SourceFilePath = value;
}
void setDiagnostics(CodeCompletionDiagnosticSeverity severity, StringRef message) { void setDiagnostics(CodeCompletionDiagnosticSeverity severity, StringRef message) {
DiagnosticSeverity = static_cast<unsigned>(severity); DiagnosticSeverity = static_cast<unsigned>(severity);
DiagnosticMessage = message; DiagnosticMessage = message;
@@ -924,12 +919,6 @@ public:
return DiagnosticMessage; return DiagnosticMessage;
} }
/// Returns the source file path where the associated decl was declared.
/// Returns an empty string if the information is not available.
StringRef getSourceFilePath() const {
return SourceFilePath;
}
/// Print a debug representation of the code completion result to \p OS. /// Print a debug representation of the code completion result to \p OS.
void printPrefix(raw_ostream &OS) const; void printPrefix(raw_ostream &OS) const;
SWIFT_DEBUG_DUMP; SWIFT_DEBUG_DUMP;
@@ -942,15 +931,6 @@ public:
static bool getDeclIsSystem(const Decl *D); static bool getDeclIsSystem(const Decl *D);
}; };
/// A pair of a file path and its up-to-date-ness.
struct SourceFileAndUpToDate {
StringRef FilePath;
bool IsUpToDate;
SourceFileAndUpToDate(StringRef FilePath, bool IsUpToDate)
: FilePath(FilePath), IsUpToDate(IsUpToDate) {}
};
struct CodeCompletionResultSink { struct CodeCompletionResultSink {
using AllocatorPtr = std::shared_ptr<llvm::BumpPtrAllocator>; using AllocatorPtr = std::shared_ptr<llvm::BumpPtrAllocator>;
@@ -963,13 +943,11 @@ struct CodeCompletionResultSink {
/// Whether to annotate the results with XML. /// Whether to annotate the results with XML.
bool annotateResult = false; bool annotateResult = false;
bool requiresSourceFileInfo = false;
/// Whether to emit object literals if desired. /// Whether to emit object literals if desired.
bool includeObjectLiterals = true; bool includeObjectLiterals = true;
std::vector<CodeCompletionResult *> Results; std::vector<CodeCompletionResult *> Results;
std::vector<SourceFileAndUpToDate> SourceFiles;
/// A single-element cache for module names stored in Allocator, keyed by a /// A single-element cache for module names stored in Allocator, keyed by a
/// clang::Module * or swift::ModuleDecl *. /// clang::Module * or swift::ModuleDecl *.
@@ -1040,9 +1018,6 @@ public:
void setAnnotateResult(bool flag) { CurrentResults.annotateResult = flag; } void setAnnotateResult(bool flag) { CurrentResults.annotateResult = flag; }
bool getAnnotateResult() const { return CurrentResults.annotateResult; } bool getAnnotateResult() const { return CurrentResults.annotateResult; }
void setRequiresSourceFileInfo(bool flag) { CurrentResults.requiresSourceFileInfo = flag; }
bool requiresSourceFileInfo() const { return CurrentResults.requiresSourceFileInfo; }
void setIncludeObjectLiterals(bool flag) { void setIncludeObjectLiterals(bool flag) {
CurrentResults.includeObjectLiterals = flag; CurrentResults.includeObjectLiterals = flag;
} }
@@ -1098,7 +1073,6 @@ class PrintingCodeCompletionConsumer
bool IncludeComments; bool IncludeComments;
bool IncludeSourceText; bool IncludeSourceText;
bool PrintAnnotatedDescription; bool PrintAnnotatedDescription;
bool RequiresSourceFileInfo = false;
public: public:
PrintingCodeCompletionConsumer(llvm::raw_ostream &OS, PrintingCodeCompletionConsumer(llvm::raw_ostream &OS,

View File

@@ -1,39 +0,0 @@
//===--- ModuleSourceFileInfo.h ---------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 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_MODULESOURCEFILEINFO_H
#define SWIFT_IDE_MODULESOURCEFILEINFO_H
#include "swift/AST/RawComment.h"
#include "swift/Basic/BasicSourceInfo.h"
#include "swift/Basic/LLVM.h"
namespace swift {
class ASTContext;
class Decl;
namespace ide {
/// Get the source file path where \p D is declared. Returns an empty string
/// if the information is not available.
StringRef getSourceFilePathForDecl(const Decl *D);
/// Check if the source file of \p info is up-to-date.
/// * \c true if the mtime and the size are the same.
/// * \c true if the interface has hasn't changed.
/// * \c false otherwise.
bool isSourceFileUpToDate(const BasicSourceFileInfo &info, ASTContext &Ctx);
} // namespace ide
} // namespace swift
#endif // SWIFT_IDE_MODULESOURCEFILEINFO_H

View File

@@ -12,7 +12,6 @@ add_swift_host_library(swiftIDE STATIC
FuzzyStringMatcher.cpp FuzzyStringMatcher.cpp
Refactoring.cpp Refactoring.cpp
ModuleInterfacePrinting.cpp ModuleInterfacePrinting.cpp
ModuleSourceFileInfo.cpp
REPLCodeCompletion.cpp REPLCodeCompletion.cpp
SwiftSourceDocInfo.cpp SwiftSourceDocInfo.cpp
SyntaxModel.cpp SyntaxModel.cpp

View File

@@ -34,7 +34,6 @@
#include "swift/Frontend/FrontendOptions.h" #include "swift/Frontend/FrontendOptions.h"
#include "swift/IDE/CodeCompletionCache.h" #include "swift/IDE/CodeCompletionCache.h"
#include "swift/IDE/CodeCompletionResultPrinter.h" #include "swift/IDE/CodeCompletionResultPrinter.h"
#include "swift/IDE/ModuleSourceFileInfo.h"
#include "swift/IDE/Utils.h" #include "swift/IDE/Utils.h"
#include "swift/Parse/CodeCompletionCallbacks.h" #include "swift/Parse/CodeCompletionCallbacks.h"
#include "swift/Sema/IDETypeChecking.h" #include "swift/Sema/IDETypeChecking.h"
@@ -636,9 +635,9 @@ CodeCompletionResult::withFlair(CodeCompletionFlair newFlair,
return new (*Sink.Allocator) CodeCompletionResult( return new (*Sink.Allocator) CodeCompletionResult(
getSemanticContext(), newFlair, getNumBytesToErase(), getSemanticContext(), newFlair, getNumBytesToErase(),
getCompletionString(), getAssociatedDeclKind(), isSystem(), getCompletionString(), getAssociatedDeclKind(), isSystem(),
getModuleName(), getSourceFilePath(), getNotRecommendedReason(), getModuleName(), getNotRecommendedReason(), getDiagnosticSeverity(),
getDiagnosticSeverity(), getDiagnosticMessage(), getDiagnosticMessage(), getBriefDocComment(), getAssociatedUSRs(),
getBriefDocComment(), getAssociatedUSRs(), getExpectedTypeRelation(), getExpectedTypeRelation(),
isOperator() ? getOperatorKind() : CodeCompletionOperatorKind::None); isOperator() ? getOperatorKind() : CodeCompletionOperatorKind::None);
} else { } else {
return new (*Sink.Allocator) CodeCompletionResult( return new (*Sink.Allocator) CodeCompletionResult(
@@ -1303,8 +1302,6 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
ModuleName, NotRecReason, copyString(*Sink.Allocator, BriefDocComment), ModuleName, NotRecReason, copyString(*Sink.Allocator, BriefDocComment),
copyAssociatedUSRs(*Sink.Allocator, AssociatedDecl), copyAssociatedUSRs(*Sink.Allocator, AssociatedDecl),
ExpectedTypeRelation); ExpectedTypeRelation);
if (!result->isSystem())
result->setSourceFilePath(getSourceFilePathForDecl(AssociatedDecl));
if (NotRecReason != NotRecommendedReason::None) { if (NotRecReason != NotRecommendedReason::None) {
// FIXME: We should generate the message lazily. // FIXME: We should generate the message lazily.
if (const auto *VD = dyn_cast<ValueDecl>(AssociatedDecl)) { if (const auto *VD = dyn_cast<ValueDecl>(AssociatedDecl)) {
@@ -6575,37 +6572,6 @@ static void postProcessResults(MutableArrayRef<CodeCompletionResult *> results,
} }
} }
static void copyAllKnownSourceFileInfo(
ASTContext &Ctx, CodeCompletionResultSink &Sink) {
assert(Sink.SourceFiles.empty());
SmallVector<ModuleDecl *, 8> loadedModules;
loadedModules.reserve(Ctx.getNumLoadedModules());
for (auto &entry : Ctx.getLoadedModules())
loadedModules.push_back(entry.second);
auto &result = Sink.SourceFiles;
for (auto *M : loadedModules) {
// We don't need to check system modules.
if (M->isSystemModule())
continue;
M->collectBasicSourceFileInfo([&](const BasicSourceFileInfo &info) {
if (info.getFilePath().empty())
return;
bool isUpToDate = false;
if (info.isFromSourceFile()) {
// 'SourceFile' is always "up-to-date" because we've just loaded.
isUpToDate = true;
} else {
isUpToDate = isSourceFileUpToDate(info, Ctx);
}
result.emplace_back(copyString(*Sink.Allocator, info.getFilePath()), isUpToDate);
});
}
}
static void deliverCompletionResults(CodeCompletionContext &CompletionContext, static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
CompletionLookup &Lookup, CompletionLookup &Lookup,
DeclContext *DC, DeclContext *DC,
@@ -6725,10 +6691,6 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
CompletionContext.CodeCompletionKind, DC, CompletionContext.CodeCompletionKind, DC,
/*Sink=*/nullptr); /*Sink=*/nullptr);
if (CompletionContext.requiresSourceFileInfo())
copyAllKnownSourceFileInfo(SF.getASTContext(),
CompletionContext.getResultSink());
Consumer.handleResultsAndModules(CompletionContext, RequestedModules, DC); Consumer.handleResultsAndModules(CompletionContext, RequestedModules, DC);
} }
@@ -7447,16 +7409,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
void PrintingCodeCompletionConsumer::handleResults( void PrintingCodeCompletionConsumer::handleResults(
CodeCompletionContext &context) { CodeCompletionContext &context) {
if (context.requiresSourceFileInfo() &&
!context.getResultSink().SourceFiles.empty()) {
OS << "Known module source files\n";
for (auto &entry : context.getResultSink().SourceFiles) {
OS << (entry.IsUpToDate ? " + " : " - ");
OS << entry.FilePath;
OS << "\n";
}
this->RequiresSourceFileInfo = true;
}
auto results = context.takeResults(); auto results = context.takeResults();
handleResults(results); handleResults(results);
} }
@@ -7503,13 +7455,6 @@ void PrintingCodeCompletionConsumer::handleResults(
OS << "; comment=" << comment; OS << "; comment=" << comment;
} }
if (RequiresSourceFileInfo) {
StringRef sourceFilePath = Result->getSourceFilePath();
if (!sourceFilePath.empty()) {
OS << "; source=" << sourceFilePath;
}
}
if (Result->getDiagnosticSeverity() != if (Result->getDiagnosticSeverity() !=
CodeCompletionDiagnosticSeverity::None) { CodeCompletionDiagnosticSeverity::None) {
OS << "; diagnostics=" << comment; OS << "; diagnostics=" << comment;

View File

@@ -102,7 +102,7 @@ CodeCompletionCache::~CodeCompletionCache() {}
/// ///
/// This should be incremented any time we commit a change to the format of the /// This should be incremented any time we commit a change to the format of the
/// cached results. This isn't expected to change very often. /// cached results. This isn't expected to change very often.
static constexpr uint32_t onDiskCompletionCacheVersion = 2; static constexpr uint32_t onDiskCompletionCacheVersion = 3; // Removed "source file path".
/// Deserializes CodeCompletionResults from \p in and stores them in \p V. /// Deserializes CodeCompletionResults from \p in and stores them in \p V.
/// \see writeCacheModule. /// \see writeCacheModule.
@@ -209,7 +209,6 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
auto numBytesToErase = static_cast<unsigned>(*cursor++); auto numBytesToErase = static_cast<unsigned>(*cursor++);
auto chunkIndex = read32le(cursor); auto chunkIndex = read32le(cursor);
auto moduleIndex = read32le(cursor); auto moduleIndex = read32le(cursor);
auto sourceFilePathIndex = read32le(cursor);
auto briefDocIndex = read32le(cursor); auto briefDocIndex = read32le(cursor);
auto diagMessageIndex = read32le(cursor); auto diagMessageIndex = read32le(cursor);
@@ -221,7 +220,6 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
CodeCompletionString *string = getCompletionString(chunkIndex); CodeCompletionString *string = getCompletionString(chunkIndex);
auto moduleName = getString(moduleIndex); auto moduleName = getString(moduleIndex);
auto sourceFilePath = getString(sourceFilePathIndex);
auto briefDocComment = getString(briefDocIndex); auto briefDocComment = getString(briefDocIndex);
auto diagMessage = getString(diagMessageIndex); auto diagMessage = getString(diagMessageIndex);
@@ -229,7 +227,7 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
if (kind == CodeCompletionResult::Declaration) { if (kind == CodeCompletionResult::Declaration) {
result = new (*V.Sink.Allocator) CodeCompletionResult( result = new (*V.Sink.Allocator) CodeCompletionResult(
context, CodeCompletionFlair(), numBytesToErase, string, context, CodeCompletionFlair(), numBytesToErase, string,
declKind, isSystem, moduleName, sourceFilePath, notRecommended, declKind, isSystem, moduleName, notRecommended,
diagSeverity, diagMessage, briefDocComment, diagSeverity, diagMessage, briefDocComment,
copyArray(*V.Sink.Allocator, ArrayRef<StringRef>(assocUSRs)), copyArray(*V.Sink.Allocator, ArrayRef<StringRef>(assocUSRs)),
CodeCompletionResult::Unknown, opKind); CodeCompletionResult::Unknown, opKind);
@@ -369,7 +367,6 @@ static void writeCachedModule(llvm::raw_ostream &out,
LE.write( LE.write(
static_cast<uint32_t>(addCompletionString(R->getCompletionString()))); static_cast<uint32_t>(addCompletionString(R->getCompletionString())));
LE.write(addString(R->getModuleName())); // index into strings LE.write(addString(R->getModuleName())); // index into strings
LE.write(addString(R->getSourceFilePath())); // index into strings
LE.write(addString(R->getBriefDocComment())); // index into strings LE.write(addString(R->getBriefDocComment())); // index into strings
LE.write(addString(R->getDiagnosticMessage())); // index into strings LE.write(addString(R->getDiagnosticMessage())); // index into strings

View File

@@ -613,6 +613,10 @@ bool swift::ide::CompletionInstance::performOperation(
std::string &Error, DiagnosticConsumer *DiagC, std::string &Error, DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &, bool)> Callback) { llvm::function_ref<void(CompilerInstance &, bool)> Callback) {
// Always disable source location resolutions from .swiftsourceinfo file
// because they're somewhat heavy operations and aren't needed for completion.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
// Disable to build syntax tree because code-completion skips some portion of // Disable to build syntax tree because code-completion skips some portion of
// source text. That breaks an invariant of syntax tree building. // source text. That breaks an invariant of syntax tree building.
Invocation.getLangOptions().BuildSyntaxTree = false; Invocation.getLangOptions().BuildSyntaxTree = false;

View File

@@ -1,90 +0,0 @@
//===--- ModuleSourceFileInfo.cpp -------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 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
//
//===----------------------------------------------------------------------===//
#include "swift/IDE/ModuleSourceFileInfo.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/Module.h"
#include "swift/AST/SourceFile.h"
#include "swift/Basic/SourceManager.h"
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
#include "swift/Subsystems.h"
using namespace swift;
using namespace swift::ide;
StringRef swift::ide::getSourceFilePathForDecl(const Decl *D) {
auto *DC = D->getDeclContext();
FileUnit *fileUnit = dyn_cast<FileUnit>(DC->getModuleScopeContext());
if (!fileUnit)
return "";
if (auto *SF = dyn_cast<SourceFile>(fileUnit))
return SF->getFilename();
if (auto loc = fileUnit->getExternalRawLocsForDecl(D))
return loc->SourceFilePath;
return "";
}
bool swift::ide::isSourceFileUpToDate(const BasicSourceFileInfo &info,
ASTContext &Ctx) {
auto &SM = Ctx.SourceMgr;
auto stat = SM.getFileSystem()->status(info.getFilePath());
// If missing, it's not up-to-date.
if (!stat)
return false;
// Assume up-to-date if the modification time and the size are the same.
if (stat->getLastModificationTime() == info.getLastModified() &&
stat->getSize() == info.getFileSize())
return true;
// If the interface hash is unknown, we can't compare it.
if (info.getInterfaceHashIncludingTypeMembers() == Fingerprint::ZERO())
return false;
// Check if the interface hash has changed.
auto buffer = SM.getFileSystem()->getBufferForFile(info.getFilePath());
// If failed to open, it's not up-to-date.
if (!buffer)
return false;
SourceManager tmpSM;
auto tmpBufferID = tmpSM.addNewSourceBuffer(std::move(*buffer));
// FIXME: Using the current options is not correct because the module might be
// compiled with different options. We could use serialized search paths etc.
LangOptions langOpts = Ctx.LangOpts;
TypeCheckerOptions typechkOpts = Ctx.TypeCheckerOpts;
SearchPathOptions searchPathOpts = Ctx.SearchPathOpts;
DiagnosticEngine tmpDiags(tmpSM);
ClangImporterOptions clangOpts;
symbolgraphgen::SymbolGraphOptions symbolOpts;
std::unique_ptr<ASTContext> tmpCtx(
ASTContext::get(langOpts, typechkOpts, searchPathOpts, clangOpts,
symbolOpts, tmpSM, tmpDiags));
registerParseRequestFunctions(tmpCtx->evaluator);
registerIDERequestFunctions(tmpCtx->evaluator);
registerTypeCheckerRequestFunctions(tmpCtx->evaluator);
registerSILGenRequestFunctions(tmpCtx->evaluator);
ModuleDecl *tmpM = ModuleDecl::create(Identifier(), *tmpCtx);
SourceFile::ParsingOptions parseOpts;
parseOpts |= SourceFile::ParsingFlags::EnableInterfaceHash;
SourceFile *tmpSF = new (*tmpCtx)
SourceFile(*tmpM, SourceFileKind::Library, tmpBufferID, parseOpts);
auto fingerprint = tmpSF->getInterfaceHashIncludingTypeMembers();
return fingerprint == info.getInterfaceHashIncludingTypeMembers();
}

View File

@@ -1,11 +0,0 @@
/// Added comment.
public struct MyStruct {
public var propertyInType: Int { 1 }
/// Added comment.
public func funcInType(x: Int) {
// Added function body.
print("DEBUG")
}
}

View File

@@ -1,4 +0,0 @@
public struct MyStruct {
public var propertyInType: Int { 1 }
public func funcInType(x: Int) {}
}

View File

@@ -1,6 +0,0 @@
public extension MyStruct {
var propertyInExtension: String { "" }
func funcInExtension() -> String { "" }
func addedMethod() -> MyStruct { return self }
}

View File

@@ -1,4 +0,0 @@
public extension MyStruct {
var propertyInExtension: String { "" }
func funcInExtension() -> String { "" }
}

View File

@@ -1,71 +0,0 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/Sources)
// RUN: %empty-directory(%t/Modules)
// RUN: cp %S/Inputs/complete_sourcefileinfo/MyModule1.swift %t/Sources/MyModule1.swift
// RUN: cp %S/Inputs/complete_sourcefileinfo/MyModule2.swift %t/Sources/MyModule2.swift
// RUN: %target-swiftc_driver -emit-module -o %t/Modules/MyModule.swiftmodule %t/Sources/MyModule1.swift %t/Sources/MyModule2.swift
// RUN: test -f %t/Modules/MyModule.swiftsourceinfo
// RUN: %empty-directory(%/result)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t/result -code-completion-sourcefileinfo -I %t/Modules
// RUN: cp %S/Inputs/complete_sourcefileinfo/MyModule1-modified.swift %t/Sources/MyModule1.swift
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t/result -code-completion-sourcefileinfo -I %t/Modules
// RUN: cp %S/Inputs/complete_sourcefileinfo/MyModule2-modified.swift %t/Sources/MyModule2.swift
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-sourcefileinfo -I %t/Modules -code-completion-token=GLOBAL | %FileCheck %s --check-prefix GLOBAL_MOD
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-sourcefileinfo -I %t/Modules -code-completion-token=MEMBER | %FileCheck %s --check-prefix MEMBER_MOD
import MyModule
var globalValue: Int = 1
func test() {
#^GLOBAL^#
}
// GLOBAL-LABEL: Known module source files
// GLOBAL-DAG: + {{.*}}{{[/\\]}}test{{[/\\]}}IDE{{[/\\]}}complete_sourcefileinfo.swift
// GLOBAL-DAG: + {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// GLOBAL-DAG: + {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// GLOBAL-LABEL: Begin completions
// GLOBAL-DAG: Decl[Struct]/OtherModule[Swift]/IsSystem: String[#String#]; name=String{{$}}
// GLOBAL-DAG: Decl[Struct]/OtherModule[MyModule]: MyStruct[#MyStruct#]; name=MyStruct; source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// GLOBAL-DAG: Decl[GlobalVar]/CurrModule: globalValue[#Int#]; name=globalValue; source={{.*}}{{[/\\]}}test{{[/\\]}}IDE{{[/\\]}}complete_sourcefileinfo.swift
// GLOBAL_MOD-LABEL: Known module source files
// GLOBAL_MOD-DAG: + {{.*}}{{[/\\]}}test{{[/\\]}}IDE{{[/\\]}}complete_sourcefileinfo.swift
// GLOBAL_MOD-DAG: + {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// GLOBAL_MOD-DAG: - {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// GLOBAL_MOD-LABEL: Begin completions
// GLOBAL_MOD-DAG: Decl[Struct]/OtherModule[Swift]/IsSystem: String[#String#]; name=String{{$}}
// GLOBAL_MOD-DAG: Decl[Struct]/OtherModule[MyModule]: MyStruct[#MyStruct#]; name=MyStruct; source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// GLOBAL_MOD-DAG: Decl[GlobalVar]/CurrModule: globalValue[#Int#]; name=globalValue; source={{.*}}{{[/\\]}}test{{[/\\]}}IDE{{[/\\]}}complete_sourcefileinfo.swift
func test(val: MyStruct) {
val.#^MEMBER^#
}
// MEMBER-LABEL: Known module source files
// MEMBER-DAG: + {{.*}}{{[/\\]}}test{{[/\\]}}IDE{{[/\\]}}complete_sourcefileinfo.swift
// MEMBER-DAG: + {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// MEMBER-DAG: + {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// MEMBER-LABEL: Begin completions, 5 items
// MEMBER-DAG: Keyword[self]/CurrNominal: self[#MyStruct#]; name=self{{$}}
// MEMBER-DAG: Decl[InstanceVar]/CurrNominal: propertyInType[#Int#]; name=propertyInType; source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: funcInType({#x: Int#})[#Void#]; name=funcInType(x:); source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// MEMBER-DAG: Decl[InstanceVar]/CurrNominal: propertyInExtension[#String#]; name=propertyInExtension; source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: funcInExtension()[#String#]; name=funcInExtension(); source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// MEMBER: End completions
// MEMBER_MOD-LABEL: Known module source files
// MEMBER_MOD-DAG: + {{.*}}{{[/\\]}}test{{[/\\]}}IDE{{[/\\]}}complete_sourcefileinfo.swift
// MEMBER_MOD-DAG: + {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// MEMBER_MOD-DAG: - {{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// MEMBER_MOD-LABEL: Begin completions, 5 items
// MEMBER_MOD-DAG: Keyword[self]/CurrNominal: self[#MyStruct#]; name=self{{$}}
// MEMBER_MOD-DAG: Decl[InstanceVar]/CurrNominal: propertyInType[#Int#]; name=propertyInType; source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// MEMBER_MOD-DAG: Decl[InstanceMethod]/CurrNominal: funcInType({#x: Int#})[#Void#]; name=funcInType(x:); source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule1.swift
// MEMBER_MOD-DAG: Decl[InstanceVar]/CurrNominal: propertyInExtension[#String#]; name=propertyInExtension; source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// MEMBER_MOD-DAG: Decl[InstanceMethod]/CurrNominal: funcInExtension()[#String#]; name=funcInExtension(); source={{.*}}{{[/\\]}}Sources{{[/\\]}}MyModule2.swift
// MEMBER_MOD: End completions

View File

@@ -1167,12 +1167,12 @@ Completion *CompletionBuilder::finish() {
if (current.getKind() == SwiftResult::Declaration) { if (current.getKind() == SwiftResult::Declaration) {
base = SwiftResult( base = SwiftResult(
semanticContext, flair, current.getNumBytesToErase(), completionString, semanticContext, flair, current.getNumBytesToErase(),
current.getAssociatedDeclKind(), current.isSystem(), completionString, current.getAssociatedDeclKind(), current.isSystem(),
current.getModuleName(), current.getSourceFilePath(), current.getModuleName(), current.getNotRecommendedReason(),
current.getNotRecommendedReason(), current.getDiagnosticSeverity(), current.getDiagnosticSeverity(), current.getDiagnosticMessage(),
current.getDiagnosticMessage(), current.getBriefDocComment(), current.getBriefDocComment(), current.getAssociatedUSRs(),
current.getAssociatedUSRs(), typeRelation, opKind); typeRelation, opKind);
} else { } else {
base = SwiftResult(current.getKind(), semanticContext, flair, base = SwiftResult(current.getKind(), semanticContext, flair,
current.getNumBytesToErase(), completionString, current.getNumBytesToErase(), completionString,

View File

@@ -471,12 +471,6 @@ CodeCOmpletionAnnotateResults("code-completion-annotate-results",
llvm::cl::cat(Category), llvm::cl::cat(Category),
llvm::cl::init(false)); llvm::cl::init(false));
static llvm::cl::opt<bool>
CodeCompletionSourceFileInfo("code-completion-sourcefileinfo",
llvm::cl::desc("print module source file information"),
llvm::cl::cat(Category),
llvm::cl::init(false));
static llvm::cl::opt<std::string> static llvm::cl::opt<std::string>
DebugClientDiscriminator("debug-client-discriminator", DebugClientDiscriminator("debug-client-discriminator",
llvm::cl::desc("A discriminator to prefer in lookups"), llvm::cl::desc("A discriminator to prefer in lookups"),
@@ -926,7 +920,6 @@ static int doCodeCompletion(const CompilerInvocation &InitInvok,
bool CodeCompletionKeywords, bool CodeCompletionKeywords,
bool CodeCompletionComments, bool CodeCompletionComments,
bool CodeCompletionAnnotateResults, bool CodeCompletionAnnotateResults,
bool CodeCompletionSourceFileInfo,
bool CodeCompletionSourceText) { bool CodeCompletionSourceText) {
std::unique_ptr<ide::OnDiskCodeCompletionCache> OnDiskCache; std::unique_ptr<ide::OnDiskCodeCompletionCache> OnDiskCache;
if (!options::CompletionCachePath.empty()) { if (!options::CompletionCachePath.empty()) {
@@ -936,7 +929,6 @@ static int doCodeCompletion(const CompilerInvocation &InitInvok,
ide::CodeCompletionCache CompletionCache(OnDiskCache.get()); ide::CodeCompletionCache CompletionCache(OnDiskCache.get());
ide::CodeCompletionContext CompletionContext(CompletionCache); ide::CodeCompletionContext CompletionContext(CompletionCache);
CompletionContext.setAnnotateResult(CodeCompletionAnnotateResults); CompletionContext.setAnnotateResult(CodeCompletionAnnotateResults);
CompletionContext.setRequiresSourceFileInfo(CodeCompletionSourceFileInfo);
// Create a CodeCompletionConsumer. // Create a CodeCompletionConsumer.
std::unique_ptr<ide::CodeCompletionConsumer> Consumer( std::unique_ptr<ide::CodeCompletionConsumer> Consumer(
@@ -1133,7 +1125,6 @@ static int doBatchCodeCompletion(const CompilerInvocation &InitInvok,
bool CodeCompletionKeywords, bool CodeCompletionKeywords,
bool CodeCompletionComments, bool CodeCompletionComments,
bool CodeCompletionAnnotateResults, bool CodeCompletionAnnotateResults,
bool CodeCompletionSourceFileInfo,
bool CodeCompletionSourceText) { bool CodeCompletionSourceText) {
auto FileBufOrErr = llvm::MemoryBuffer::getFile(SourceFilename); auto FileBufOrErr = llvm::MemoryBuffer::getFile(SourceFilename);
if (!FileBufOrErr) { if (!FileBufOrErr) {
@@ -1276,7 +1267,6 @@ static int doBatchCodeCompletion(const CompilerInvocation &InitInvok,
// Consumer. // Consumer.
ide::CodeCompletionContext CompletionContext(CompletionCache); ide::CodeCompletionContext CompletionContext(CompletionCache);
CompletionContext.setAnnotateResult(CodeCompletionAnnotateResults); CompletionContext.setAnnotateResult(CodeCompletionAnnotateResults);
CompletionContext.setRequiresSourceFileInfo(CodeCompletionSourceFileInfo);
std::unique_ptr<CodeCompletionCallbacksFactory> callbacksFactory( std::unique_ptr<CodeCompletionCallbacksFactory> callbacksFactory(
ide::makeCodeCompletionCallbacksFactory(CompletionContext, ide::makeCodeCompletionCallbacksFactory(CompletionContext,
*Consumer)); *Consumer));
@@ -4068,7 +4058,6 @@ int main(int argc, char *argv[]) {
options::CodeCompletionKeywords, options::CodeCompletionKeywords,
options::CodeCompletionComments, options::CodeCompletionComments,
options::CodeCOmpletionAnnotateResults, options::CodeCOmpletionAnnotateResults,
options::CodeCompletionSourceFileInfo,
options::CodeCompletionSourceText); options::CodeCompletionSourceText);
break; break;
@@ -4085,7 +4074,6 @@ int main(int argc, char *argv[]) {
options::CodeCompletionKeywords, options::CodeCompletionKeywords,
options::CodeCompletionComments, options::CodeCompletionComments,
options::CodeCOmpletionAnnotateResults, options::CodeCOmpletionAnnotateResults,
options::CodeCompletionSourceFileInfo,
options::CodeCompletionSourceText); options::CodeCompletionSourceText);
break; break;