Implement code completion support for module import declarations, e.g.,
@import <complete with module names here> or @import std.<complete with submodule names here> Addresses <rdar://problem/10710117>. llvm-svn: 149199
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
#include "clang/AST/ExprCXX.h"
|
||||
#include "clang/AST/ExprObjC.h"
|
||||
#include "clang/Lex/HeaderSearch.h"
|
||||
#include "clang/Lex/MacroInfo.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
@@ -3010,6 +3011,57 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext,
|
||||
}
|
||||
}
|
||||
|
||||
void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc,
|
||||
ModuleIdPath Path) {
|
||||
typedef CodeCompletionResult Result;
|
||||
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
|
||||
CodeCompletionContext::CCC_Other);
|
||||
Results.EnterNewScope();
|
||||
|
||||
CodeCompletionAllocator &Allocator = Results.getAllocator();
|
||||
CodeCompletionBuilder Builder(Allocator);
|
||||
typedef CodeCompletionResult Result;
|
||||
if (Path.empty()) {
|
||||
// Enumerate all top-level modules.
|
||||
llvm::SmallVector<Module *, 8> Modules;
|
||||
PP.getHeaderSearchInfo().collectAllModules(Modules);
|
||||
for (unsigned I = 0, N = Modules.size(); I != N; ++I) {
|
||||
Builder.AddTypedTextChunk(
|
||||
Builder.getAllocator().CopyString(Modules[I]->Name));
|
||||
Results.AddResult(Result(Builder.TakeString(),
|
||||
CCP_Declaration,
|
||||
CXCursor_NotImplemented,
|
||||
Modules[I]->isAvailable()
|
||||
? CXAvailability_Available
|
||||
: CXAvailability_NotAvailable));
|
||||
}
|
||||
} else {
|
||||
// Load the named module.
|
||||
Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path,
|
||||
Module::AllVisible,
|
||||
/*IsInclusionDirective=*/false);
|
||||
// Enumerate submodules.
|
||||
if (Mod) {
|
||||
for (Module::submodule_iterator Sub = Mod->submodule_begin(),
|
||||
SubEnd = Mod->submodule_end();
|
||||
Sub != SubEnd; ++Sub) {
|
||||
|
||||
Builder.AddTypedTextChunk(
|
||||
Builder.getAllocator().CopyString((*Sub)->Name));
|
||||
Results.AddResult(Result(Builder.TakeString(),
|
||||
CCP_Declaration,
|
||||
CXCursor_NotImplemented,
|
||||
(*Sub)->isAvailable()
|
||||
? CXAvailability_Available
|
||||
: CXAvailability_NotAvailable));
|
||||
}
|
||||
}
|
||||
}
|
||||
Results.ExitScope();
|
||||
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
|
||||
Results.data(),Results.size());
|
||||
}
|
||||
|
||||
void Sema::CodeCompleteOrdinaryName(Scope *S,
|
||||
ParserCompletionContext CompletionContext) {
|
||||
typedef CodeCompletionResult Result;
|
||||
|
||||
Reference in New Issue
Block a user