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>.
|
#include <qqmllsutils_p.h>
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< QQmlLSUtilsItemLocation > | itemsFromTextLocation (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< QQmlLSUtilsLocation > | findTypeDefinitionOf (const DomItem &item) |
Returns the location of the type definition pointed by object. | |
static std::optional< QQmlLSUtilsLocation > | findDefinitionOf (const DomItem &item) |
static QList< QQmlLSUtilsLocation > | findUsagesOf (const DomItem &item) |
static std::optional< QQmlLSUtilsErrorMessage > | checkNameForRename (const DomItem &item, const QString &newName, const std::optional< QQmlLSUtilsExpressionType > &targetType=std::nullopt) |
static QList< QQmlLSUtilsEdit > | renameUsagesOf (const DomItem &item, const QString &newName, const std::optional< QQmlLSUtilsExpressionType > &targetType=std::nullopt) |
Rename the appearance of item to newName. | |
static std::optional< QQmlLSUtilsExpressionType > | resolveExpressionType (const DomItem &item, QQmlLSUtilsResolveOptions) |
static bool | isValidEcmaScriptIdentifier (QStringView view) |
static QPair< QString, QStringList > | cmakeBuildCommand (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) |
Definition at line 134 of file qqmllsutils_p.h.
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().
|
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().
|
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.
|
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().
|
static |
Definition at line 1741 of file qqmllsutils.cpp.
References AttachedTypeIdentifier, QQmlJS::Dom::DomItem::component(), EnumeratorIdentifier, EnumeratorValueIdentifier, QQmlJS::Dom::DomItem::field(), findMethodDefinitionOf(), findPropertyDefinitionOf(), GroupedPropertyIdentifier, QQmlJS::Dom::DomItem::index(), item, JavaScriptIdentifier, QQmlJS::Dom::DomItem::key(), MethodIdentifier, PropertyChangedHandlerIdentifier, PropertyChangedSignalIdentifier, PropertyIdentifier, qCDebug, QmlComponentIdentifier, QmlObjectIdIdentifier, resolveExpressionType(), ResolveOwnerType, SignalHandlerIdentifier, SignalIdentifier, SingletonIdentifier, sourceLocationToDomItem(), and QQmlJS::Dom::FileLocations::treeOf().
Referenced by QmlGoToDefinitionSupport::process().
|
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().
|
static |
Definition at line 985 of file qqmllsutils.cpp.
References findUsagesHelper(), item, and qCDebug.
Referenced by QQmlFindUsagesSupport::process(), and renameUsagesOf().
|
static |
Definition at line 2170 of file qqmllsutils.cpp.
References file, itemsFromTextLocation(), line, position(), and Q_UNUSED.
Referenced by QQmlHover::process().
|
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().
|
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().
|
static |
Definition at line 2135 of file qqmllsutils.cpp.
References QQmlJS::Lexer::lex(), QQmlJS::Lexer::setCode(), token, and QStringView::toString().
Referenced by checkNameForRename().
|
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().
|
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.
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().
|
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().
|
static |
Definition at line 135 of file qqmllsutils.cpp.
References url.
|
static |
Definition at line 36 of file qqmllsutils.cpp.
References el, fieldMemberExpressionBits(), isFieldMemberAccess(), isFieldMemberExpression(), and item.
Referenced by QQmlLSQuickCompletionPlugin::suggestSnippetsForLeftHandSideOfBinding(), and QQmlLSQuickCompletionPlugin::suggestSnippetsForRightHandSideOfBinding().
|
static |
Rename the appearance of item to newName.
Special cases: \list
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().
|
static |
Resolves the type of the given DomItem, when possible (e.g., when there are enough type annotations).
Definition at line 1451 of file qqmllsutils.cpp.
References component(), EnumeratorIdentifier, EnumeratorValueIdentifier, findDefiningScopeForBinding(), findDefiningScopeForEnumeration(), findDefiningScopeForEnumerationKey(), findDefiningScopeForMethod(), findDefiningScopeForProperty(), findScopeOfSpecialItems(), GroupedPropertyIdentifier, isFieldMemberExpression(), item, QQmlLSUtilsExpressionType::name, PropertyIdentifier, qCDebug, qDebug, QmlComponentIdentifier, QmlObjectIdIdentifier, ResolveActualTypeForFieldMemberExpression, resolveExpressionType(), resolveIdentifierExpressionType(), resolveNameInQmlScope(), ResolveOwnerType, resolveSignalOrPropertyExpressionType(), and QQmlJS::Dom::AttributeInfo::semanticScope().
Referenced by checkNameForRename(), findDefinitionOf(), findTypeDefinitionOf(), findUsagesOfNonJSIdentifiers(), QQmlRenameSymbolSupport::process(), renameUsagesOf(), resolveExpressionType(), and resolveFieldMemberExpressionType().
|
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().
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.
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().
|
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]}.
Definition at line 209 of file qqmllsutils.cpp.
Referenced by QQmlDocumentFormatting::process(), QQmlRangeFormatting::process(), and qmlLocationToLspLocation().