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
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
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
13
14using namespace Qt::StringLiterals;
15
16QQmlFindUsagesSupport::QQmlFindUsagesSupport(QmlLsp::QQmlCodeModelManager *codeModelManager)
17 : BaseT(codeModelManager)
18{
19}
20
22{
23 return u"QmlFindUsagesSupport"_s;
24}
25
27 const QLspSpecification::InitializeParams &,
28 QLspSpecification::InitializeResult &serverCapabilities)
29{
30 // just assume serverCapabilities.capabilities.typeDefinitionProvider is a bool for now
31 // handle the ReferenceOptions later if needed (it adds the possibility to communicate the
32 // current progress).
33 serverCapabilities.capabilities.referencesProvider = true;
34}
35
36void QQmlFindUsagesSupport::registerHandlers(QLanguageServer *, QLanguageServerProtocol *protocol)
37{
38 protocol->registerReferenceRequestHandler(getRequestHandler());
39}
40
41void QQmlFindUsagesSupport::process(QQmlFindUsagesSupport::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
51 std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
52
53 auto usages = QQmlLSUtils::findUsagesOf(front.domItem);
54
55 QQmlJS::Dom::DomItem files = front.domItem.top().field(QQmlJS::Dom::Fields::qmlFileWithPath);
56
57 // note: ignore usages in filenames here as that is not supported by the protocol.
58 for (const auto &usage : usages.usagesInFile()) {
59 QLspSpecification::Location location;
60 location.uri = QUrl::fromLocalFile(usage.filename()).toEncoded();
61 location.range = QQmlLSUtils::qmlLocationToLspLocation(usage);
62
63 results.append(location);
64 }
65}
66QT_END_NAMESPACE
Implements a server for the language server protocol.
void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, QLspSpecification::InitializeResult &) override
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
void process(RequestPointerArgument request) override
QString name() const override
This class sends a result or an error when going out of scope.