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
qqmlgototypedefinitionsupport.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
15QmlGoToTypeDefinitionSupport::QmlGoToTypeDefinitionSupport(QmlLsp::QQmlCodeModelManager *codeModel)
16 : BaseT(codeModel)
17{
18}
19
20void QmlGoToTypeDefinitionSupport::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.typeDefinitionProvider = true;
26}
27
29 QLanguageServerProtocol *protocol)
30{
31 protocol->registerTypeDefinitionRequestHandler(getRequestHandler());
32}
33
34void QmlGoToTypeDefinitionSupport::process(RequestPointerArgument request)
35{
36 QList<QLspSpecification::Location> results;
37 ResponseScopeGuard guard(results, request->m_response);
38
39 auto itemsFound = itemsForRequest(request);
40 if (guard.setErrorFrom(itemsFound))
41 return;
42
43 auto &front = std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
44
45 auto base = QQmlLSUtils::findTypeDefinitionOf(front.domItem);
46
47 if (!base) {
48 qDebug() << u"Could not obtain the base from the item"_s;
49 return;
50 }
51
52 QLspSpecification::Location l;
53 l.uri = QUrl::fromLocalFile(base->filename()).toEncoded();
54 l.range = QQmlLSUtils::qmlLocationToLspLocation(*base);
55
56 results.append(l);
57}
58
59QT_END_NAMESPACE
void process(RequestPointerArgument request) override
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
Combined button and popup list for selecting options.