[clangd] Simplify code. No functionality change intended.
llvm-svn: 321523
This commit is contained in:
parent
314981bacd
commit
50a967d601
|
@ -37,7 +37,7 @@ void FileSymbols::update(PathRef Path, std::unique_ptr<SymbolSlab> Slab) {
|
||||||
if (!Slab)
|
if (!Slab)
|
||||||
FileToSlabs.erase(Path);
|
FileToSlabs.erase(Path);
|
||||||
else
|
else
|
||||||
FileToSlabs[Path] = std::shared_ptr<SymbolSlab>(Slab.release());
|
FileToSlabs[Path] = std::move(Slab);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<std::vector<const Symbol *>> FileSymbols::allSymbols() {
|
std::shared_ptr<std::vector<const Symbol *>> FileSymbols::allSymbols() {
|
||||||
|
@ -74,9 +74,10 @@ void FileIndex::update(const Context &Ctx, PathRef Path, ParsedAST *AST) {
|
||||||
Index.build(std::move(Symbols));
|
Index.build(std::move(Symbols));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileIndex::fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
bool FileIndex::fuzzyFind(
|
||||||
std::function<void(const Symbol &)> Callback) const {
|
const Context &Ctx, const FuzzyFindRequest &Req,
|
||||||
return Index.fuzzyFind(Ctx, Req, std::move(Callback));
|
llvm::function_ref<void(const Symbol &)> Callback) const {
|
||||||
|
return Index.fuzzyFind(Ctx, Req, Callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace clangd
|
} // namespace clangd
|
||||||
|
|
|
@ -60,8 +60,9 @@ public:
|
||||||
/// nullptr, this removes all symbols in the file
|
/// nullptr, this removes all symbols in the file
|
||||||
void update(const Context &Ctx, PathRef Path, ParsedAST *AST);
|
void update(const Context &Ctx, PathRef Path, ParsedAST *AST);
|
||||||
|
|
||||||
bool fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
bool
|
||||||
std::function<void(const Symbol &)> Callback) const override;
|
fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
||||||
|
llvm::function_ref<void(const Symbol &)> Callback) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileSymbols FSymbols;
|
FileSymbols FSymbols;
|
||||||
|
|
|
@ -29,10 +29,6 @@ void operator>>(StringRef Str, SymbolID &ID) {
|
||||||
std::copy(HexString.begin(), HexString.end(), ID.HashValue.begin());
|
std::copy(HexString.begin(), HexString.end(), ID.HashValue.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolSlab::const_iterator SymbolSlab::begin() const { return Symbols.begin(); }
|
|
||||||
|
|
||||||
SymbolSlab::const_iterator SymbolSlab::end() const { return Symbols.end(); }
|
|
||||||
|
|
||||||
SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
|
SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
|
||||||
auto It = std::lower_bound(Symbols.begin(), Symbols.end(), ID,
|
auto It = std::lower_bound(Symbols.begin(), Symbols.end(), ID,
|
||||||
[](const Symbol &S, const SymbolID &I) {
|
[](const Symbol &S, const SymbolID &I) {
|
||||||
|
@ -50,9 +46,7 @@ static void own(Symbol &S, DenseSet<StringRef> &Strings,
|
||||||
auto Intern = [&](StringRef &V) {
|
auto Intern = [&](StringRef &V) {
|
||||||
auto R = Strings.insert(V);
|
auto R = Strings.insert(V);
|
||||||
if (R.second) { // New entry added to the table, copy the string.
|
if (R.second) { // New entry added to the table, copy the string.
|
||||||
char *Data = Arena.Allocate<char>(V.size());
|
*R.first = V.copy(Arena);
|
||||||
memcpy(Data, V.data(), V.size());
|
|
||||||
*R.first = StringRef(Data, V.size());
|
|
||||||
}
|
}
|
||||||
V = *R.first;
|
V = *R.first;
|
||||||
};
|
};
|
||||||
|
|
|
@ -140,8 +140,8 @@ public:
|
||||||
|
|
||||||
SymbolSlab() = default;
|
SymbolSlab() = default;
|
||||||
|
|
||||||
const_iterator begin() const;
|
const_iterator begin() const { return Symbols.begin(); }
|
||||||
const_iterator end() const;
|
const_iterator end() const { return Symbols.end(); }
|
||||||
const_iterator find(const SymbolID &SymID) const;
|
const_iterator find(const SymbolID &SymID) const;
|
||||||
|
|
||||||
size_t size() const { return Symbols.size(); }
|
size_t size() const { return Symbols.size(); }
|
||||||
|
@ -214,7 +214,7 @@ public:
|
||||||
/// to MaxCandidateCount
|
/// to MaxCandidateCount
|
||||||
virtual bool
|
virtual bool
|
||||||
fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
||||||
std::function<void(const Symbol &)> Callback) const = 0;
|
llvm::function_ref<void(const Symbol &)> Callback) const = 0;
|
||||||
|
|
||||||
// FIXME: add interfaces for more index use cases:
|
// FIXME: add interfaces for more index use cases:
|
||||||
// - Symbol getSymbolInfo(SymbolID);
|
// - Symbol getSymbolInfo(SymbolID);
|
||||||
|
|
|
@ -26,8 +26,9 @@ void MemIndex::build(std::shared_ptr<std::vector<const Symbol *>> Syms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemIndex::fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
bool MemIndex::fuzzyFind(
|
||||||
std::function<void(const Symbol &)> Callback) const {
|
const Context &Ctx, const FuzzyFindRequest &Req,
|
||||||
|
llvm::function_ref<void(const Symbol &)> Callback) const {
|
||||||
assert(!StringRef(Req.Query).contains("::") &&
|
assert(!StringRef(Req.Query).contains("::") &&
|
||||||
"There must be no :: in query.");
|
"There must be no :: in query.");
|
||||||
|
|
||||||
|
@ -38,14 +39,7 @@ bool MemIndex::fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
||||||
const Symbol *Sym = Pair.second;
|
const Symbol *Sym = Pair.second;
|
||||||
|
|
||||||
// Exact match against all possible scopes.
|
// Exact match against all possible scopes.
|
||||||
bool ScopeMatched = Req.Scopes.empty();
|
if (!Req.Scopes.empty() && !llvm::is_contained(Req.Scopes, Sym->Scope))
|
||||||
for (StringRef Scope : Req.Scopes) {
|
|
||||||
if (Scope == Sym->Scope) {
|
|
||||||
ScopeMatched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ScopeMatched)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// FIXME(ioeric): use fuzzy matcher.
|
// FIXME(ioeric): use fuzzy matcher.
|
||||||
|
|
|
@ -24,8 +24,9 @@ public:
|
||||||
/// accessible as long as `Symbols` is kept alive.
|
/// accessible as long as `Symbols` is kept alive.
|
||||||
void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
|
void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
|
||||||
|
|
||||||
bool fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
bool
|
||||||
std::function<void(const Symbol &)> Callback) const override;
|
fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
|
||||||
|
llvm::function_ref<void(const Symbol &)> Callback) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<std::vector<const Symbol *>> Symbols;
|
std::shared_ptr<std::vector<const Symbol *>> Symbols;
|
||||||
|
|
|
@ -48,11 +48,10 @@ std::string makeAbsolutePath(const SourceManager &SM, StringRef Path) {
|
||||||
llvm::sys::path::parent_path(AbsolutePath.str()));
|
llvm::sys::path::parent_path(AbsolutePath.str()));
|
||||||
if (Dir) {
|
if (Dir) {
|
||||||
StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
|
StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
|
||||||
SmallVector<char, 128> AbsoluteFilename;
|
SmallString<128> AbsoluteFilename;
|
||||||
llvm::sys::path::append(AbsoluteFilename, DirName,
|
llvm::sys::path::append(AbsoluteFilename, DirName,
|
||||||
llvm::sys::path::filename(AbsolutePath.str()));
|
llvm::sys::path::filename(AbsolutePath.str()));
|
||||||
return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size())
|
return AbsoluteFilename.str();
|
||||||
.str();
|
|
||||||
}
|
}
|
||||||
return AbsolutePath.str();
|
return AbsolutePath.str();
|
||||||
}
|
}
|
||||||
|
@ -85,11 +84,10 @@ bool SymbolCollector::handleDeclOccurence(
|
||||||
if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
|
if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
llvm::SmallVector<char, 128> Buff;
|
llvm::SmallString<128> USR;
|
||||||
if (index::generateUSRForDecl(ND, Buff))
|
if (index::generateUSRForDecl(ND, USR))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
std::string USR(Buff.data(), Buff.size());
|
|
||||||
auto ID = SymbolID(USR);
|
auto ID = SymbolID(USR);
|
||||||
if (Symbols.find(ID) != nullptr)
|
if (Symbols.find(ID) != nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue