From 55c0d5b4eb0c57cbfe424944739c3a5a554eb480 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 26 Aug 2020 11:36:55 -0700 Subject: [PATCH] project: override the compdb entry with .ccls if compile_commands.json is not used Note: `exact_match` should be false if the entry is an synthetic one, instead of an explicit entry in compile_commands.json --- src/project.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/project.cc b/src/project.cc index 58fa850d..d9bbec1e 100644 --- a/src/project.cc +++ b/src/project.cc @@ -522,9 +522,10 @@ Project::Entry Project::findEntry(const std::string &path, bool can_redirect, auto it = folder.path2entry_index.find(path); if (it != folder.path2entry_index.end()) { Project::Entry &entry = folder.entries[it->second]; - exact_match = entry.filename == path; - if ((match = exact_match || can_redirect) || entry.compdb_size) { - // best->compdb_size is >0 for a compdb entry, 0 for a .ccls entry. + // best->compdb_size is >0 for an explicit compile_commands.json + // entry, 0 for an implicit entry. + exact_match = entry.compdb_size > 0 && entry.filename == path; + if ((match = exact_match || can_redirect) && entry.compdb_size) { best_compdb_folder = &folder; best = &entry; }