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
21{
22 return u"QmlNavigationSupport"_s;
23}
24
26 const QLspSpecification::InitializeParams &,
27 QLspSpecification::InitializeResult &serverCapabilities)
28{
29 // just assume serverCapabilities.capabilities.typeDefinitionProvider is a bool for now
30 // handle the TypeDefinitionOptions and TypeDefinitionRegistrationOptions cases later on, if
31 // needed (as they just allow more fancy go-to-type-definition action).
32 serverCapabilities.capabilities.typeDefinitionProvider = true;
33}
34
36 QLanguageServerProtocol *protocol)
37{
38 protocol->registerTypeDefinitionRequestHandler(getRequestHandler());
39}
40
41void QmlGoToTypeDefinitionSupport::process(RequestPointerArgument request)
42{
43 QList<QLspSpecification::Location> results;
44 ResponseScopeGuard guard(results, request->m_response);
45
46 auto itemsFound = itemsForRequest(request);
47 if (guard.setErrorFrom(itemsFound))
48 return;
49
50 auto &front = std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
51
52 auto base = QQmlLSUtils::findTypeDefinitionOf(front.domItem);
53
54 if (!base) {
55 qDebug() << u"Could not obtain the base from the item"_s;
56 return;
57 }
58
59 QLspSpecification::Location l;
60 l.uri = QUrl::fromLocalFile(base->filename()).toEncoded();
61 l.range = QQmlLSUtils::qmlLocationToLspLocation(*base);
62
63 results.append(l);
64}
65
66QT_END_NAMESPACE
Implements a server for the language server protocol.
void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, QLspSpecification::InitializeResult &) override
void process(RequestPointerArgument request) override
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
This class sends a result or an error when going out of scope.