Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
class  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 : quint8 {
  NotAnIdentifier , JavaScriptIdentifier , PropertyIdentifier , PropertyChangedSignalIdentifier ,
  PropertyChangedHandlerIdentifier , SignalIdentifier , SignalHandlerIdentifier , MethodIdentifier ,
  LambdaMethodIdentifier , QmlObjectIdIdentifier , SingletonIdentifier , EnumeratorIdentifier ,
  EnumeratorValueIdentifier , AttachedTypeIdentifier , AttachedTypeIdentifierInBindingTarget , GroupedPropertyIdentifier ,
  QmlComponentIdentifier , QualifiedModuleIdentifier
}
enum  ResolveOptions { ResolveOwnerType , ResolveActualTypeForFieldMemberExpression }
enum  SearchOption { FindFirst , FindAll , FindFirst , FindAll }
enum  SearchOption { FindFirst , FindAll , FindFirst , FindAll }

Functions

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).
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 sourceLocationToDomItem (const DomItem &file, const QQmlJS::SourceLocation &location)
QByteArray lspUriToQmlUrl (const QByteArray &uri)
QByteArray qmlUrlToLspUri (const QByteArray &url)
QLspSpecification::Range qmlLocationToLspLocation (Location qmlLocation)
 Converts a QQmlJS::SourceLocation to a LSP Range.
DomItem baseObject (const DomItem &qmlObject)
std::optional< LocationfindTypeDefinitionOf (const DomItem &object)
 Returns the location of the type definition pointed by object.
std::optional< LocationfindDefinitionOf (const DomItem &item, const QStringList &headerDirectories)
Usages findUsagesOf (const DomItem &item)
std::optional< ErrorMessagecheckNameForRename (const DomItem &item, const QString &newName, const std::optional< ExpressionType > &targetType=std::nullopt)
RenameUsages renameUsagesOf (const DomItem &item, const QString &dirtyNewName, const std::optional< ExpressionType > &targetType)
 Rename the appearance of item to newName.
std::optional< ExpressionTyperesolveExpressionType (const QQmlJS::Dom::DomItem &item, ResolveOptions options)
 Resolves the type of the given DomItem, when possible (e.g., when there are enough type annotations).
bool isValidEcmaScriptIdentifier (QStringView view)
std::pair< QString, QStringListcmakeBuildCommand (const QString &path)
bool isFieldMemberExpression (const DomItem &item)
bool isFieldMemberAccess (const DomItem &item)
bool isFieldMemberBase (const DomItem &item)
QStringList fieldMemberExpressionBits (const DomItem &item, const DomItem &stopAtChild={})
QString qualifiersFrom (const DomItem &el)
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)
QStringList findFilePathsFromFileNames (const QString &rootDir, const QStringList &fileNamesToSearch, const QSet< QString > &ignoredPaths)
QString findFilePathFromFileName (const QStringList &rootDirs, const QString &fileNameToSearch, const QSet< QString > &ignoredPaths)
static QList< ItemLocation >::const_iterator handlePropertyDefinitionAndBindingOverlap (const QList< ItemLocation > &items, qsizetype offsetInFile)
static QList< ItemLocationfilterItemsFromTextLocation (const QList< ItemLocation > &items, qsizetype offsetInFile)
static std::optional< LocationlocationFromDomItem (const DomItem &item, FileLocationRegion region)
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)
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 std::optional< LocationlocationFromJSIdentifierDefinition (const DomItem &definitionOfItem, const QString &name)
static void findUsagesHelper (const DomItem &item, const QString &name, Usages &result)
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< ExpressionTyperesolveTypeName (const std::shared_ptr< QQmlJSTypeResolver > &resolver, const QString &name, const DomItem &item, ResolveOptions options)
 Distinguishes singleton types from attached types and "regular" qml components.
