mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-23 16:15:07 +00:00
textDocument/didOpen: index related files when a header is opened
Fix #180 index.initialBlacklist: ["."] can inhibit initial indexing (useful for larger code bases). Opened files are still indexed, though. This heuristic allows related files (a/foo.c a/b/foo.cc) to be indexed when a header (foo.h) is opened.
This commit is contained in:
parent
36f7775a67
commit
e1b68383c6
@ -53,10 +53,12 @@ void MessageHandler::textDocument_didOpen(DidOpenTextDocumentParam ¶m) {
|
|||||||
|
|
||||||
// Submit new index request if it is not a header file or there is no
|
// Submit new index request if it is not a header file or there is no
|
||||||
// pending index request.
|
// pending index request.
|
||||||
std::pair<LanguageId, bool> lang = lookupExtension(path);
|
auto [lang, header] = lookupExtension(path);
|
||||||
if ((lang.first != LanguageId::Unknown && !lang.second) ||
|
if ((lang != LanguageId::Unknown && !header) ||
|
||||||
!pipeline::pending_index_requests)
|
!pipeline::pending_index_requests)
|
||||||
pipeline::Index(path, {}, IndexMode::Normal, false);
|
pipeline::Index(path, {}, IndexMode::Normal, false);
|
||||||
|
if (header)
|
||||||
|
project->IndexRelated(path);
|
||||||
|
|
||||||
manager->OnView(path);
|
manager->OnView(path);
|
||||||
}
|
}
|
||||||
|
@ -535,4 +535,22 @@ void Project::Index(WorkingFiles *wfiles, RequestId id) {
|
|||||||
// trigger refreshing semantic highlight for all working files.
|
// trigger refreshing semantic highlight for all working files.
|
||||||
pipeline::Index("", {}, IndexMode::NonInteractive, false);
|
pipeline::Index("", {}, IndexMode::NonInteractive, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::IndexRelated(const std::string &path) {
|
||||||
|
auto &gi = g_config->index;
|
||||||
|
GroupMatch match(gi.whitelist, gi.blacklist);
|
||||||
|
std::string stem = sys::path::stem(path);
|
||||||
|
std::lock_guard lock(mtx);
|
||||||
|
for (auto &[root, folder] : root2folder)
|
||||||
|
if (StringRef(path).startswith(root)) {
|
||||||
|
for (const Project::Entry &entry : folder.entries) {
|
||||||
|
std::string reason;
|
||||||
|
if (sys::path::stem(entry.filename) == stem && entry.filename != path &&
|
||||||
|
match.Matches(entry.filename, &reason))
|
||||||
|
pipeline::Index(entry.filename, entry.args, IndexMode::NonInteractive,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
@ -65,5 +65,6 @@ struct Project {
|
|||||||
const std::string &path);
|
const std::string &path);
|
||||||
|
|
||||||
void Index(WorkingFiles *wfiles, RequestId id);
|
void Index(WorkingFiles *wfiles, RequestId id);
|
||||||
|
void IndexRelated(const std::string &path);
|
||||||
};
|
};
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
Loading…
Reference in New Issue
Block a user