Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQmlLSUtils Namespace Reference

Classes

struct  Edit
 
struct  ErrorMessage
 
struct  ExpressionType
 
struct  FileRename
 Represents a rename operation where the file itself needs to be renamed. More...
 
struct  ItemLocation
 
struct  Location
 
class  RenameUsages
 Represents the locations where a renaming should take place. More...
 
struct  SignalOrProperty
 
struct  TextPosition
 
class  Usages
 Represents the locations where some highlighting should take place, like in the "find all references" feature of the LSP. More...
 

Typedefs

using DomItem = QQmlJS::Dom::DomItem
 

Enumerations

enum  IdentifierType : char {
  JavaScriptIdentifier , PropertyIdentifier , PropertyChangedSignalIdentifier , PropertyChangedHandlerIdentifier ,
  SignalIdentifier , SignalHandlerIdentifier , MethodIdentifier , QmlObjectIdIdentifier ,
  SingletonIdentifier , EnumeratorIdentifier , EnumeratorValueIdentifier , AttachedTypeIdentifier ,
  GroupedPropertyIdentifier , QmlComponentIdentifier
}
 
enum  ResolveOptions { ResolveOwnerType , ResolveActualTypeForFieldMemberExpression }
 

Functions

QString qualifiersFrom (const DomItem &el)
 
bool isFieldMemberExpression (const DomItem &item)
 
bool isFieldMemberAccess (const DomItem &item)
 
QStringList fieldMemberExpressionBits (const DomItem &item, const DomItem &stopAtChild)
 
QByteArray lspUriToQmlUrl (const QByteArray &uri)
 
QByteArray qmlUrlToLspUri (const QByteArray &url)
 
QLspSpecification::Range qmlLocationToLspLocation (const QString &code, QQmlJS::SourceLocation qmlLocation)
 Converts a QQmlJS::SourceLocation to a LSP Range.
 
qsizetype textOffsetFrom (const QString &text, int row, int column)
 Convert a text position from (line, column) into an offset.
 
TextPosition textRowAndColumnFrom (const QString &text, qsizetype offset)
 Convert a text position from an offset into (line, column).
 
static QList< ItemLocation >::const_iterator handlePropertyDefinitionAndBindingOverlap (const QList< ItemLocation > &items, qsizetype offsetInFile)
 
static QList< ItemLocationfilterItemsFromTextLocation (const QList< ItemLocation > &items, qsizetype offsetInFile)
 
QList< ItemLocationitemsFromTextLocation (const DomItem &file, int line, int character)
 Find the DomItem representing the object situated in file at given line and character/column.
 
DomItem baseObject (const DomItem &object)
 
static std::optional< LocationlocationFromDomItem (const DomItem &item, FileLocationRegion region)
 
std::optional< LocationfindTypeDefinitionOf (const DomItem &object)
 Returns the location of the type definition pointed by object.
 
static bool findDefinitionFromItem (const DomItem &item, const QString &name)
 
static DomItem findJSIdentifierDefinition (const DomItem &item, const QString &name)
 
static std::optional< SignalOrPropertyresolveNameInQmlScope (const QString &name, const QQmlJSScope::ConstPtr &owner)
 Find out if {name} is a signal, signal handler, property, property changed signal, or a property changed handler in the given QQmlJSScope.
 
static QStringList namesOfPossibleUsages (const QString &name, const DomItem &item, const QQmlJSScope::ConstPtr &targetType)
 
template<typename Predicate >
QQmlJSScope::ConstPtr findDefiningScopeIf (const QQmlJSScope::ConstPtr &referrerScope, Predicate &&check)
 
QQmlJSScope::ConstPtr findDefiningScopeForProperty (const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck)
 Finds the scope where a property is first defined.
 
QQmlJSScope::ConstPtr findDefiningScopeForBinding (const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck)
 
QQmlJSScope::ConstPtr findDefiningScopeForMethod (const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck)
 
QQmlJSScope::ConstPtr findDefiningScopeForEnumeration (const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck)
 
QQmlJSScope::ConstPtr findDefiningScopeForEnumerationKey (const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck)
 
static FieldFilter filterForFindUsages ()
 Filter away the parts of the Dom not needed for find usages, by following the profiler's information.
 
static void findUsagesOfNonJSIdentifiers (const DomItem &item, const QString &name, Usages &result)
 
static Location locationFromJSIdentifierDefinition (const DomItem &definitionOfItem, const QString &name)
 
static void findUsagesHelper (const DomItem &item, const QString &name, Usages &result)
 
Usages findUsagesOf (const DomItem &item)
 
static std::optional< IdentifierTypehasMethodOrSignal (const QQmlJSScope::ConstPtr &scope, const QString &name)
 
static std::optional< ExpressionTypemethodFromReferrerScope (const QQmlJSScope::ConstPtr &referrerScope, const QString &name, ResolveOptions options)
 
static std::optional< ExpressionTypepropertyFromReferrerScope (const QQmlJSScope::ConstPtr &referrerScope, const QString &propertyName, ResolveOptions options)
 
static std::optional< ExpressionTypepropertyBindingFromReferrerScope (const QQmlJSScope::ConstPtr &referrerScope, const QString &name, ResolveOptions options, QQmlJSTypeResolver *resolverForIds)
 
static QQmlJSScope::ConstPtr findScopeOfSpecialItems (const QQmlJSScope::ConstPtr &scope, const DomItem &item)
 
