Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KDevelop
KDevelop Python Support
Commits
7f298993
Commit
7f298993
authored
Oct 10, 2015
by
Sven Brauch
Browse files
do not additionally report not-found imports as undefined variables
BUG:316901
parent
e33e2d55
Changes
5
Hide whitespace changes
Inline
Side-by-side
duchain/declarationbuilder.cpp
View file @
7f298993
...
...
@@ -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
;
}
...
...
duchain/declarationbuilder.h
View file @
7f298993
...
...
@@ -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
;
};
}
...
...
duchain/usebuilder.cpp
View file @
7f298993
...
...
@@ -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
);
}
}
}
...
...
duchain/usebuilder.h
View file @
7f298993
...
...
@@ -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
;
};
}
...
...
pythonparsejob.cpp
View file @
7f298993
...
...
@@ -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
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment