mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-23 16:15:07 +00:00
Simplify indexer and query
This commit is contained in:
parent
97b1592475
commit
236e7c1393
@ -717,7 +717,7 @@ const int IndexFile::kMajorVersion = 15;
|
||||
const int IndexFile::kMinorVersion = 0;
|
||||
|
||||
IndexFile::IndexFile(const std::string& path, const std::string& contents)
|
||||
: id_cache(path), path(path), file_contents(contents) {}
|
||||
: id_cache{path}, path(path), file_contents(contents) {}
|
||||
|
||||
IndexTypeId IndexFile::ToTypeId(Usr usr) {
|
||||
auto it = id_cache.usr_to_type_id.find(usr);
|
||||
@ -843,9 +843,6 @@ void AddUseSpell(IndexFile* db, std::vector<Use>& uses, ClangCursor cursor) {
|
||||
AddUse(db, uses, cursor.get_spell(), cursor.get_lexical_parent().cx_cursor);
|
||||
}
|
||||
|
||||
IdCache::IdCache(const std::string& primary_file)
|
||||
: primary_file(primary_file) {}
|
||||
|
||||
void OnIndexDiagnostic(CXClientData client_data,
|
||||
CXDiagnosticSet diagnostics,
|
||||
void* reserved) {
|
||||
@ -903,24 +900,6 @@ CXIdxClientFile OnIndexIncludedFile(CXClientData client_data,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ClangCursor::VisitResult DumpVisitor(ClangCursor cursor,
|
||||
ClangCursor parent,
|
||||
int* level) {
|
||||
fprintf(stderr, "%*s%s %s\n", *level * 2, "",
|
||||
ToString(cursor.get_kind()).c_str(), cursor.get_spell_name().c_str());
|
||||
|
||||
*level += 1;
|
||||
cursor.VisitChildren(&DumpVisitor, level);
|
||||
*level -= 1;
|
||||
|
||||
return ClangCursor::VisitResult::Continue;
|
||||
}
|
||||
|
||||
void Dump(ClangCursor cursor) {
|
||||
int level = 0;
|
||||
cursor.VisitChildren(&DumpVisitor, &level);
|
||||
}
|
||||
|
||||
struct FindChildOfKindParam {
|
||||
CXCursorKind target_kind;
|
||||
std::optional<ClangCursor> result;
|
||||
@ -2191,8 +2170,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<FileContents>& file_contents,
|
||||
PerformanceImportFile* perf,
|
||||
ClangIndex* index,
|
||||
bool dump_ast) {
|
||||
ClangIndex* index) {
|
||||
if (!g_config->index.enabled)
|
||||
return {};
|
||||
|
||||
@ -2218,9 +2196,6 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
|
||||
perf->index_parse = timer.ElapsedMicrosecondsAndReset();
|
||||
|
||||
if (dump_ast)
|
||||
Dump(clang_getTranslationUnitCursor(tu->cx_tu));
|
||||
|
||||
return ParseWithTu(file_consumer_shared, perf, tu.get(), index, file,
|
||||
args, unsaved_files);
|
||||
}
|
||||
|
@ -223,11 +223,6 @@ struct Config {
|
||||
// Maximum number of definition/reference/... results.
|
||||
int maxNum = 2000;
|
||||
} xref;
|
||||
|
||||
//// For debugging
|
||||
|
||||
// Dump AST after parsing if some pattern matches the source filename.
|
||||
std::vector<std::string> dumpAST;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(Config::ClientCapability, snippetSupport);
|
||||
MAKE_REFLECT_STRUCT(Config::CodeLens, localVariables);
|
||||
@ -277,8 +272,6 @@ MAKE_REFLECT_STRUCT(Config,
|
||||
highlight,
|
||||
index,
|
||||
workspaceSymbol,
|
||||
xref,
|
||||
|
||||
dumpAST);
|
||||
xref);
|
||||
|
||||
extern std::unique_ptr<Config> g_config;
|
||||
|
@ -12,14 +12,7 @@ struct ClangIndexer : IIndexer {
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<FileContents>& file_contents,
|
||||
PerformanceImportFile* perf) override {
|
||||
bool dump_ast = false;
|
||||
for (const std::string& pattern : g_config->dumpAST)
|
||||
if (file.find(pattern) != std::string::npos) {
|
||||
dump_ast = true;
|
||||
break;
|
||||
}
|
||||
return Parse(file_consumer_shared, file, args, file_contents, perf,
|
||||
&index, dump_ast);
|
||||
return Parse(file_consumer_shared, file, args, file_contents, perf, &index);
|
||||
}
|
||||
|
||||
// Note: constructing this acquires a global lock
|
||||
|
@ -402,8 +402,6 @@ struct IdCache {
|
||||
std::unordered_map<IndexTypeId, Usr> type_id_to_usr;
|
||||
std::unordered_map<IndexFuncId, Usr> func_id_to_usr;
|
||||
std::unordered_map<IndexVarId, Usr> var_id_to_usr;
|
||||
|
||||
IdCache(const std::string& primary_file);
|
||||
};
|
||||
|
||||
struct IndexInclude {
|
||||
@ -484,8 +482,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<FileContents>& file_contents,
|
||||
PerformanceImportFile* perf,
|
||||
ClangIndex* index,
|
||||
bool dump_ast = false);
|
||||
ClangIndex* index);
|
||||
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
PerformanceImportFile* perf,
|
||||
|
@ -2,6 +2,16 @@
|
||||
#include "query_utils.h"
|
||||
#include "queue_manager.h"
|
||||
|
||||
MAKE_REFLECT_STRUCT(QueryFile::Def,
|
||||
file,
|
||||
path,
|
||||
args,
|
||||
language,
|
||||
outline,
|
||||
all_symbols,
|
||||
inactive_regions,
|
||||
dependencies);
|
||||
|
||||
namespace {
|
||||
MethodType kMethodType = "$ccls/fileInfo";
|
||||
|
||||
|
45
src/query.cc
45
src/query.cc
@ -22,6 +22,49 @@
|
||||
MAKE_HASHABLE(Range, t.start, t.end);
|
||||
MAKE_HASHABLE(Use, t.range);
|
||||
|
||||
template <typename TVisitor, typename TId, typename TValue>
|
||||
void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(id);
|
||||
REFLECT_MEMBER(to_add);
|
||||
REFLECT_MEMBER(to_remove);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
template <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, WithUsr<T>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(usr);
|
||||
REFLECT_MEMBER(value);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
template <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, WithFileContent<T>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(value);
|
||||
REFLECT_MEMBER(file_content);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
// NOTICE: We're not reflecting on files_removed or files_def_update, it is too
|
||||
// much output when logging
|
||||
MAKE_REFLECT_STRUCT(IndexUpdate,
|
||||
types_removed,
|
||||
types_def_update,
|
||||
types_derived,
|
||||
types_instances,
|
||||
types_uses,
|
||||
funcs_removed,
|
||||
funcs_def_update,
|
||||
funcs_declarations,
|
||||
funcs_derived,
|
||||
funcs_uses,
|
||||
vars_removed,
|
||||
vars_def_update,
|
||||
vars_declarations,
|
||||
vars_uses);
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
@ -414,7 +457,7 @@ Maybe<QueryVarId> QueryDatabase::GetQueryVarIdFromUsr(Usr usr) {
|
||||
}
|
||||
|
||||
IdMap::IdMap(QueryDatabase* query_db, const IdCache& local_ids)
|
||||
: local_ids(local_ids) {
|
||||
: local_ids{local_ids} {
|
||||
// LOG_S(INFO) << "Creating IdMap for " << local_ids.primary_file;
|
||||
primary_file =
|
||||
*GetQueryFileIdFromPath(query_db, local_ids.primary_file, true);
|
||||
|
48
src/query.h
48
src/query.h
@ -46,14 +46,6 @@ struct MergeableUpdate {
|
||||
std::vector<TValue>&& to_remove)
|
||||
: id(id), to_add(std::move(to_add)), to_remove(std::move(to_remove)) {}
|
||||
};
|
||||
template <typename TVisitor, typename TId, typename TValue>
|
||||
void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(id);
|
||||
REFLECT_MEMBER(to_add);
|
||||
REFLECT_MEMBER(to_remove);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct WithUsr {
|
||||
@ -63,13 +55,6 @@ struct WithUsr {
|
||||
WithUsr(Usr usr, const T& value) : usr(usr), value(value) {}
|
||||
WithUsr(Usr usr, T&& value) : usr(usr), value(std::move(value)) {}
|
||||
};
|
||||
template <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, WithUsr<T>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(usr);
|
||||
REFLECT_MEMBER(value);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct WithFileContent {
|
||||
@ -79,13 +64,6 @@ struct WithFileContent {
|
||||
WithFileContent(const T& value, const std::string& file_content)
|
||||
: value(value), file_content(file_content) {}
|
||||
};
|
||||
template <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, WithFileContent<T>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(value);
|
||||
REFLECT_MEMBER(file_content);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
struct QueryFamily {
|
||||
using FileId = Id<QueryFile>;
|
||||
@ -124,15 +102,6 @@ struct QueryFile {
|
||||
def->path = path;
|
||||
}
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(QueryFile::Def,
|
||||
file,
|
||||
path,
|
||||
args,
|
||||
language,
|
||||
outline,
|
||||
all_symbols,
|
||||
inactive_regions,
|
||||
dependencies);
|
||||
|
||||
template <typename Q, typename QDef>
|
||||
struct QueryEntity {
|
||||
@ -239,23 +208,6 @@ struct IndexUpdate {
|
||||
IndexFile& previous,
|
||||
IndexFile& current);
|
||||
};
|
||||
// NOTICE: We're not reflecting on files_removed or files_def_update, it is too
|
||||
// much output when logging
|
||||
MAKE_REFLECT_STRUCT(IndexUpdate,
|
||||
types_removed,
|
||||
types_def_update,
|
||||
types_derived,
|
||||
types_instances,
|
||||
types_uses,
|
||||
funcs_removed,
|
||||
funcs_def_update,
|
||||
funcs_declarations,
|
||||
funcs_derived,
|
||||
funcs_uses,
|
||||
vars_removed,
|
||||
vars_def_update,
|
||||
vars_declarations,
|
||||
vars_uses);
|
||||
|
||||
// The query database is heavily optimized for fast queries. It is stored
|
||||
// in-memory.
|
||||
|
@ -294,8 +294,7 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) {
|
||||
g_config = std::make_unique<Config>();
|
||||
FileConsumerSharedState file_consumer_shared;
|
||||
PerformanceImportFile perf;
|
||||
auto dbs = Parse(&file_consumer_shared, path, flags, {}, &perf, &index,
|
||||
false /*dump_ast*/);
|
||||
auto dbs = Parse(&file_consumer_shared, path, flags, {}, &perf, &index);
|
||||
|
||||
for (const auto& entry : all_expected_output) {
|
||||
const std::string& expected_path = entry.first;
|
||||
|
Loading…
Reference in New Issue
Block a user