static std::optional< ExpressionTyperesolveFieldMemberExpressionType (const DomItem &item, ResolveOptions options)
static std::optional< ExpressionTyperesolveBindingIfSignalHandler (const DomItem &functionExpression)
static std::optional< ExpressionTyperesolveSignalHandlerParameterType (const DomItem &parameterDefinition, const QString &name, ResolveOptions options)
static std::optional< ExpressionTyperesolveIdentifierExpressionType (const DomItem &item, ResolveOptions options)
static std::optional< ExpressionTyperesolveSignalOrPropertyExpressionType (const QString &name, const QQmlJSScope::ConstPtr &scope, ResolveOptions options)
static std::optional< LocationfindEnumDefinitionOf (const DomItem &file, QQmlJS::SourceLocation location, const QString &name)
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)
static QQmlJS::SourceLocation sourceLocationOrDefault (const QQmlJS::SourceLocation &location)
static std::optional< LocationcreateCppTypeLocation (const QQmlJSScope::ConstPtr &type, const QStringList &headerLocations, const QQmlJS::SourceLocation &location)
static std::optional< LocationfindDefinitionOfType (const QQmlJSScope::ConstPtr &scope, const DomItem &item, const QStringList &headerDirectories)
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)
static std::optional< QStringoldNameFrom (const DomItem &item)
static std::optional< QStringnewNameFrom (const QString &dirtyNewName, IdentifierType alternative)
static QStringList findFilePathsFromFileNamesImpl (const QStringList &rootDirs, const QStringList &fileNamesToSearch, SearchOption option, const QSet< QString > &ignoredFilePaths)

Typedef Documentation

◆ DomItem

Definition at line 259 of file qqmllsutils_p.h.

Enumeration Type Documentation

◆ IdentifierType

Enumerator
NotAnIdentifier 
JavaScriptIdentifier 
PropertyIdentifier 
PropertyChangedSignalIdentifier 
PropertyChangedHandlerIdentifier 
SignalIdentifier 
SignalHandlerIdentifier 
MethodIdentifier 
LambdaMethodIdentifier 
QmlObjectIdIdentifier 
SingletonIdentifier 
EnumeratorIdentifier 
EnumeratorValueIdentifier 
AttachedTypeIdentifier 
AttachedTypeIdentifierInBindingTarget 
GroupedPropertyIdentifier 
QmlComponentIdentifier 
QualifiedModuleIdentifier 

Definition at line 45 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 254 of file qqmllsutils_p.h.

◆ SearchOption [1/2]

Enumerator
FindFirst 
FindAll 
FindFirst 
FindAll 

Definition at line 2554 of file qqmllsutils.cpp.

◆ SearchOption [2/2]

Enumerator
FindFirst 
FindAll 
FindFirst 
FindAll 

Definition at line 2554 of file qqmllsutils.cpp.

Function Documentation

◆ baseObject()

DomItem QQmlLSUtils::baseObject ( const DomItem & qmlObject)

Definition at line 394 of file qqmllsutils.cpp.

◆ checkNameForRename()

std::optional< ErrorMessage > QQmlLSUtils::checkNameForRename ( const DomItem & item,
const QString & newName,
const std::optional< ExpressionType > & targetType = std::nullopt )

◆ cmakeBuildCommand()

std::pair< 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 2520 of file qqmllsutils.cpp.

◆ createCppTypeLocation()

std::optional< Location > QQmlLSUtils::createCppTypeLocation ( const QQmlJSScope::ConstPtr & type,
const QStringList & headerLocations,
const QQmlJS::SourceLocation & location )
static

Definition at line 1994 of file qqmllsutils.cpp.

◆ expressionTypeWithDefinition()

◆ 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 112 of file qqmllsutils.cpp.

◆ filterForFindUsages()

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 825 of file qqmllsutils.cpp.

◆ filterItemsFromTextLocation()

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

Definition at line 266 of file qqmllsutils.cpp.

◆ 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 770 of file qqmllsutils.cpp.

◆ findDefiningScopeForEnumeration()

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

See also findDefiningScopeForProperty().

Definition at line 794 of file qqmllsutils.cpp.

◆ findDefiningScopeForEnumerationKey()

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

See also findDefiningScopeForProperty().

Definition at line 806 of file qqmllsutils.cpp.

◆ findDefiningScopeForMethod()

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

See also findDefiningScopeForProperty().

Definition at line 782 of file qqmllsutils.cpp.

◆ 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 756 of file qqmllsutils.cpp.

◆ findDefiningScopeIf()

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

Definition at line 733 of file qqmllsutils.cpp.

◆ findDefinitionFromItem()

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

Definition at line 549 of file qqmllsutils.cpp.

◆ findDefinitionOf()

◆ findDefinitionOfType()

std::optional< Location > QQmlLSUtils::findDefinitionOfType ( const QQmlJSScope::ConstPtr & scope,
const DomItem & item,
const QStringList & headerDirectories )
static

Definition at line 2008 of file qqmllsutils.cpp.

◆ findEnumDefinitionOf()

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

Definition at line 1915 of file qqmllsutils.cpp.

◆ findFilePathFromFileName()

QString QQmlLSUtils::findFilePathFromFileName ( const QStringList & rootDirs,
const QString & fileNameToSearch,
const QSet< QString > & ignoredPaths )

