Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmlfindusagessupport.cpp
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qqmlfindusagessupport_p.h"
6
#
include
"qqmllsutils_p.h"
7
#
include
<
QtLanguageServer
/
private
/
qlanguageserverspectypes_p
.
h
>
8
#
include
<
QtQmlDom
/
private
/
qqmldomexternalitems_p
.
h
>
9
#
include
<
QtQmlDom
/
private
/
qqmldomtop_p
.
h
>
10
#
include
<
variant
>
11
12
QT_BEGIN_NAMESPACE
13
14
using
namespace
Qt::StringLiterals;
15
16
QQmlFindUsagesSupport
::QQmlFindUsagesSupport(
QmlLsp
::
QQmlCodeModelManager
*codeModelManager)
17
: BaseT(codeModelManager)
18
{
19
}
20
21
void
QQmlFindUsagesSupport
::
setupCapabilities
(QLspSpecification::ServerCapabilities &caps)
22
{
23
// just assume caps.typeDefinitionProvider is a bool for now
24
// handle the ReferenceOptions later if needed (it adds the possibility to communicate the
25
// current progress).
26
caps.referencesProvider =
true
;
27
}
28
29
void
QQmlFindUsagesSupport
::
registerHandlers
(
QLanguageServer
*, QLanguageServerProtocol *protocol)
30
{
31
protocol->registerReferenceRequestHandler(getRequestHandler());
32
}
33
34
void
QQmlFindUsagesSupport
::
process
(QQmlFindUsagesSupport::RequestPointerArgument request)
35
{
36
QList<QLspSpecification::Location> results;
37
ResponseScopeGuard
guard(results, request->m_response);
38
39
auto
itemsFound = itemsForRequest(request);
40
if
(!itemsFound.has_value()) {
41
guard.setError(itemsFound.error());
42
return
;
43
}
44
45
QQmlLSUtils
::
ItemLocation
&front = itemsFound.value().front();
46
47
auto
usages = QQmlLSUtils::findUsagesOf(front.domItem);
48
49
QQmlJS::Dom::DomItem files = front.domItem.top().field(QQmlJS::Dom::Fields::qmlFileWithPath);
50
51
// note: ignore usages in filenames here as that is not supported by the protocol.
52
for
(
const
auto
&usage : usages.usagesInFile()) {
53
QLspSpecification::Location location;
54
location.uri = QUrl::fromLocalFile(usage.filename()).toEncoded();
55
location.range = QQmlLSUtils::qmlLocationToLspLocation(usage);
56
57
results.append(location);
58
}
59
}
60
QT_END_NAMESPACE
QLanguageServer
Implements a server for the language server protocol.
Definition
qlanguageserver_p.h:40
QQmlFindUsagesSupport
Definition
qqmlfindusagessupport_p.h:29
QQmlFindUsagesSupport::registerHandlers
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
Definition
qqmlfindusagessupport.cpp:29
QQmlFindUsagesSupport::process
void process(RequestPointerArgument request) override
Definition
qqmlfindusagessupport.cpp:34
QQmlFindUsagesSupport::setupCapabilities
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
Definition
qqmlfindusagessupport.cpp:21
QmlLsp::QQmlCodeModelManager
Definition
qqmlcodemodelmanager_p.h:44
QQmlLSUtils
Definition
qqmllsutils_p.h:31
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QmlLsp
Definition
qmllsmain.cpp:50
QQmlLSUtils::ItemLocation
Definition
qqmllsutils_p.h:34
ResponseScopeGuard
This class sends a result or an error when going out of scope.
Definition
qqmlbasemodule_p.h:56
qtdeclarative
src
qmlls
qqmlfindusagessupport.cpp
Generated on
for Qt by
1.18.0