Qt 6.x
The Qt SDK
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 (QQmlJS::Dom::DomItem file, int line, int character)
 Find the DomItem representing the object situated in file at given line and character/column.
 
static QQmlJS::Dom::DomItem sourceLocationToDomItem (QQmlJS::Dom::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 QQmlJS::Dom::DomItem baseObject (QQmlJS::Dom::DomItem qmlObject)
 
static QQmlJS::Dom::DomItem findTypeDefinitionOf (QQmlJS::Dom::DomItem item)
 Extracts the QML object type of an \l DomItem.
 
static std::optional< QQmlLSUtilsLocationfindDefinitionOf (QQmlJS::Dom::DomItem item)
 
static QList< QQmlLSUtilsLocationfindUsagesOf (QQmlJS::Dom::DomItem item)
 
static QQmlJSScope::ConstPtr resolveExpressionType (QQmlJS::Dom::DomItem item, QQmlLSUtilsResolveOptions)
 

Detailed Description

Definition at line 67 of file qqmllsutils_p.h.

Member Function Documentation

◆ baseObject()

DomItem QQmlLSUtils::baseObject ( QQmlJS::Dom::DomItem  qmlObject)
static

Definition at line 268 of file qqmllsutils.cpp.

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

Referenced by findTypeDefinitionOf().

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

◆ findDefinitionOf()

std::optional< QQmlLSUtilsLocation > QQmlLSUtils::findDefinitionOf ( QQmlJS::Dom::DomItem  item)
static

Definition at line 789 of file qqmllsutils.cpp.

References canonicalPath(), file, findJSIdentifierDefinition(), findMethodDefinitionOf(), findMethodIn(), findPropertyDefinitionOf(), findPropertyIn(), isFieldMemberAccess(), item, JustOwner, Q_ASSERT_X, qDebug, resolveExpressionType(), QQmlJS::Dom::ScriptIdentifierExpression, and QQmlJSScope::sourceLocation().

Referenced by QmlGoToDefinitionSupport::process().

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

◆ findTypeDefinitionOf()

DomItem QQmlLSUtils::findTypeDefinitionOf ( QQmlJS::Dom::DomItem  item)
static

Extracts the QML object type of an \l DomItem.

For a PropertyDefinition, return the type of the property. For a Binding, return the bound item's type if an QmlObject is bound, and otherwise the type of the property. For a QmlObject, do nothing and return it. For an Id, return the object to which the id resolves. For a Methodparameter, return the type of the parameter. = Otherwise, return an empty item.

Definition at line 300 of file qqmllsutils.cpp.

References baseObject(), QQmlJS::Dom::Binding, QQmlJS::Dom::Empty, Everything, QQmlJS::Dom::DomItem::field(), QQmlJS::Dom::DomItem::filterUp(), QQmlJS::Dom::Id, item, QQmlJS::Dom::Paths::lookupTypePath(), QQmlJS::Dom::MethodInfo, QQmlJS::Dom::MethodParameter, QQmlJS::Dom::DomItem::proceedToScope(), QQmlJS::Dom::PropertyDefinition, Q_ASSERT, qDebug, QQmlJS::Dom::QmlComponent, QQmlJS::Dom::QmlObject, resolveExpressionType(), QQmlJS::Dom::ScriptIdentifierExpression, 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 ( QQmlJS::Dom::DomItem  item)
static

Definition at line 514 of file qqmllsutils.cpp.

References findUsagesHelper(), item, and qCDebug.

Referenced by QQmlFindUsagesSupport::process().

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

◆ itemsFromTextLocation()

QList< QQmlLSUtilsItemLocation > QQmlLSUtils::itemsFromTextLocation ( QQmlJS::Dom::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 176 of file qqmllsutils.cpp.

References QList< T >::append(), QList< T >::begin(), QSet< T >::begin(), QQmlJS::SourceLocation::begin(), QQmlLSUtilsItemLocation::domItem, QList< T >::end(), QSet< T >::end(), QQmlJS::SourceLocation::end(), file, QQmlLSUtilsItemLocation::fileLocation, QList< T >::isEmpty(), it, QList< T >::last(), line, QQmlJS::Dom::DomItem::path(), Q_ASSERT, qCDebug, QList< T >::removeLast(), QList< T >::size(), and textOffsetFrom().

Referenced by CompletionRequest::completions(), 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 69 of file qqmllsutils.cpp.

Referenced by WorkspaceHandlers::clientInitialized(), TextSynchronization::didCloseTextDocument(), TextSynchronization::didDidChangeTextDocument(), TextSynchronization::didOpenTextDocument(), QQmlBaseModule< RequestType >::itemsForRequest(), QQmlDocumentFormatting::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 88 of file qqmllsutils.cpp.

References QQmlJS::SourceLocation::end(), QQmlJS::SourceLocation::startColumn, QQmlJS::SourceLocation::startLine, and textRowAndColumnFrom().

Referenced by QQmlFindUsagesSupport::process(), QmlGoToDefinitionSupport::process(), and QmlGoToTypeDefinitionSupport::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 74 of file qqmllsutils.cpp.

References url.

◆ resolveExpressionType()

QQmlJSScope::ConstPtr QQmlLSUtils::resolveExpressionType ( QQmlJS::Dom::DomItem  item,
QQmlLSUtilsResolveOptions  options 
)
static

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

Definition at line 588 of file qqmllsutils.cpp.

References Everything, findJSIdentifierDefinition(), findMethodIn(), findPropertyIn(), isFieldMemberAccess(), isFieldMemberExpression(), item, JustOwner, parent, property, Q_ASSERT_X, qCDebug, resolveExpressionType(), QQmlJS::Dom::DomItem::semanticScope(), QQmlJS::Dom::MethodInfo::semanticScope(), and QQmlJS::Dom::QmlObject::semanticScope().

Referenced by findDefinitionOf(), findTypeDefinitionOf(), findUsagesOfNonJSIdentifiers(), and resolveExpressionType().

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

◆ sourceLocationToDomItem()

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

Definition at line 718 of file qqmllsutils.cpp.

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

Referenced by 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 111 of file qqmllsutils.cpp.

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

Referenced by CompletionRequest::completions(), and itemsFromTextLocation().

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

References i, and text.

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

+ Here is the caller graph for this function:

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