Definition at line 2619 of file qqmllsutils.cpp.

◆ findFilePathsFromFileNames()

QStringList QQmlLSUtils::findFilePathsFromFileNames ( const QString & rootDir,
const QStringList & fileNamesToSearch,
const QSet< QString > & ignoredPaths )

Definition at line 2612 of file qqmllsutils.cpp.

◆ findFilePathsFromFileNamesImpl()

QStringList QQmlLSUtils::findFilePathsFromFileNamesImpl ( const QStringList & rootDirs,
const QStringList & fileNamesToSearch,
SearchOption option,
const QSet< QString > & ignoredFilePaths )
static

Definition at line 2555 of file qqmllsutils.cpp.

◆ findJSIdentifierDefinition()

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

Definition at line 561 of file qqmllsutils.cpp.

◆ findMethodDefinitionOf()

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

Definition at line 1952 of file qqmllsutils.cpp.

◆ findPropertyDefinitionOf()

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

Definition at line 1970 of file qqmllsutils.cpp.

◆ findScopeOfSpecialItems()

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 1218 of file qqmllsutils.cpp.

◆ 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 447 of file qqmllsutils.cpp.

References QmlObjectIdIdentifier.

◆ findUsagesHelper()

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

Definition at line 961 of file qqmllsutils.cpp.

References QQmlLSUtils::Usages::appendUsage().

Here is the call graph for this function:

◆ findUsagesOf()

Usages QQmlLSUtils::findUsagesOf ( const DomItem & item)

Definition at line 1009 of file qqmllsutils.cpp.

References QQmlLSUtils::Usages::sort().

Here is the call graph for this function:

◆ findUsagesOfNonJSIdentifiers()

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

Definition at line 836 of file qqmllsutils.cpp.

References QQmlLSUtils::Usages::appendUsage(), and QmlComponentIdentifier.

Here is the call graph for this function:

◆ handlePropertyDefinitionAndBindingOverlap()

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

Definition at line 217 of file qqmllsutils.cpp.

◆ hasMethodOrSignal()

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

Definition at line 1065 of file qqmllsutils.cpp.

References MethodIdentifier, and SignalIdentifier.

◆ isFieldMemberAccess()

bool QQmlLSUtils::isFieldMemberAccess ( const DomItem & item)

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

Definition at line 68 of file qqmllsutils.cpp.

◆ isFieldMemberBase()

bool QQmlLSUtils::isFieldMemberBase ( const DomItem & item)

Helper to check if item is a Field Member Base base in {base.memberAccess}.

Definition at line 83 of file qqmllsutils.cpp.

◆ isFieldMemberExpression()

bool QQmlLSUtils::isFieldMemberExpression ( const DomItem & item)

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

Definition at line 56 of file qqmllsutils.cpp.

◆ isValidEcmaScriptIdentifier()

bool QQmlLSUtils::isValidEcmaScriptIdentifier ( QStringView view)

Definition at line 2494 of file qqmllsutils.cpp.

◆ 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.

We usually assume that sourcelocations have inclusive ends, for example we assume that auto-completion on \n in someName\n wants suggestions for someName, even if its technically one position "outside" the sourcelocation of someName. This is not true for ScriptBinaryExpressions, where auto-completion on . in someName. should not return suggestions for someName. The same also applies to all other binary expressions +, -, and so on.

Definition at line 318 of file qqmllsutils.cpp.

◆ locationFromDomItem()

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

Definition at line 421 of file qqmllsutils.cpp.

◆ locationFromJSIdentifierDefinition()

std::optional< Location > QQmlLSUtils::locationFromJSIdentifierDefinition ( const DomItem & definitionOfItem,
const QString & name )
static

Definition at line 947 of file qqmllsutils.cpp.

◆ 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 153 of file qqmllsutils.cpp.

◆ methodFromReferrerScope()

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 1089 of file qqmllsutils.cpp.

References ResolveActualTypeForFieldMemberExpression, and SignalHandlerIdentifier.

◆ methodOwnerFrom()

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

Definition at line 2163 of file qqmllsutils.cpp.

◆ namesOfPossibleUsages()

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 677 of file qqmllsutils.cpp.

References PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, SignalHandlerIdentifier, and SignalIdentifier.

◆ newNameFrom()

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

◆ oldNameFrom()

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

Definition at line 2301 of file qqmllsutils.cpp.

◆ propertyBindingFromReferrerScope()

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 1159 of file qqmllsutils.cpp.