static std::optional< ExpressionTyperesolveFieldMemberExpressionType (const DomItem &item, ResolveOptions options)
 
static std::optional< ExpressionTyperesolveIdentifierExpressionType (const DomItem &item, ResolveOptions options)
 
static std::optional< ExpressionTyperesolveSignalOrPropertyExpressionType (const QString &name, const QQmlJSScope::ConstPtr &scope, ResolveOptions options)
 
std::optional< ExpressionTyperesolveExpressionType (const QQmlJS::Dom::DomItem &item, ResolveOptions options)
 
DomItem sourceLocationToDomItem (const DomItem &file, const QQmlJS::SourceLocation &location)
 
static std::optional< LocationfindMethodDefinitionOf (const DomItem &file, QQmlJS::SourceLocation location, const QString &name)
 
static std::optional< LocationfindPropertyDefinitionOf (const DomItem &file, QQmlJS::SourceLocation propertyDefinitionLocation, const QString &name)
 
std::optional< LocationfindDefinitionOf (const DomItem &item)
 
static QQmlJSScope::ConstPtr propertyOwnerFrom (const QQmlJSScope::ConstPtr &type, const QString &name)
 
static QQmlJSScope::ConstPtr methodOwnerFrom (const QQmlJSScope::ConstPtr &type, const QString &name)
 
static QQmlJSScope::ConstPtr expressionTypeWithDefinition (const ExpressionType &ownerType)
 
std::optional< ErrorMessagecheckNameForRename (const DomItem &item, const QString &dirtyNewName, const std::optional< ExpressionType > &ownerType)
 
static std::optional< QStringoldNameFrom (const DomItem &item)
 
static std::optional< QStringnewNameFrom (const QString &dirtyNewName, IdentifierType alternative)
 
RenameUsages renameUsagesOf (const DomItem &item, const QString &dirtyNewName, const std::optional< ExpressionType > &targetType)
 Rename the appearance of item to newName.
 
bool isValidEcmaScriptIdentifier (QStringView identifier)
 
QPair< QString, QStringListcmakeBuildCommand (const QString &path)
 

Typedef Documentation

◆ DomItem

Definition at line 229 of file qqmllsutils_p.h.

Enumeration Type Documentation

◆ IdentifierType

Enumerator
JavaScriptIdentifier 
PropertyIdentifier 
PropertyChangedSignalIdentifier 
PropertyChangedHandlerIdentifier 
SignalIdentifier 
SignalHandlerIdentifier 
MethodIdentifier 
QmlObjectIdIdentifier 
SingletonIdentifier 
EnumeratorIdentifier 
EnumeratorValueIdentifier 
AttachedTypeIdentifier 
GroupedPropertyIdentifier 
QmlComponentIdentifier 

Definition at line 44 of file qqmllsutils_p.h.

◆ ResolveOptions

Choose whether to resolve the owner type or the entire type (the latter is only required to resolve the types of qualified names and property accesses).

For properties, methods, enums and co: ResolveOwnerType returns the base type of the owner that owns the property, method, enum and co. For example, resolving "x" in "myRectangle.x" will return the Item as the owner, as Item is the base type of Rectangle that defines the "x" property. ResolveActualTypeForFieldMemberExpression is used to resolve field member expressions, and might lose some information about the owner. For example, resolving "x" in "myRectangle.x" will return the JS type for float that was used to define the "x" property.

Enumerator
ResolveOwnerType 
ResolveActualTypeForFieldMemberExpression 

Definition at line 224 of file qqmllsutils_p.h.

Function Documentation

◆ baseObject()

DomItem QQmlLSUtils::baseObject ( const DomItem & object)

Definition at line 389 of file qqmllsutils.cpp.

References base, baseObject(), QQmlJS::Dom::DomItem::component(), QQmlJS::Dom::DomItem::field(), QQmlJS::Dom::DomItem::index(), qDebug, and QQmlJS::Dom::DomItem::qmlObject().

Referenced by baseObject(), and findTypeDefinitionOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkNameForRename()

std::optional< ErrorMessage > QQmlLSUtils::checkNameForRename ( const DomItem & item,
const QString & dirtyNewName,
const std::optional< ExpressionType > & ownerType )

Definition at line 1870 of file qqmllsutils.cpp.

References checkNameForRename(), expressionTypeWithDefinition(), QQmlSignalNames::isChangedHandlerName(), QQmlSignalNames::isChangedSignalName(), QQmlSignalNames::isHandlerName(), isValidEcmaScriptIdentifier(), item, JavaScriptIdentifier, MethodIdentifier, PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, QmlObjectIdIdentifier, resolveExpressionType(), ResolveOwnerType, SignalHandlerIdentifier, and SignalIdentifier.

Referenced by checkNameForRename(), and QQmlRenameSymbolSupport::process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cmakeBuildCommand()

QPair< QString, QStringList > QQmlLSUtils::cmakeBuildCommand ( const QString & path)

Returns the name of the cmake program along with the arguments needed to build the qmltyperegistration. This command generates the .qmltypes, qmldir and .qrc files required for qmlls to provide correct information on C++ defined QML elements.

We assume here that CMake is available in the path. This should be the case for linux and macOS by default. For windows, having CMake in the path is not too unrealistic, for example, https://doc.qt.io/qt-6/windows-building.html#step-2-install-build-requirements claims that you need to have CMake in your path to build Qt. So a developer machine running qmlls has a high chance of having CMake in their path, if CMake is installed and used.

