Commit 7f298993 authored by Sven Brauch's avatar Sven Brauch
Browse files

do not additionally report not-found imports as undefined variables

BUG:316901
parent e33e2d55
......@@ -806,6 +806,7 @@ Declaration* DeclarationBuilder::createModuleImportDeclaration(QString moduleNam
p->setSource(KDevelop::IProblem::SemanticAnalysis);
p->setSeverity(KDevelop::IProblem::Warning);
p->setDescription(i18n("Module \"%1\" not found", moduleName));
m_missingModules.append(IndexedString(moduleName));
problemEncountered = p;
return 0;
}
......
......@@ -74,6 +74,13 @@ public:
*/
QString buildModuleNameFromNode(ImportFromAst* node, AliasAst* alias, const QString& intermediate) const;
/**
* @brief Get a list of all module names which were not found while parsing.
*/
QVector<IndexedString> missingModules() const {
return m_missingModules;
}
protected:
/// AST visitor functions
virtual void visitClassDefinition(ClassDefinitionAst* node);
......@@ -286,6 +293,8 @@ private:
QScopedPointer<CorrectionHelper> m_correctionHelper;
int m_ownPriority = 0;
StructureType::Ptr m_currentClassType;
// missing modules, for not reporting them as unknown variables
QVector<IndexedString> m_missingModules;
};
}
......
......@@ -39,7 +39,10 @@ using namespace KDevelop;
namespace Python {
UseBuilder::UseBuilder (PythonEditorIntegrator* editor) : UseBuilderBase(), m_errorReportingEnabled(true)
UseBuilder::UseBuilder(PythonEditorIntegrator* editor, QVector<IndexedString> ignoreVariables)
: UseBuilderBase()
, m_errorReportingEnabled(true)
, m_ignoreVariables(ignoreVariables)
{
setEditor(editor);
}
......@@ -75,15 +78,17 @@ void UseBuilder::visitName(NameAst* node)
if ( declaration && declaration->range() == useRange ) return;
if ( ! declaration && ! keywords.contains(node->identifier->value) && m_errorReportingEnabled ) {
KDevelop::Problem *p = new KDevelop::Problem();
p->setFinalLocation(DocumentRange(currentlyParsedDocument(), useRange.castToSimpleRange())); // TODO ok?
p->setSource(KDevelop::IProblem::SemanticAnalysis);
p->setSeverity(KDevelop::IProblem::Hint);
p->setDescription(i18n("Undefined variable: %1", node->identifier->value));
{
DUChainWriteLocker wlock(DUChain::lock());
ProblemPointer ptr(p);
topContext()->addProblem(ptr);
if ( ! m_ignoreVariables.contains(IndexedString(node->identifier->value)) ) {
KDevelop::Problem *p = new KDevelop::Problem();
p->setFinalLocation(DocumentRange(currentlyParsedDocument(), useRange.castToSimpleRange())); // TODO ok?
p->setSource(KDevelop::IProblem::SemanticAnalysis);
p->setSeverity(KDevelop::IProblem::Hint);
p->setDescription(i18n("Undefined variable: %1", node->identifier->value));
{
DUChainWriteLocker wlock(DUChain::lock());
ProblemPointer ptr(p);
topContext()->addProblem(ptr);
}
}
}
......
......@@ -35,7 +35,8 @@ typedef KDevelop::AbstractUseBuilder<Ast, Identifier, ContextBuilder> UseBuilder
class KDEVPYTHONDUCHAIN_EXPORT UseBuilder: public UseBuilderBase
{
public:
UseBuilder(PythonEditorIntegrator *editor);
/// vector of names to ignore since they were unknown imports
UseBuilder(PythonEditorIntegrator *editor, QVector<IndexedString> ignoreVariables);
ParseSession* parseSession() const;
protected:
......@@ -56,6 +57,8 @@ private:
m_errorReportingEnabled = true;
};
DUContext* contextAtOrCurrent(const CursorInRevision& pos);
QVector<IndexedString> m_ignoreVariables;
};
}
......
......@@ -173,7 +173,7 @@ void ParseJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*th
setDuChain(m_duContext);
// gather uses of variables and functions on the document
UseBuilder usebuilder(editor.data());
UseBuilder usebuilder(editor.data(), builder.missingModules());
usebuilder.setCurrentlyParsedDocument(document());
usebuilder.buildUses(m_ast.data());
......
Supports Markdown
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