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) ...@@ -239,7 +239,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::FunctionExpression* node)
declareFunction<FunctionDeclaration>( declareFunction<FunctionDeclaration>(
node, node,
QualifiedIdentifier(), QualifiedIdentifier(),
RangeInRevision(), QmlJS::emptyRangeOnLine(node->functionToken),
node->formals, node->formals,
m_session->locationsToInnerRange(node->lparenToken, node->rparenToken), m_session->locationsToInnerRange(node->lparenToken, node->rparenToken),
node->body, node->body,
...@@ -429,7 +429,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::ObjectLiteral* node) ...@@ -429,7 +429,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::ObjectLiteral* node)
DUChainWriteLocker lock; DUChainWriteLocker lock;
ClassDeclaration* decl = openDeclaration<ClassDeclaration>( ClassDeclaration* decl = openDeclaration<ClassDeclaration>(
QualifiedIdentifier(), QualifiedIdentifier(),
RangeInRevision() QmlJS::emptyRangeOnLine(node->lbraceToken)
); );
decl->setKind(Declaration::Type); decl->setKind(Declaration::Type);
...@@ -656,7 +656,7 @@ void DeclarationBuilder::declareComponentSubclass(QmlJS::AST::UiObjectInitialize ...@@ -656,7 +656,7 @@ void DeclarationBuilder::declareComponentSubclass(QmlJS::AST::UiObjectInitialize
currentContext()->type() == DUContext::Global ? currentContext()->type() == DUContext::Global ?
QualifiedIdentifier(m_session->moduleName()) : QualifiedIdentifier(m_session->moduleName()) :
name, name,
RangeInRevision() QmlJS::emptyRangeOnLine(node->lbraceToken)
); );
decl->clearBaseClasses(); decl->clearBaseClasses();
...@@ -1028,7 +1028,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::UiPublicMember* node) ...@@ -1028,7 +1028,7 @@ bool DeclarationBuilder::visit(QmlJS::AST::UiPublicMember* node)
node->parameters, node->parameters,
m_session->locationToRange(node->identifierToken), // The AST does not provide the location of the parens m_session->locationToRange(node->identifierToken), // The AST does not provide the location of the parens
nullptr, nullptr,
RangeInRevision() RangeInRevision::invalid()
); );
// This declaration is a signal and its return type is void // This declaration is a signal and its return type is void
......
...@@ -154,4 +154,9 @@ DUContext* getInternalContext(const DeclarationPointer& declaration) ...@@ -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 } // End of namespace QmlJS
...@@ -79,6 +79,11 @@ using namespace KDevelop; ...@@ -79,6 +79,11 @@ using namespace KDevelop;
KDEVQMLJSDUCHAIN_EXPORT DUContext* getInternalContext(const DeclarationPointer &declaration); 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 } // 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