Definition at line 2152 of file qqmllsutils.cpp.

References cmakeBuildCommand().

Referenced by cmakeBuildCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expressionTypeWithDefinition()

static QQmlJSScope::ConstPtr QQmlLSUtils::expressionTypeWithDefinition ( const ExpressionType & ownerType)
static

Definition at line 1835 of file qqmllsutils.cpp.

References AttachedTypeIdentifier, QQmlSignalNames::changedHandlerNameToPropertyName(), QQmlSignalNames::changedSignalNameToPropertyName(), EnumeratorIdentifier, EnumeratorValueIdentifier, expressionTypeWithDefinition(), GroupedPropertyIdentifier, QQmlSignalNames::handlerNameToSignalName(), JavaScriptIdentifier, MethodIdentifier, methodOwnerFrom(), PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, propertyOwnerFrom(), QmlComponentIdentifier, QmlObjectIdIdentifier, SignalHandlerIdentifier, SignalIdentifier, and SingletonIdentifier.

Referenced by checkNameForRename(), and expressionTypeWithDefinition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fieldMemberExpressionBits()

QStringList QQmlLSUtils::fieldMemberExpressionBits ( const DomItem & item,
const DomItem & stopAtChild )

Get the bits of a field member expression, like {a}, {b} and {c} for {a.b.c}.

stopAtChild can either be an FieldMemberExpression, a ScriptIdentifierExpression or a default constructed DomItem: This exits early before processing Field::right of an FieldMemberExpression stopAtChild, or before processing a ScriptIdentifierExpression stopAtChild. No early exits if stopAtChild is default constructed.

Definition at line 89 of file qqmllsutils.cpp.

References QQmlJS::Dom::DomItem::field(), fieldMemberExpressionBits(), isFieldMemberAccess(), isFieldMemberExpression(), item, QCborValue::toString(), and QQmlJS::Dom::DomItem::value().

Referenced by fieldMemberExpressionBits(), findTypeDefinitionOf(), and qualifiersFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filterForFindUsages()

static FieldFilter QQmlLSUtils::filterForFindUsages ( )
static

Filter away the parts of the Dom not needed for find usages, by following the profiler's information.

  1. "propertyInfos" tries to require all inherited properties of some QmlObject. That is super slow (profiler says it eats 90% of the time needed by tst_qmlls_utils findUsages!) and is not needed for usages.
  2. "get" tries to resolve references, like base types saved in prototypes for example, and is not needed to find usages. Profiler says it eats 70% of the time needed by tst_qmlls_utils findUsages.
  3. "defaultPropertyName" also recurses through base types and is not needed to find usages.

Definition at line 806 of file qqmllsutils.cpp.

References filterForFindUsages(), and QString::fromUtf16().

Referenced by filterForFindUsages(), findUsagesHelper(), and findUsagesOfNonJSIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filterItemsFromTextLocation()

static QList< ItemLocation > QQmlLSUtils::filterItemsFromTextLocation ( const QList< ItemLocation > & items,
qsizetype offsetInFile )
static

Definition at line 279 of file qqmllsutils.cpp.

References QList< T >::begin(), QSet< T >::begin(), QQmlJS::SourceLocation::begin(), QList< T >::end(), filterItemsFromTextLocation(), handlePropertyDefinitionAndBindingOverlap(), it, items, and QList< T >::size().

Referenced by filterItemsFromTextLocation(), and itemsFromTextLocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefiningScopeForBinding()

QQmlJSScope::ConstPtr QQmlLSUtils::findDefiningScopeForBinding ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & nameToCheck )

See also findDefiningScopeForProperty().

Special case: you can also bind to a signal handler.

Definition at line 751 of file qqmllsutils.cpp.

References findDefiningScopeForBinding(), findDefiningScopeIf(), QQmlJSScope::hasOwnMethod(), and QQmlJSScope::hasOwnProperty().

Referenced by findDefiningScopeForBinding(), and resolveExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefiningScopeForEnumeration()

QQmlJSScope::ConstPtr QQmlLSUtils::findDefiningScopeForEnumeration ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & nameToCheck )

See also findDefiningScopeForProperty().

Definition at line 775 of file qqmllsutils.cpp.

References findDefiningScopeForEnumeration(), findDefiningScopeIf(), and QQmlJSScope::hasOwnEnumeration().

Referenced by findDefiningScopeForEnumeration(), and resolveExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefiningScopeForEnumerationKey()

QQmlJSScope::ConstPtr QQmlLSUtils::findDefiningScopeForEnumerationKey ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & nameToCheck )

See also findDefiningScopeForProperty().

Definition at line 787 of file qqmllsutils.cpp.

References findDefiningScopeForEnumerationKey(), findDefiningScopeIf(), and QQmlJSScope::hasOwnEnumerationKey().

Referenced by findDefiningScopeForEnumerationKey(), and resolveExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefiningScopeForMethod()

QQmlJSScope::ConstPtr QQmlLSUtils::findDefiningScopeForMethod ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & nameToCheck )

See also findDefiningScopeForProperty().

Definition at line 763 of file qqmllsutils.cpp.

References findDefiningScopeForMethod(), findDefiningScopeIf(), and QQmlJSScope::hasOwnMethod().

Referenced by findDefiningScopeForMethod(), methodFromReferrerScope(), resolveExpressionType(), and resolveSignalOrPropertyExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefiningScopeForProperty()

