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 Class Reference

#include <qqmllsutils_p.h>

+ Collaboration diagram for QQmlLSUtils:

Static Public Member Functions

static qsizetype textOffsetFrom (const QString &code, int row, int character)
 Convert a text position from (line, column) into an offset.
 
static QQmlLSUtilsTextPosition textRowAndColumnFrom (const QString &code, qsizetype offset)
 Convert a text position from an offset into (line, column).
 
static QList< QQmlLSUtilsItemLocationitemsFromTextLocation (const DomItem &file, int line, int character)
 Find the DomItem representing the object situated in file at given line and character/column.
 
static DomItem sourceLocationToDomItem (const DomItem &file, const QQmlJS::SourceLocation &location)
 
static QByteArray lspUriToQmlUrl (const QByteArray &uri)
 
static QByteArray qmlUrlToLspUri (const QByteArray &url)
 
static QLspSpecification::Range qmlLocationToLspLocation (const QString &code, QQmlJS::SourceLocation qmlLocation)
 Converts a QQmlJS::SourceLocation to a LSP Range.
 
static DomItem baseObject (const DomItem &qmlObject)
 
static std::optional< QQmlLSUtilsLocationfindTypeDefinitionOf (const DomItem &item)
 Returns the location of the type definition pointed by object.
 
static std::optional< QQmlLSUtilsLocationfindDefinitionOf (const DomItem &item)
 
static QList< QQmlLSUtilsLocationfindUsagesOf (const DomItem &item)
 
static std::optional< QQmlLSUtilsErrorMessagecheckNameForRename (const DomItem &item, const QString &newName, const std::optional< QQmlLSUtilsExpressionType > &targetType=std::nullopt)
 
static QList< QQmlLSUtilsEditrenameUsagesOf (const DomItem &item, const QString &newName, const std::optional< QQmlLSUtilsExpressionType > &targetType=std::nullopt)
 Rename the appearance of item to newName.
 
static std::optional< QQmlLSUtilsExpressionTyperesolveExpressionType (const DomItem &item, QQmlLSUtilsResolveOptions)
 
static bool isValidEcmaScriptIdentifier (QStringView view)
 
static QPair< QString, QStringListcmakeBuildCommand (const QString &path)
 
static QByteArray getDocumentationFromLocation (const DomItem &file, const QQmlLSUtilsTextPosition &position)
 
static bool isFieldMemberExpression (const DomItem &item)
 
static bool isFieldMemberAccess (const DomItem &item)
 
static QStringList fieldMemberExpressionBits (const DomItem &item, const DomItem &stopAtChild={})
 
static QString qualifiersFrom (const DomItem &el)
 

Detailed Description

Definition at line 134 of file qqmllsutils_p.h.

Member Function Documentation

◆ baseObject()

DomItem QQmlLSUtils::baseObject ( const DomItem & qmlObject)
static

Definition at line 393 of file qqmllsutils.cpp.

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

Referenced by findTypeDefinitionOf().

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

◆ checkNameForRename()

std::optional< QQmlLSUtilsErrorMessage > QQmlLSUtils::checkNameForRename ( const DomItem & item,
const QString & newName,
const std::optional< QQmlLSUtilsExpressionType > & targetType = std::nullopt )
static

Definition at line 1889 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)
static

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

◆ fieldMemberExpressionBits()

QStringList QQmlLSUtils::fieldMemberExpressionBits ( const DomItem & item,
const DomItem & stopAtChild = {} )
static

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(), isFieldMemberAccess(), isFieldMemberExpression(), item, QCborValue::toString(), and QQmlJS::Dom::DomItem::value().

Referenced by findTypeDefinitionOf(), and qualifiersFrom().

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

◆ findDefinitionOf()

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

◆ findTypeDefinitionOf()

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

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

References baseObject(), QQmlJS::Dom::Binding, QQmlJS::Dom::DomItem::field(), fieldMemberExpressionBits(), 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, ResolveActualTypeForFieldMemberExpression, resolveExpressionType(), QQmlJS::Dom::ScriptIdentifierExpression, QQmlLSUtilsLocation::sourceLocation, and sourceLocationToDomItem().

Referenced by QmlGoToTypeDefinitionSupport::process().

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

◆ findUsagesOf()

QList< QQmlLSUtilsLocation > QQmlLSUtils::findUsagesOf ( const DomItem & item)
static

Definition at line 985 of file qqmllsutils.cpp.

References findUsagesHelper(), item, and qCDebug.

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

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

◆ getDocumentationFromLocation()

QByteArray QQmlLSUtils::getDocumentationFromLocation ( const DomItem & file,
const QQmlLSUtilsTextPosition & position )
static

Definition at line 2170 of file qqmllsutils.cpp.

References file, itemsFromTextLocation(), line, position(), and Q_UNUSED.

Referenced by QQmlHover::process().

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

◆ isFieldMemberAccess()

bool QQmlLSUtils::isFieldMemberAccess ( const DomItem & item)
static

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(), isFieldMemberExpression(), and item.

Referenced by fieldMemberExpressionBits(), 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)
static

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, and item.

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

+ Here is the caller graph for this function:

◆ isValidEcmaScriptIdentifier()

bool QQmlLSUtils::isValidEcmaScriptIdentifier ( QStringView view)
static

Definition at line 2135 of file qqmllsutils.cpp.

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

Referenced by checkNameForRename().

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

◆ itemsFromTextLocation()

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

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

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

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

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

◆ lspUriToQmlUrl()

QByteArray QQmlLSUtils::lspUriToQmlUrl ( const QByteArray & uri)
static

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.

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

+ Here is the caller graph for this function:

◆ qmlLocationToLspLocation()

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

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(), and textRowAndColumnFrom().

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

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

◆ qmlUrlToLspUri()

QByteArray QQmlLSUtils::qmlUrlToLspUri ( const QByteArray & url)
static

Definition at line 135 of file qqmllsutils.cpp.

References url.

◆ qualifiersFrom()

QT_BEGIN_NAMESPACE QString QQmlLSUtils::qualifiersFrom ( const DomItem & el)
static

Definition at line 36 of file qqmllsutils.cpp.

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

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

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

◆ renameUsagesOf()

QList< QQmlLSUtilsEdit > QQmlLSUtils::renameUsagesOf ( const DomItem & item,
const QString & dirtyNewName,
const std::optional< QQmlLSUtilsExpressionType > & targetType = std::nullopt )
static

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

References QList< T >::append(), edit, findUsagesOf(), item, newNameFrom(), oldNameFrom(), QQmlSignalNames::propertyNameToChangedHandlerName(), QQmlSignalNames::propertyNameToChangedSignalName(), qCDebug, resolveExpressionType(), resolveNameInQmlScope(), ResolveOwnerType, results, and QQmlSignalNames::signalNameToHandlerName().

Referenced by QQmlRenameSymbolSupport::process().

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

◆ resolveExpressionType()

◆ sourceLocationToDomItem()

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

Definition at line 1661 of file qqmllsutils.cpp.

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

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

+ 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 )
static

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(), and text.

Referenced by CompletionRequest::completions(), QQmlLSUtilsLocation::from(), itemsFromTextLocation(), and QQmlRangeFormatting::process().

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

◆ textRowAndColumnFrom()

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

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, and text.

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

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: