[CursorInfo] Always add module name to response

To simplify clients, have the cursorinfo result be consistent whether
requesting a symbol within the current module or not, ie. do not skip
adding the module name.

Resolves rdar://77003299
This commit is contained in:
Ben Barham
2021-10-21 16:18:24 +10:00
parent 9415becb10
commit 8128450690
8 changed files with 160 additions and 24 deletions

View File

@@ -753,26 +753,23 @@ getParamParentNameOffset(const ValueDecl *VD, SourceLoc Cursor) {
return SM.getLocOffsetInBuffer(Loc, SM.findBufferContainingLoc(Loc));
}
static StringRef
getModuleName(const ValueDecl *VD, llvm::BumpPtrAllocator &Allocator,
ModuleDecl *IgnoreModule = nullptr) {
static StringRef getModuleName(const ValueDecl *VD,
llvm::BumpPtrAllocator &Allocator) {
ASTContext &Ctx = VD->getASTContext();
ClangImporter *Importer =
static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
auto ClangNode = VD->getClangNode();
if (ClangNode) {
auto ClangMod = Importer->getClangOwningModule(ClangNode);
if (ClangMod)
if (auto ClangNode = VD->getClangNode()) {
if (const auto *ClangMod = Importer->getClangOwningModule(ClangNode))
return copyString(Allocator, ClangMod->getFullModuleName());
} else if (VD->getModuleContext() != IgnoreModule) {
ModuleDecl *MD = VD->getModuleContext();
// If the decl is from a cross-import overlay module, report the
// overlay's declaring module as the owning module.
if (ModuleDecl *Declaring = MD->getDeclaringModuleIfCrossImportOverlay())
MD = Declaring;
return MD->getNameStr();
return "";
}
return "";
ModuleDecl *MD = VD->getModuleContext();
// If the decl is from a cross-import overlay module, report the
// overlay's declaring module as the owning module.
if (ModuleDecl *Declaring = MD->getDeclaringModuleIfCrossImportOverlay())
MD = Declaring;
return MD->getNameStr();
}
struct DeclInfo {
@@ -1044,9 +1041,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
llvm::makeArrayRef(ReferencedDecls));
}
Symbol.ModuleName = copyString(Allocator,
getModuleName(DInfo.VD, Allocator,
/*ModuleToIgnore=*/MainModule));
Symbol.ModuleName = getModuleName(DInfo.VD, Allocator);
if (auto IFaceGenRef =
Lang.getIFaceGenContexts().find(Symbol.ModuleName, Invoc))
Symbol.ModuleInterfaceName = IFaceGenRef->getDocumentName();