Commit e186124e authored by Denis Steckelmacher's avatar Denis Steckelmacher

Give a proper range to anonymous classes/structs/functions

Replace RangeInRevision() (first line, first column, zero length) with a zero-length
range that is on the right line. This way, multiple anonymous declarations in the
same context can be differentiated if they are all on a different line.
parent ad18a07c
......@@ -239,7 +239,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::FunctionExpression* node)
declareFunction<FunctionDeclaration>(
node,
QualifiedIdentifier(),
RangeInRevision(),
QmlJS::emptyRangeOnLine(node->functionToken),
node->formals,
m_session->locationsToInnerRange(node->lparenToken, node->rparenToken),
node->body,
......@@ -429,7 +429,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::ObjectLiteral* node)
DUChainWriteLocker lock;
ClassDeclaration* decl = openDeclaration<ClassDeclaration>(
QualifiedIdentifier(),
RangeInRevision()
QmlJS::emptyRangeOnLine(node->lbraceToken)
);
decl->setKind(Declaration::Type);
......@@ -656,7 +656,7 @@ void DeclarationBuilder::declareComponentSubclass(QmlJS::AST::UiObjectInitialize
currentContext()->type() == DUContext::Global ?
QualifiedIdentifier(m_session->moduleName()) :
name,
RangeInRevision()
QmlJS::emptyRangeOnLine(node->lbraceToken)
);
decl->clearBaseClasses();
......@@ -1028,7 +1028,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::UiPublicMember* node)
node->parameters,
m_session->locationToRange(node->identifierToken), // The AST does not provide the location of the parens
nullptr,
RangeInRevision()
RangeInRevision::invalid()
);
// This declaration is a signal and its return type is void
......
......@@ -154,4 +154,9 @@ DUContext* getInternalContext(const DeclarationPointer& declaration)
}
}
RangeInRevision emptyRangeOnLine(const AST::SourceLocation& location)
{
return RangeInRevision(location.startLine - 1, 0, location.startLine - 1, 0);
}
} // End of namespace QmlJS
......@@ -79,6 +79,11 @@ using namespace KDevelop;
KDEVQMLJSDUCHAIN_EXPORT DUContext* getInternalContext(const DeclarationPointer &declaration);
/**
* Build a zero-length range on the line of the given SourceLocation
*/
KDEVQMLJSDUCHAIN_EXPORT RangeInRevision emptyRangeOnLine(const AST::SourceLocation& location);
} // End of namespace QmlJS
......
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