You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
change-namespace
clang-apply-replacements
clang-move
clang-query
clang-reorder-fields
clang-tidy
clang-tidy-vs
clangd
clients
fuzzer
global-symbol-builder
index
FileIndex.cpp
FileIndex.h
Index.cpp
Index.h
MemIndex.cpp
MemIndex.h
SymbolCollector.cpp
SymbolCollector.h
SymbolYAML.cpp
SymbolYAML.h
tool
CMakeLists.txt
ClangdLSPServer.cpp
ClangdLSPServer.h
ClangdServer.cpp
ClangdServer.h
ClangdUnit.cpp
ClangdUnit.h
ClangdUnitStore.cpp
ClangdUnitStore.h
CodeComplete.cpp
CodeComplete.h
CodeCompletionStrings.cpp
CodeCompletionStrings.h
Compiler.cpp
Compiler.h
Context.cpp
Context.h
DraftStore.cpp
DraftStore.h
Function.h
FuzzyMatch.cpp
FuzzyMatch.h
GlobalCompilationDatabase.cpp
GlobalCompilationDatabase.h
JSONExpr.cpp
JSONExpr.h
JSONRPCDispatcher.cpp
JSONRPCDispatcher.h
Logger.cpp
Logger.h
Path.h
Protocol.cpp
Protocol.h
ProtocolHandlers.cpp
ProtocolHandlers.h
SourceCode.cpp
SourceCode.h
Trace.cpp
Trace.h
XRefs.cpp
XRefs.h
docs
include-fixer
modularize
pp-trace
test
tool-template
unittests
.arcconfig
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
LICENSE.TXT
README.txt
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
![]() |
//===--- FileIndex.cpp - Indexes for files. ------------------------ C++-*-===//
|
||
|
//
|
||
|
// The LLVM Compiler Infrastructure
|
||
|
//
|
||
|
// This file is distributed under the University of Illinois Open Source
|
||
|
// License. See LICENSE.TXT for details.
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
#include "FileIndex.h"
|
||
|
#include "SymbolCollector.h"
|
||
|
#include "clang/Index/IndexingAction.h"
|
||
|
|
||
|
namespace clang {
|
||
|
namespace clangd {
|
||
|
namespace {
|
||
|
|
||
|
/// Retrieves namespace and class level symbols in \p Decls.
|
||
|
std::unique_ptr<SymbolSlab> indexAST(ASTContext &Ctx,
|
||
|
llvm::ArrayRef<const Decl *> Decls) {
|
||
|
auto Collector = std::make_shared<SymbolCollector>();
|
||
|
index::IndexingOptions IndexOpts;
|
||
|
IndexOpts.SystemSymbolFilter =
|
||
|
index::IndexingOptions::SystemSymbolFilterKind::All;
|
||
|
IndexOpts.IndexFunctionLocals = false;
|
||
|
|
||
|
index::indexTopLevelDecls(Ctx, Decls, Collector, IndexOpts);
|
||
|
auto Symbols = llvm::make_unique<SymbolSlab>();
|
||
|
*Symbols = Collector->takeSymbols();
|
||
|
return Symbols;
|
||
|
}
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
void FileSymbols::update(PathRef Path, std::unique_ptr<SymbolSlab> Slab) {
|
||
|
std::lock_guard<std::mutex> Lock(Mutex);
|
||
|
if (!Slab)
|
||
|
FileToSlabs.erase(Path);
|
||
|
else
|
||
|
FileToSlabs[Path] = std::move(Slab);
|
||
|
}
|
||
|
|
||
|
std::shared_ptr<std::vector<const Symbol *>> FileSymbols::allSymbols() {
|
||
|
// The snapshot manages life time of symbol slabs and provides pointers of all
|
||
|
// symbols in all slabs.
|
||
|
struct Snapshot {
|
||
|
std::vector<const Symbol *> Pointers;
|
||
|
std::vector<std::shared_ptr<SymbolSlab>> KeepAlive;
|
||
|
};
|
||
|
auto Snap = std::make_shared<Snapshot>();
|
||
|
{
|
||
|
std::lock_guard<std::mutex> Lock(Mutex);
|
||
|
|
||
|
for (const auto &FileAndSlab : FileToSlabs) {
|
||
|
Snap->KeepAlive.push_back(FileAndSlab.second);
|
||
|
for (const auto &Iter : *FileAndSlab.second)
|
||
|
Snap->Pointers.push_back(&Iter);
|
||
|
}
|
||
|
}
|
||
|
auto *Pointers = &Snap->Pointers;
|
||
|
// Use aliasing constructor to keep the snapshot alive along with the
|
||
|
// pointers.
|
||
|
return {std::move(Snap), Pointers};
|
||
|
}
|
||
|
|
||
|
void FileIndex::update(const Context &Ctx, PathRef Path, ParsedAST *AST) {
|
||
|
if (!AST) {
|
||
|
FSymbols.update(Path, nullptr);
|
||
|
} else {
|
||
|
auto Slab = indexAST(AST->getASTContext(), AST->getTopLevelDecls());
|
||
|
FSymbols.update(Path, std::move(Slab));
|
||
|
}
|
||
|
auto Symbols = FSymbols.allSymbols();
|
||
|
Index.build(std::move(Symbols));
|
||
|
}
|
||
|
|
||
|
bool FileIndex::fuzzyFind(
|
||
|
const Context &Ctx, const FuzzyFindRequest &Req,
|
||
|
llvm::function_ref<void(const Symbol &)> Callback) const {
|
||
|
return Index.fuzzyFind(Ctx, Req, Callback);
|
||
|
}
|
||
|
|
||
|
} // namespace clangd
|
||
|
} // namespace clang
|