Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/clang_indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what problem does this check solve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should fix wrong spell name highlight for aliased namespace. For example, namespace fs = std::experimental::filesystem in filesystem.hh. 7:11-7:13 are also highlighted in other files.

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;
}
Expand Down
19 changes: 19 additions & 0 deletions src/import_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down Expand Up @@ -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
Copy link
Owner

@MaskRay MaskRay May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic highlighting does work reliably when the project is still loading. This is because message_handler.cc uses:

    switch (sym.kind) {
      case SymbolKind::Func: {
        const QueryFunc& func = db->GetFunc(sym);
        const QueryFunc::Def* def = func.AnyDef(); ///////// definition required, declaration is ignored
        if (!def)
          continue;  // applies to for loop

Functions defined outside of the current file may not be colored correctly.
I think this patch is very promising to improve the situation!

I occasionally observe that some files are not highlighted, but I am unable to narrow it down (does not look like a forward-line out-of-range error)

I'll try this patch tomorrow on LLVM

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);

Expand Down
4 changes: 2 additions & 2 deletions src/include_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ void IncludeComplete::Rescan() {
SetThreadName("scan_includes");
Timer timer;

InsertIncludesFromDirectory(g_config->projectRoot,
false /*use_angle_brackets*/);
// InsertIncludesFromDirectory(g_config->projectRoot,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be removed. (I didn't even notice this because I don't use include completion much)

https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

// 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)
Expand Down
9 changes: 3 additions & 6 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

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([=]() {
Expand Down
3 changes: 3 additions & 0 deletions src/project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Capitalize.

// trigger refreshing semantic highlight for all working files
queue->index_request.PushBack(Index_Request("", {}, false, ""));
}

TEST_SUITE("Project") {
Expand Down
6 changes: 1 addition & 5 deletions src/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down