QQmlJSScope::ConstPtr QQmlLSUtils::findDefiningScopeForProperty ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & nameToCheck )

Finds the scope where a property is first defined.

Starts looking for the name starting from the given scope and traverse through base and extension types.

Definition at line 737 of file qqmllsutils.cpp.

References findDefiningScopeForProperty(), findDefiningScopeIf(), and QQmlJSScope::hasOwnProperty().

Referenced by findDefiningScopeForProperty(), propertyBindingFromReferrerScope(), propertyFromReferrerScope(), resolveExpressionType(), and resolveSignalOrPropertyExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefiningScopeIf()

template<typename Predicate >
QQmlJSScope::ConstPtr QQmlLSUtils::findDefiningScopeIf ( const QQmlJSScope::ConstPtr & referrerScope,
Predicate && check )

Definition at line 714 of file qqmllsutils.cpp.

References findDefiningScopeIf(), and QQmlJSUtils::searchBaseAndExtensionTypes().

Referenced by findDefiningScopeForBinding(), findDefiningScopeForEnumeration(), findDefiningScopeForEnumerationKey(), findDefiningScopeForMethod(), findDefiningScopeForProperty(), and findDefiningScopeIf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefinitionFromItem()

static bool QQmlLSUtils::findDefinitionFromItem ( const DomItem & item,
const QString & name )
static

Definition at line 546 of file qqmllsutils.cpp.

References findDefinitionFromItem(), item, and qCDebug.

Referenced by findDefinitionFromItem(), and findJSIdentifierDefinition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDefinitionOf()

std::optional< Location > QQmlLSUtils::findDefinitionOf ( const DomItem & item)

◆ findJSIdentifierDefinition()

static DomItem QQmlLSUtils::findJSIdentifierDefinition ( const DomItem & item,
const QString & name )
static

Definition at line 558 of file qqmllsutils.cpp.

References QQmlJS::Dom::DomItem::field(), findDefinitionFromItem(), findJSIdentifierDefinition(), i, and item.

