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
qqmlgotodefinitionsupport.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
"qqmlgotodefinitionsupport_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
11
QT_BEGIN_NAMESPACE
12
13
using
namespace
Qt::StringLiterals;
14
15
QmlGoToDefinitionSupport
::QmlGoToDefinitionSupport(QmlLsp::QQmlCodeModelManager *codeModel)
16
: BaseT(codeModel)
17
{
18
}
19
20
void
QmlGoToDefinitionSupport
::
setupCapabilities
(QLspSpecification::ServerCapabilities &caps)
21
{
22
// just assume caps.typeDefinitionProvider is a bool for now
23
// handle the TypeDefinitionOptions and TypeDefinitionRegistrationOptions cases later on, if
24
// needed (as they just allow more fancy go-to-type-definition action).
25
caps.definitionProvider =
true
;
26
}
27
28
void
QmlGoToDefinitionSupport
::
registerHandlers
(QLanguageServer *,
29
QLanguageServerProtocol *protocol)
30
{
31
protocol->registerDefinitionRequestHandler(getRequestHandler());
32
}
33
34
void
QmlGoToDefinitionSupport
::
process
(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
auto
&front = itemsFound.value().front();
46
47
const
QByteArray shortestRootUrl =
48
m_codeModelManager->shortestRootUrlForFile(request->m_parameters.textDocument.uri);
49
50
const
QStringList headerDirectories = shortestRootUrl.isEmpty()
51
? QStringList{}
52
: QStringList{ QUrl::fromEncoded(shortestRootUrl).toLocalFile() };
53
54
const
auto
locations = QQmlLSUtils::findDefinitionOf(front.domItem, headerDirectories);
55
56
for
(
const
QQmlLSUtils::Location &location : locations) {
57
results.append({ QUrl::fromLocalFile(location.filename()).toEncoded(),
58
QQmlLSUtils::qmlLocationToLspLocation(location) });
59
}
60
}
61
QT_END_NAMESPACE
QmlGoToDefinitionSupport
Definition
qqmlgotodefinitionsupport_p.h:30
QmlGoToDefinitionSupport::process
void process(RequestPointerArgument request) override
Definition
qqmlgotodefinitionsupport.cpp:34
QmlGoToDefinitionSupport::registerHandlers
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
Definition
qqmlgotodefinitionsupport.cpp:28
QmlGoToDefinitionSupport::setupCapabilities
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
Definition
qqmlgotodefinitionsupport.cpp:20
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
qmlls
qqmlgotodefinitionsupport.cpp
Generated on
for Qt by
1.18.0