References AttachedTypeIdentifierInBindingTarget, GroupedPropertyIdentifier, ResolveActualTypeForFieldMemberExpression, and ResolveOwnerType.

◆ propertyFromReferrerScope()

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 1129 of file qqmllsutils.cpp.

References ResolveActualTypeForFieldMemberExpression.

◆ propertyOwnerFrom()

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

Definition at line 2144 of file qqmllsutils.cpp.

◆ qmlLocationToLspLocation()

QLspSpecification::Range QQmlLSUtils::qmlLocationToLspLocation ( Location 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.

Definition at line 169 of file qqmllsutils.cpp.

References QQmlLSUtils::TextPosition::character, QQmlLSUtils::Location::end(), and QQmlLSUtils::TextPosition::line.

Here is the call graph for this function:

◆ qmlUrlToLspUri()

QByteArray QQmlLSUtils::qmlUrlToLspUri ( const QByteArray & url)

Definition at line 158 of file qqmllsutils.cpp.

◆ qualifiersFrom()

QString QQmlLSUtils::qualifiersFrom ( const DomItem & el)

Definition at line 34 of file qqmllsutils.cpp.

◆ 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 2364 of file qqmllsutils.cpp.

References QQmlLSUtils::Usages::isEmpty().

Here is the call graph for this function:

◆ resolveBindingIfSignalHandler()

std::optional< ExpressionType > QQmlLSUtils::resolveBindingIfSignalHandler ( const DomItem & functionExpression)
static

Resolves the expression type of a binding for signal handlers, like the function expression {(x) => ...} in

\qml onHelloSignal: (x) => ... \endqml

would be resolved to the {onHelloSignal} expression type, for example.

Definition at line 1405 of file qqmllsutils.cpp.

◆ resolveExpressionType()

std::optional< ExpressionType > QQmlLSUtils::resolveExpressionType ( const QQmlJS::Dom::DomItem & item,
ResolveOptions options )

Resolves the type of the given DomItem, when possible (e.g., when there are enough type annotations).

Might return an ExpressionType without(!) semantic scope when no type information is available, for example resolving the type of x in someJSObject.x (where let someJSObject = { x: 42 };) then the name and type of x is known but no semantic scope can be obtained.

Definition at line 1633 of file qqmllsutils.cpp.

References GroupedPropertyIdentifier, JavaScriptIdentifier, LambdaMethodIdentifier, MethodIdentifier, NotAnIdentifier, PropertyIdentifier, QmlComponentIdentifier, QmlObjectIdIdentifier, ResolveActualTypeForFieldMemberExpression, and ResolveOwnerType.

◆ resolveFieldMemberExpressionType()

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

◆ resolveIdentifierExpressionType()

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

◆ resolveNameInQmlScope()

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 629 of file qqmllsutils.cpp.

References MethodIdentifier, PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, SignalHandlerIdentifier, and SignalIdentifier.

◆ resolveSignalHandlerParameterType()

std::optional< ExpressionType > QQmlLSUtils::resolveSignalHandlerParameterType ( const DomItem & parameterDefinition,
const QString & name,
ResolveOptions options )
static

In a signal handler

\qml onSomeSignal: (x, y, z) => .... \endqml

the parameters x, y and z are not allowed to have type annotations: instead, their type is defined by the signal definition itself.

This code detects signal handler parameters and resolves their type using the signal's definition.

Definition at line 1436 of file qqmllsutils.cpp.

References JavaScriptIdentifier, PropertyChangedHandlerIdentifier, ResolveOwnerType, and SignalHandlerIdentifier.

◆ resolveSignalOrPropertyExpressionType()

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

◆ resolveTypeName()

std::optional< ExpressionType > QQmlLSUtils::resolveTypeName ( const std::shared_ptr< QQmlJSTypeResolver > & resolver,
const QString & name,
const DomItem & item,
ResolveOptions options )
static

Distinguishes singleton types from attached types and "regular" qml components.

Definition at line 1281 of file qqmllsutils.cpp.

References AttachedTypeIdentifier, QmlComponentIdentifier, ResolveOwnerType, and SingletonIdentifier.

◆ sourceLocationOrDefault()

QQmlJS::SourceLocation QQmlLSUtils::sourceLocationOrDefault ( const QQmlJS::SourceLocation & location)
static

Definition at line 1989 of file qqmllsutils.cpp.

◆ sourceLocationToDomItem()

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

Definition at line 1879 of file qqmllsutils.cpp.

◆ 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 190 of file qqmllsutils.cpp.

◆ 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 205 of file qqmllsutils.cpp.