Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
7#include <QtLanguageServer/private/qlanguageserverspectypes_p.h>
8#include <QtQmlDom/private/qqmldomexternalitems_p.h>
9#include <QtQmlDom/private/qqmldomtop_p.h>
10
12
13using namespace Qt::StringLiterals;
14
15QmlGoToDefinitionSupport::QmlGoToDefinitionSupport(QmlLsp::QQmlCodeModelManager *codeModel)
16 : BaseT(codeModel)
17{
18}
19
20void 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
29 QLanguageServerProtocol *protocol)
30{
31 protocol->registerDefinitionRequestHandler(getRequestHandler());
32}
33
34void QmlGoToDefinitionSupport::process(RequestPointerArgument request)
35{
36 QList<QLspSpecification::Location> results;
37 ResponseScopeGuard guard(results, request->m_response);
38
39 auto itemsFound = itemsForRequest(request);
40
41 if (guard.setErrorFrom(itemsFound))
42 return;
43
44 auto &front = std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
45
46 const QByteArray shortestRootUrl =
47 m_codeModelManager->shortestRootUrlForFile(request->m_parameters.textDocument.uri);
48
49 const QStringList headerDirectories = shortestRootUrl.isEmpty()
50 ? QStringList{}
51 : QStringList{ QUrl::fromEncoded(shortestRootUrl).toLocalFile() };
52
53 const auto location = QQmlLSUtils::findDefinitionOf(front.domItem, headerDirectories);
54 if (!location)
55 return;
56
57 QLspSpecification::Location l;
58 l.uri = QUrl::fromLocalFile(location->filename()).toEncoded();
59 l.range = QQmlLSUtils::qmlLocationToLspLocation(*location);
60
61 results.append(l);
62}
63QT_END_NAMESPACE
void process(RequestPointerArgument request) override
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
Combined button and popup list for selecting options.