Random changes. (#6)

This commit is contained in:
scturtle 2018-05-08 15:35:32 +08:00 committed by Fangrui Song
parent 6c57f9663e
commit 888a870c0d
6 changed files with 37 additions and 19 deletions

View File

@ -1841,12 +1841,15 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
if (!ns.def.spell) {
ClangCursor sem_parent = referenced.get_semantic_parent();
ClangCursor lex_parent = referenced.get_lexical_parent();
ns.def.spell =
SetUse(db, referenced.get_spell(), sem_parent, Role::Definition);
ns.def.extent =
SetUse(db, referenced.get_extent(), lex_parent, Role::None);
std::string name = referenced.get_spell_name();
SetTypeName(ns, referenced, nullptr, name.c_str(), param);
CXFile referenced_file;
Range spell = referenced.get_spell(&referenced_file);
if (file == referenced_file) {
ns.def.spell = SetUse(db, spell, sem_parent, Role::Definition);
ns.def.extent =
SetUse(db, referenced.get_extent(), lex_parent, Role::None);
std::string name = referenced.get_spell_name();
SetTypeName(ns, referenced, nullptr, name.c_str(), param);
}
}
break;
}

View File

@ -71,6 +71,13 @@ bool Indexer_Parse(DiagnosticsEngine* diag_engine,
auto& request = *opt_request;
ICacheManager cache;
// dummy one to trigger refresh semantic highlight
if (request.path.empty()) {
queue->on_indexed.PushBack(
Index_OnIndexed(IndexUpdate{}, PerformanceImportFile()), false);
return false;
}
Project::Entry entry;
{
std::lock_guard<std::mutex> lock(project->mutex_);
@ -216,6 +223,18 @@ void QueryDb_OnIndexed(QueueManager* queue,
SemanticHighlightSymbolCache* semantic_cache,
WorkingFiles* working_files,
Index_OnIndexed* response) {
if (response->update.file_id < 0) { // dummy
LOG_S(INFO) << "Loaded project. Refresh semantic highlight for all working file.";
std::lock_guard<std::mutex> lock(working_files->files_mutex);
for (auto& f : working_files->files) {
int file_id = db->name2file_id[LowerPathIfInsensitive(f->filename)];
QueryFile* file = &db->files[file_id];
EmitSemanticHighlighting(db, semantic_cache, f.get(), file);
}
return;
}
Timer time;
db->ApplyIndexUpdate(&response->update);

View File

@ -106,8 +106,8 @@ void IncludeComplete::Rescan() {
SetThreadName("scan_includes");
Timer timer;
InsertIncludesFromDirectory(g_config->projectRoot,
false /*use_angle_brackets*/);
// InsertIncludesFromDirectory(g_config->projectRoot,
// false /*use_angle_brackets*/);
for (const std::string& dir : project_->quote_include_directories)
InsertIncludesFromDirectory(dir, false /*use_angle_brackets*/);
for (const std::string& dir : project_->angle_include_directories)

View File

@ -510,12 +510,9 @@ struct Handler_Initialize : BaseMessageHandler<In_InitializeRequest> {
// Start indexer threads. Start this after loading the project, as that
// may take a long time. Indexer threads will emit status/progress
// reports.
if (g_config->index.threads == 0) {
// If the user has not specified how many indexers to run, try to
// guess an appropriate value. Default to 80% utilization.
g_config->index.threads =
std::max(int(std::thread::hardware_concurrency() * 0.8), 1);
}
if (g_config->index.threads == 0)
g_config->index.threads = std::thread::hardware_concurrency();
LOG_S(INFO) << "Starting " << g_config->index.threads << " indexers";
for (int i = 0; i < g_config->index.threads; i++) {
std::thread([=]() {

View File

@ -563,6 +563,9 @@ void Project::Index(QueueManager* queue,
queue->index_request.PushBack(Index_Request(entry.filename, entry.args,
is_interactive, *content, id));
});
// dummy request to indicate that project is loaded and
// trigger refreshing semantic highlight for all working files
queue->index_request.PushBack(Index_Request("", {}, false, ""));
}
TEST_SUITE("Project") {

View File

@ -99,11 +99,7 @@ struct IndexUpdate {
static IndexUpdate CreateDelta(IndexFile* previous,
IndexFile* current);
// Merge |update| into this update; this can reduce overhead / index update
// work can be parallelized.
void Merge(IndexUpdate&& update);
int file_id;
int file_id = -1;
// File updates.
std::optional<std::string> files_removed;