[clangd] Change index scope convention from "outer::inner" to "outer::inner::"
Global scope is "" (was "")
Top-level namespace scope is "ns::" (was "ns")
Nested namespace scope is "ns::ns::" (was "ns::ns")
This composes more naturally:
- qname = scope + name
- full scope = resolved scope + unresolved scope (D42073 was the trigger)
It removes a wart from the old way: "foo::" has one more separator than "".
Another alternative that has these properties is "::ns", but that lacks
the property that both the scope and the name are substrings of the
qname as produced by clang.
This is re-landing r322996 which didn't build.
llvm-svn: 323000
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 1a95b6b..639547d 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -313,7 +313,7 @@
/// completion (e.g. "ns::ab?").
struct SpecifiedScope {
/// The scope specifier as written. For example, for completion "ns::ab?", the
- /// written scope specifier is "ns".
+ /// written scope specifier is "ns::".
std::string Written;
// If this scope specifier is recognized in Sema (e.g. as a namespace
// context), this will be set to the fully qualfied name of the corresponding
@@ -321,8 +321,8 @@
std::string Resolved;
llvm::StringRef forIndex() {
- llvm::StringRef Chosen = Resolved.empty() ? Written : Resolved;
- return Chosen.trim(':');
+ return Resolved.empty() ? StringRef(Written).ltrim("::")
+ : StringRef(Resolved);
}
};
@@ -631,15 +631,14 @@
auto SpecifierRange = SS.getRange();
Info.Written = Lexer::getSourceText(
CharSourceRange::getCharRange(SpecifierRange), SM, clang::LangOptions());
+ if (!Info.Written.empty())
+ Info.Written += "::"; // Sema excludes the trailing ::.
if (SS.isValid()) {
DeclContext *DC = S.computeDeclContext(SS);
if (auto *NS = llvm::dyn_cast<NamespaceDecl>(DC)) {
- Info.Resolved = NS->getQualifiedNameAsString();
+ Info.Resolved = NS->getQualifiedNameAsString() + "::";
} else if (llvm::dyn_cast<TranslationUnitDecl>(DC) != nullptr) {
- Info.Resolved = "::";
- // Sema does not include the suffix "::" in the range of SS, so we add
- // it back here.
- Info.Written = "::";
+ Info.Resolved = "";
}
}
return Info;