DocumentSymbol filter out some PropertyDefinitions

Because of the way Dom stores PropertyDefinitions and Bindings,
the following expressions like `property var a: 4;` are stored
inside DOM (QmlObject to be precise) as first: propertyDefinition of `a`,
second as binding `a:4;` Hence leading to "duplicates" in the Outline view.
It was decided that in such cases "representational "priority
should be given to Binding, hence it's necessary
to filter out PropertyDefinition.
This is done using the ColonTokenRegion of PropertyDefinition from the FileLocations

Note: this could have been done later, during the rearrangement of
DocumentSymbol tree, however, to do that during the "first" visit "should be"
more computationally efficient.

Task-number: QTBUG-120002
Change-Id: I8cef8d3205c8559556937f4ccc56924ead0434f3
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
This commit is contained in:
Dmitrii Akshintsev 2024-07-17 17:30:13 +02:00
parent 86a3a0fbf7
commit 2de3e2930b
1 changed files with 21 additions and 1 deletions

View File

@ -52,6 +52,26 @@ constexpr static inline bool documentSymbolNotSupportedFor(const DomType &type)
return symbolKindFor(type) == SymbolKind::Null;
}
static bool propertyBoundAtDefinitionLine(const DomItem &propertyDefinition)
{
Q_ASSERT(propertyDefinition.internalKind() == DomType::PropertyDefinition);
return FileLocations::treeOf(propertyDefinition)->info().regions[ColonTokenRegion].isValid();
}
static inline bool shouldFilterOut(const DomItem &item)
{
const auto itemType = item.internalKind();
if (documentSymbolNotSupportedFor(itemType)) {
return true;
}
if (itemType == DomType::PropertyDefinition && propertyBoundAtDefinitionLine(item)) {
// without this check there is a "duplication" of symbols.
// one representing PropertyDefinition another one - Binding
return true;
}
return false;
}
static std::optional<QByteArray> tryGetQmlObjectDetail(const DomItem &qmlObj)
{
using namespace QQmlJS::Dom;
@ -121,7 +141,7 @@ std::optional<QByteArray> tryGetDetailOf(const DomItem &item)
*/
SymbolsList buildSymbolOrReturnChildren(const DomItem &item, SymbolsList &&children)
{
if (documentSymbolNotSupportedFor(item.internalKind())) {
if (shouldFilterOut(item)) {
// nothing to build, just returning children
return std::move(children);
}