Referenced by findJSIdentifierDefinition(), findUsagesHelper(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findMethodDefinitionOf()

static std::optional< Location > QQmlLSUtils::findMethodDefinitionOf ( const DomItem & file,
QQmlJS::SourceLocation location,
const QString & name )
static

Definition at line 1681 of file qqmllsutils.cpp.

References QSet< T >::constEnd(), QSet< T >::constFind(), QQmlJS::Dom::DomItem::field(), file, findMethodDefinitionOf(), QQmlJS::Dom::IdentifierRegion, QQmlJS::Dom::DomItem::index(), it, QQmlJS::Dom::DomItem::key(), method, QQmlJS::Dom::DomItem::qmlObject(), sourceLocationToDomItem(), and QQmlJS::Dom::FileLocations::treeOf().

Referenced by findDefinitionOf(), and findMethodDefinitionOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findPropertyDefinitionOf()

static std::optional< Location > QQmlLSUtils::findPropertyDefinitionOf ( const DomItem & file,
QQmlJS::SourceLocation propertyDefinitionLocation,
const QString & name )
static

Definition at line 1702 of file qqmllsutils.cpp.

References QSet< T >::constEnd(), QSet< T >::constFind(), QQmlJS::Dom::DomItem::field(), file, findPropertyDefinitionOf(), QQmlJS::Dom::IdentifierRegion, QQmlJS::Dom::DomItem::index(), it, QQmlJS::Dom::DomItem::key(), QQmlJS::Dom::DomItem::qmlObject(), sourceLocationToDomItem(), and QQmlJS::Dom::FileLocations::treeOf().

Referenced by findDefinitionOf(), and findPropertyDefinitionOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findScopeOfSpecialItems()

static QQmlJSScope::ConstPtr QQmlLSUtils::findScopeOfSpecialItems ( const QQmlJSScope::ConstPtr & scope,
const DomItem & item )
static

Finds the scope within the special elements like Connections, PropertyChanges, Bindings or AnchorChanges.

Definition at line 1191 of file qqmllsutils.cpp.

References QQmlJS::Dom::DomItem::bindings(), findScopeOfSpecialItems(), QQmlJSScope::hasOwnPropertyBindings(), QQmlJS::Dom::DomItem::index(), QString::isEmpty(), item, QQmlJS::Dom::DomItem::key(), QQmlJSScope::parentScope(), QQmlJSUtils::searchBaseAndExtensionTypes(), and typeName.

Referenced by findScopeOfSpecialItems(), and resolveExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findTypeDefinitionOf()

std::optional< Location > QQmlLSUtils::findTypeDefinitionOf ( const DomItem & object)

Returns the location of the type definition pointed by object.

For a PropertyDefinition, return the location of the type of the property. For a Binding, return the bound item's type location if an QmlObject is bound, and otherwise the type of the property. For a QmlObject, return the location of the QmlObject's base. For an Id, return the location of the object to which the id resolves. For a Methodparameter, return the location of the type of the parameter. Otherwise, return std::nullopt.

Definition at line 444 of file qqmllsutils.cpp.

References baseObject(), QQmlJS::Dom::Binding, QQmlJS::Dom::DomItem::field(), fieldMemberExpressionBits(), findTypeDefinitionOf(), QQmlJS::Dom::Id, QQmlJS::Dom::DomItem::index(), item, locationFromDomItem(), QQmlJS::Dom::Paths::lookupTypePath(), QQmlJS::Dom::MethodInfo, QQmlJS::Dom::MethodParameter, QQmlJS::Dom::PropertyDefinition, Q_ASSERT, qDebug, QQmlJS::Dom::QmlComponent, QQmlJS::Dom::QmlObject, QmlObjectIdIdentifier, resolveExpressionType(), QQmlJS::Dom::ScriptIdentifierExpression, QQmlLSUtils::Location::sourceLocation, and sourceLocationToDomItem().

Referenced by findTypeDefinitionOf(), and QmlGoToTypeDefinitionSupport::process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findUsagesHelper()

static void QQmlLSUtils::findUsagesHelper ( const DomItem & item,
const QString & name,
Usages & result )
static

Definition at line 941 of file qqmllsutils.cpp.

References QQmlJS::Dom::emptyChildrenVisitor(), fileName, filterForFindUsages(), findJSIdentifierDefinition(), findUsagesHelper(), findUsagesOfNonJSIdentifiers(), item, locationFromJSIdentifierDefinition(), qCDebug, qCWarning, and QQmlJS::Dom::FileLocations::treeOf().

Referenced by findUsagesHelper(), and findUsagesOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findUsagesOf()

Usages QQmlLSUtils::findUsagesOf ( const DomItem & item)

Definition at line 982 of file qqmllsutils.cpp.

References findUsagesHelper(), findUsagesOf(), item, and qCDebug.

Referenced by findUsagesOf(), QQmlFindUsagesSupport::process(), and renameUsagesOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findUsagesOfNonJSIdentifiers()

static void QQmlLSUtils::findUsagesOfNonJSIdentifiers ( const DomItem & item,
const QString & name,
Usages & result )
static

Definition at line 817 of file qqmllsutils.cpp.

References QQmlJS::Dom::emptyChildrenVisitor(), QQmlJS::Dom::DomItem::field(), file, filterForFindUsages(), findUsagesOfNonJSIdentifiers(), QQmlJS::Dom::IdentifierRegion, QQmlJS::SourceLocation::isValid(), item, QQmlJS::Dom::DomItem::key(), QQmlJS::Dom::DomItem::keys(), QQmlJS::Dom::MainRegion, namesOfPossibleUsages(), QmlComponentIdentifier, QQmlJS::Dom::FileLocations::region(), resolveExpressionType(), ResolveOwnerType, QQmlJS::Dom::FileLocations::treeOf(), and QQmlJS::Dom::DomItem::visitTree().

Referenced by findUsagesHelper(), and findUsagesOfNonJSIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handlePropertyDefinitionAndBindingOverlap()

static QList< ItemLocation >::const_iterator QQmlLSUtils::handlePropertyDefinitionAndBindingOverlap ( const QList< ItemLocation > & items,
qsizetype offsetInFile )
static

Definition at line 230 of file qqmllsutils.cpp.

References QList< T >::begin(), QQmlJS::Dom::ColonTokenRegion, QList< T >::end(), handlePropertyDefinitionAndBindingOverlap(), and items.

Referenced by filterItemsFromTextLocation(), and handlePropertyDefinitionAndBindingOverlap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasMethodOrSignal()

static std::optional< IdentifierType > QQmlLSUtils::hasMethodOrSignal ( const QQmlJSScope::ConstPtr & scope,
const QString & name )
static

Definition at line 1038 of file qqmllsutils.cpp.

References hasMethodOrSignal(), QQmlJSScope::methods(), and methods.

Referenced by hasMethodOrSignal(), and methodFromReferrerScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFieldMemberAccess()

bool QQmlLSUtils::isFieldMemberAccess ( const DomItem & item)

Helper to check if item is a Field Member Access memberAccess in { <someExpression>.memberAccess}.

Definition at line 70 of file qqmllsutils.cpp.

References QQmlJS::Dom::DomItem::field(), isFieldMemberAccess(), isFieldMemberExpression(), and item.

Referenced by fieldMemberExpressionBits(), isFieldMemberAccess(), qualifiersFrom(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFieldMemberExpression()

bool QQmlLSUtils::isFieldMemberExpression ( const DomItem & item)

Helper to check if item is a Field Member Expression { <someExpression>.propertyName}.

Definition at line 58 of file qqmllsutils.cpp.

References QQmlJS::Dom::ScriptElements::BinaryExpression::FieldMemberAccess, isFieldMemberExpression(), and item.

Referenced by fieldMemberExpressionBits(), isFieldMemberAccess(), isFieldMemberExpression(), qualifiersFrom(), and resolveExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidEcmaScriptIdentifier()

bool QQmlLSUtils::isValidEcmaScriptIdentifier ( QStringView identifier)

Definition at line 2126 of file qqmllsutils.cpp.

References isValidEcmaScriptIdentifier(), QQmlJS::Lexer::lex(), QQmlJS::Lexer::setCode(), token, and QStringView::toString().

Referenced by checkNameForRename(), and isValidEcmaScriptIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ itemsFromTextLocation()

QList< ItemLocation > QQmlLSUtils::itemsFromTextLocation ( const DomItem & file,
int line,
int character )

Find the DomItem representing the object situated in file at given line and character/column.

If line and character point between two objects, two objects might be returned. If line and character point to whitespace, it might return an inner node of the QmlDom-Tree.

Definition at line 323 of file qqmllsutils.cpp.

References QSet< T >::begin(), QQmlLSUtils::ItemLocation::domItem, QSet< T >::end(), file, QQmlLSUtils::ItemLocation::fileLocation, QQmlJS::Dom::QmlFile::fileLocationsTree(), filterItemsFromTextLocation(), it, itemsFromTextLocation(), line, QQmlJS::Dom::DomItem::path(), Q_ASSERT, qCDebug, and textOffsetFrom().

Referenced by CompletionRequest::completions(), HelpManager::documentationForItem(), QQmlBaseModule< RequestType >::itemsForRequest(), itemsFromTextLocation(), and sourceLocationToDomItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locationFromDomItem()

static std::optional< Location > QQmlLSUtils::locationFromDomItem ( const DomItem & item,
FileLocationRegion region )
static

Definition at line 416 of file qqmllsutils.cpp.

References QQmlLSUtils::Location::filename, item, locationFromDomItem(), QQmlJS::Dom::MainRegion, QQmlJS::Dom::FileLocations::region(), and QQmlJS::Dom::FileLocations::treeOf().

Referenced by findTypeDefinitionOf(), and locationFromDomItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locationFromJSIdentifierDefinition()

static Location QQmlLSUtils::locationFromJSIdentifierDefinition ( const DomItem & definitionOfItem,
const QString & name )
static

Definition at line 926 of file qqmllsutils.cpp.

References locationFromJSIdentifierDefinition(), and Q_ASSERT_X.

Referenced by findUsagesHelper(), and locationFromJSIdentifierDefinition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lspUriToQmlUrl()

QByteArray QQmlLSUtils::lspUriToQmlUrl ( const QByteArray & uri)

The language server protocol calls "URI" what QML calls "URL". According to RFC 3986, a URL is a special case of URI that not only identifies a resource but also shows how to access it. In QML, however, URIs are distinct from URLs. URIs are the identifiers of modules, for example "QtQuick.Controls". In order to not confuse the terms we interpret language server URIs as URLs in the QML code model. This method marks a point of translation between the terms, but does not have to change the actual URI/URL.

See also
QQmlLSUtils::qmlUriToLspUrl

Definition at line 130 of file qqmllsutils.cpp.

References lspUriToQmlUrl().

Referenced by WorkspaceHandlers::clientInitialized(), TextSynchronization::didCloseTextDocument(), TextSynchronization::didDidChangeTextDocument(), TextSynchronization::didOpenTextDocument(), QQmlBaseModule< RequestType >::itemsForRequest(), lspUriToQmlUrl(), SemanticTokenDeltaHandler::process(), SemanticTokenRangeHandler::process(), SemanticTokenFullHandler::process(), QQmlDocumentFormatting::process(), QQmlHover::process(), QQmlRangeFormatting::process(), WorkspaceHandlers::registerHandlers(), and QQmlBaseModule< RequestType >::requestHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ methodFromReferrerScope()

static std::optional< ExpressionType > QQmlLSUtils::methodFromReferrerScope ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & name,
ResolveOptions options )
static

Searches for a method by traversing the parent scopes.

We assume here that it is possible to call methods from parent scope to simplify things, as the linting module already warns about calling methods from parent scopes.

Note: in QML, one can only call methods from the current scope, and from the QML file root scope. Everything else needs a qualifier.

Definition at line 1062 of file qqmllsutils.cpp.

References findDefiningScopeForMethod(), QQmlSignalNames::handlerNameToSignalName(), hasMethodOrSignal(), methodFromReferrerScope(), QQmlJSScope::parentScope(), ResolveActualTypeForFieldMemberExpression, ResolveOwnerType, and SignalHandlerIdentifier.

Referenced by methodFromReferrerScope(), resolveFieldMemberExpressionType(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ methodOwnerFrom()

static QQmlJSScope::ConstPtr QQmlLSUtils::methodOwnerFrom ( const QQmlJSScope::ConstPtr & type,
const QString & name )
static

Definition at line 1816 of file qqmllsutils.cpp.

References QQmlJSScope::baseType(), methodOwnerFrom(), Q_ASSERT, and qCDebug.

Referenced by expressionTypeWithDefinition(), and methodOwnerFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ namesOfPossibleUsages()

static QStringList QQmlLSUtils::namesOfPossibleUsages ( const QString & name,
const DomItem & item,
const QQmlJSScope::ConstPtr & targetType )
static

Returns a list of names, that when belonging to the same targetType, should be considered equal. This is used to find signal handlers as usages of their corresponding signals, for example.

Definition at line 658 of file qqmllsutils.cpp.

References item, namesOfPossibleUsages(), PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, QQmlSignalNames::propertyNameToChangedHandlerName(), QQmlSignalNames::propertyNameToChangedSignalName(), resolveNameInQmlScope(), SignalHandlerIdentifier, SignalIdentifier, and QQmlSignalNames::signalNameToHandlerName().

Referenced by findUsagesOfNonJSIdentifiers(), and namesOfPossibleUsages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ newNameFrom()

static std::optional< QString > QQmlLSUtils::newNameFrom ( const QString & dirtyNewName,
IdentifierType alternative )
static

Definition at line 1972 of file qqmllsutils.cpp.

References QQmlSignalNames::changedHandlerNameToPropertyName(), QQmlSignalNames::changedSignalNameToPropertyName(), QQmlSignalNames::handlerNameToSignalName(), newNameFrom(), PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, SignalHandlerIdentifier, and SignalIdentifier.

Referenced by newNameFrom(), and renameUsagesOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ oldNameFrom()

static std::optional< QString > QQmlLSUtils::oldNameFrom ( const DomItem & item)
static

Definition at line 1950 of file qqmllsutils.cpp.

References item, oldNameFrom(), and qCDebug.

Referenced by oldNameFrom(), and renameUsagesOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ propertyBindingFromReferrerScope()

static std::optional< ExpressionType > QQmlLSUtils::propertyBindingFromReferrerScope ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & name,
ResolveOptions options,
QQmlJSTypeResolver * resolverForIds )
static

See comment on methodFromReferrerScope: the same applies to property bindings.

If resolver is not null then it is used to resolve the id with which a generalized grouped properties starts.

Definition at line 1132 of file qqmllsutils.cpp.

References AssumeComponentsAreBound, QQmlSA::AttachedProperty, AttachedTypeIdentifier, findDefiningScopeForProperty(), getScope(), GroupedPropertyIdentifier, QQmlSA::GroupProperty, propertyBindingFromReferrerScope(), QmlObjectIdIdentifier, ResolveActualTypeForFieldMemberExpression, and ResolveOwnerType.

Referenced by propertyBindingFromReferrerScope(), resolveFieldMemberExpressionType(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ propertyFromReferrerScope()

static std::optional< ExpressionType > QQmlLSUtils::propertyFromReferrerScope ( const QQmlJSScope::ConstPtr & referrerScope,
const QString & propertyName,
ResolveOptions options )
static

See comment on methodFromReferrerScope: the same applies to properties.

Definition at line 1102 of file qqmllsutils.cpp.

References findDefiningScopeForProperty(), QQmlJSScope::parentScope(), property, propertyFromReferrerScope(), ResolveActualTypeForFieldMemberExpression, resolveNameInQmlScope(), and ResolveOwnerType.

Referenced by propertyFromReferrerScope(), resolveFieldMemberExpressionType(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ propertyOwnerFrom()

static QQmlJSScope::ConstPtr QQmlLSUtils::propertyOwnerFrom ( const QQmlJSScope::ConstPtr & type,
const QString & name )
static

Definition at line 1797 of file qqmllsutils.cpp.

References QQmlJSScope::baseType(), propertyOwnerFrom(), Q_ASSERT, and qCDebug.

Referenced by expressionTypeWithDefinition(), and propertyOwnerFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qmlLocationToLspLocation()

QLspSpecification::Range QQmlLSUtils::qmlLocationToLspLocation ( const QString & code,
QQmlJS::SourceLocation qmlLocation )

Converts a QQmlJS::SourceLocation to a LSP Range.

QQmlJS::SourceLocation starts counting lines and rows at 1, but the LSP Range starts at 0. Also, the QQmlJS::SourceLocation contains startLine, startColumn and length while the LSP Range contains startLine, startColumn, endLine and endColumn, which must be computed from the actual qml code.

Definition at line 149 of file qqmllsutils.cpp.

References QString::end(), qmlLocationToLspLocation(), and textRowAndColumnFrom().

Referenced by QQmlFindUsagesSupport::process(), QmlGoToDefinitionSupport::process(), QmlGoToTypeDefinitionSupport::process(), QQmlRenameSymbolSupport::process(), and qmlLocationToLspLocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qmlUrlToLspUri()

QByteArray QQmlLSUtils::qmlUrlToLspUri ( const QByteArray & url)

Definition at line 135 of file qqmllsutils.cpp.

References qmlUrlToLspUri(), and url.

Referenced by qmlUrlToLspUri().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qualifiersFrom()

QString QQmlLSUtils::qualifiersFrom ( const DomItem & el)

Definition at line 36 of file qqmllsutils.cpp.

References el, fieldMemberExpressionBits(), isFieldMemberAccess(), isFieldMemberExpression(), item, and qualifiersFrom().

Referenced by qualifiersFrom(), QQmlLSQuickCompletionPlugin::suggestSnippetsForLeftHandSideOfBinding(), and QQmlLSQuickCompletionPlugin::suggestSnippetsForRightHandSideOfBinding().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renameUsagesOf()

RenameUsages QQmlLSUtils::renameUsagesOf ( const DomItem & item,
const QString & dirtyNewName,
const std::optional< ExpressionType > & targetType )

Rename the appearance of item to newName.

Special cases: \list

  • Renaming a property changed signal or property changed handler does the same as renaming the underlying property, except that newName gets \list
  • its "on"-prefix and "Changed"-suffix chopped of if item is a property changed handlers
  • its "Changed"-suffix chopped of if item is a property changed signals \endlist
  • Renaming a signal handler does the same as renaming a signal, but the "on"-prefix in newName is chopped of.

All of the chopping operations are done using the static helpers from QQmlSignalNames. \endlist

Definition at line 2013 of file qqmllsutils.cpp.

References QDir::cleanPath(), edit, extension(), findUsagesOf(), info, item, newNameFrom(), oldNameFrom(), QQmlSignalNames::propertyNameToChangedHandlerName(), QQmlSignalNames::propertyNameToChangedSignalName(), qCDebug, renameUsagesOf(), resolveExpressionType(), resolveNameInQmlScope(), and QQmlSignalNames::signalNameToHandlerName().

Referenced by QQmlRenameSymbolSupport::process(), and renameUsagesOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveExpressionType()

◆ resolveFieldMemberExpressionType()

static std::optional< ExpressionType > QQmlLSUtils::resolveFieldMemberExpressionType ( const DomItem & item,
ResolveOptions options )
static

Definition at line 1251 of file qqmllsutils.cpp.

References EnumeratorIdentifier, EnumeratorValueIdentifier, QQmlJS::Dom::DomItem::field(), it, item, methodFromReferrerScope(), propertyBindingFromReferrerScope(), propertyFromReferrerScope(), qCDebug, QmlComponentIdentifier, resolveExpressionType(), and resolveFieldMemberExpressionType().

Referenced by resolveFieldMemberExpressionType(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveIdentifierExpressionType()

static std::optional< ExpressionType > QQmlLSUtils::resolveIdentifierExpressionType ( const DomItem & item,
ResolveOptions options )
static

Definition at line 1302 of file qqmllsutils.cpp.

References AssumeComponentsAreBound, findJSIdentifierDefinition(), isFieldMemberAccess(), item, methodFromReferrerScope(), propertyBindingFromReferrerScope(), propertyFromReferrerScope(), Q_ASSERT_X, QmlComponentIdentifier, QmlObjectIdIdentifier, resolveFieldMemberExpressionType(), and resolveIdentifierExpressionType().

Referenced by resolveExpressionType(), and resolveIdentifierExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveNameInQmlScope()

static std::optional< SignalOrProperty > QQmlLSUtils::resolveNameInQmlScope ( const QString & name,
const QQmlJSScope::ConstPtr & owner )
static

Find out if {name} is a signal, signal handler, property, property changed signal, or a property changed handler in the given QQmlJSScope.

Heuristic to find if name is a property, property changed signal, .... because those can appear under different names, for example {mySignal} and {onMySignal} for a signal. This will give incorrect results as soon as properties/signals/methods are called {onMySignal}, {on<some already existing property>Changed}, ..., but the good news is that the engine also will act weird in these cases (e.g. one cannot bind to a property called like an already existing signal or a property changed handler). For future reference: you can always add additional checks to check the existence of those buggy properties/signals/methods by looking if they exist in the QQmlJSScope.

Definition at line 617 of file qqmllsutils.cpp.

References QQmlSignalNames::changedHandlerNameToPropertyName(), QQmlSignalNames::changedSignalNameToPropertyName(), QQmlSignalNames::handlerNameToSignalName(), QQmlJSScope::hasProperty(), MethodIdentifier, QQmlJSScope::methods(), methods, PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, resolveNameInQmlScope(), SignalHandlerIdentifier, and SignalIdentifier.

Referenced by namesOfPossibleUsages(), propertyFromReferrerScope(), renameUsagesOf(), resolveExpressionType(), resolveNameInQmlScope(), and resolveSignalOrPropertyExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveSignalOrPropertyExpressionType()

static std::optional< ExpressionType > QQmlLSUtils::resolveSignalOrPropertyExpressionType ( const QString & name,
const QQmlJSScope::ConstPtr & scope,
ResolveOptions options )
static

Definition at line 1379 of file qqmllsutils.cpp.

References findDefiningScopeForMethod(), findDefiningScopeForProperty(), MethodIdentifier, QQmlJSScope::property(), PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, ResolveActualTypeForFieldMemberExpression, resolveNameInQmlScope(), ResolveOwnerType, resolveSignalOrPropertyExpressionType(), SignalHandlerIdentifier, SignalIdentifier, and QQmlJSMetaProperty::type().

Referenced by resolveExpressionType(), and resolveSignalOrPropertyExpressionType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sourceLocationToDomItem()

DomItem QQmlLSUtils::sourceLocationToDomItem ( const DomItem & file,
const QQmlJS::SourceLocation & location )

Definition at line 1645 of file qqmllsutils.cpp.

References QList< T >::back(), file, QList< T >::front(), items, itemsFromTextLocation(), Q_ASSERT_X, qDebug, QList< T >::size(), and sourceLocationToDomItem().

Referenced by findDefinitionOf(), findMethodDefinitionOf(), findPropertyDefinitionOf(), findTypeDefinitionOf(), and sourceLocationToDomItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textOffsetFrom()

qsizetype QQmlLSUtils::textOffsetFrom ( const QString & text,
int row,
int column )

Convert a text position from (line, column) into an offset.

Row, Column and the offset are all 0-based. For example, {s[textOffsetFrom(s, 5, 55)]} returns the character of s at line 5 and column 55.

See also
QQmlLSUtils::textRowAndColumnFrom

Definition at line 172 of file qqmllsutils.cpp.

References QString::at(), i, QString::size(), text, and textOffsetFrom().

Referenced by CompletionRequest::completions(), QQmlLSUtils::Location::from(), itemsFromTextLocation(), SemanticTokenRangeHandler::process(), QQmlRangeFormatting::process(), and textOffsetFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textRowAndColumnFrom()

TextPosition QQmlLSUtils::textRowAndColumnFrom ( const QString & text,
qsizetype offset )

Convert a text position from an offset into (line, column).

Row, Column and the offset are all 0-based. For example, {textRowAndColumnFrom(s, 55)} returns the line and columns of the character at {s[55]}.

See also
QQmlLSUtils::textOffsetFrom

Definition at line 209 of file qqmllsutils.cpp.

References i, text, and textRowAndColumnFrom().

Referenced by QQmlDocumentFormatting::process(), QQmlRangeFormatting::process(), qmlLocationToLspLocation(), and textRowAndColumnFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: