project: decrease score if .c is matched against .hh (#549)

This commit is contained in:
Fangrui Song 2019-12-22 10:06:34 -08:00
parent e373f9ed97
commit 6c87a4656c

View File

@ -551,11 +551,16 @@ Project::Entry Project::findEntry(const std::string &path, bool can_redirect,
if (!best) { if (!best) {
// Infer args from a similar path. // Infer args from a similar path.
int best_score = INT_MIN; int best_score = INT_MIN;
auto [lang, header] = lookupExtension(path);
for (auto &[root, folder] : root2folder) for (auto &[root, folder] : root2folder)
if (StringRef(path).startswith(root)) if (StringRef(path).startswith(root))
for (const Entry &e : folder.entries) for (const Entry &e : folder.entries)
if (e.compdb_size) { if (e.compdb_size) {
int score = computeGuessScore(path, e.filename); int score = computeGuessScore(path, e.filename);
// Decrease score if .c is matched against .hh
auto [lang1, header1] = lookupExtension(e.filename);
if (lang != lang1 && !(lang == LanguageId::C && header))
score -= 30;
if (score > best_score) { if (score > best_score) {
best_score = score; best_score = score;
best_compdb_folder = &folder; best_compdb_folder = &folder;