Members of the KDE Community are recommended to subscribe to the kde-community mailing list at to allow them to participate in important discussions and receive other important announcements

Commit a52858b8 authored by Milian Wolff's avatar Milian Wolff

Filter out declarations from non-imported contexts in code completion

We easily got confused in our code completion, e.g. when you
looked at the navigation widget for `main()`, it often came from
a different file... Other times this lead to even bigger issues,
like not picking up the right overload and instead using a random
other function from a different file unrelated to the current TU.

Note, I really need to get my ass up and finally get integrated upstream...
parent 9a952eb3
......@@ -521,7 +521,22 @@ Declaration* findDeclaration(const QualifiedIdentifier& qid, const DUContextPoin
PersistentSymbolTable::Declarations decl = PersistentSymbolTable::self().getDeclarations(qid);
const auto top = ctx->topContext();
const auto& importedContexts = top->importedParentContexts();
for (auto it = decl.iterator(); it; ++it) {
// if the context is not included, then this match is not correct for our consideration
// this fixes issues where we used to include matches from files that did not have
// anything to do with the current TU, e.g. the main from a different file or stuff like that
// it also reduces the chance of us picking up a function of the same name from somewhere else
// also, this makes sure the context has the correct language and we don't get confused by stuff
// from other language plugins
if (std::none_of(importedContexts.begin(), importedContexts.end(), [it] (const DUContext::Import& import) {
return import.topContextIndex() == it->indexedTopContext().index();
})) {
auto declaration = it->declaration();
if (!declaration) {
// Mitigate problems such as: Cannot load a top-context from file "/home/kfunk/.cache/kdevduchain/kdevelop-{foo}/topcontexts/6085"
......@@ -530,11 +545,6 @@ Declaration* findDeclaration(const QualifiedIdentifier& qid, const DUContextPoin
const auto& file = declaration->topContext()->parsingEnvironmentFile();
if (!file || file->language() != ParseSession::languageString()) {
if (declaration->kind() == Declaration::Instance && !declaration->isFunctionDeclaration()) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment