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
21void QQmlFindUsagesSupport::setupCapabilities(QLspSpecification::ServerCapabilities &caps)
22{
23 // just assume caps.typeDefinitionProvider is a bool for now
24 // handle the ReferenceOptions later if needed (it adds the possibility to communicate the
25 // current progress).
26 caps.referencesProvider = true;
27}
28
29void QQmlFindUsagesSupport::registerHandlers(QLanguageServer *, QLanguageServerProtocol *protocol)
30{
31 protocol->registerReferenceRequestHandler(getRequestHandler());
32}
33
34void QQmlFindUsagesSupport::process(QQmlFindUsagesSupport::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
44 std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
45
46 auto usages = QQmlLSUtils::findUsagesOf(front.domItem);
47
48 QQmlJS::Dom::DomItem files = front.domItem.top().field(QQmlJS::Dom::Fields::qmlFileWithPath);
49
50 // note: ignore usages in filenames here as that is not supported by the protocol.
51 for (const auto &usage : usages.usagesInFile()) {
52 QLspSpecification::Location location;
53 location.uri = QUrl::fromLocalFile(usage.filename()).toEncoded();
54 location.range = QQmlLSUtils::qmlLocationToLspLocation(usage);
55
56 results.append(location);
57 }
58}
59QT_END_NAMESPACE
Implements a server for the language server protocol.
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
void process(RequestPointerArgument request) override
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
Combined button and popup list for selecting options.
This class sends a result or an error when going out of scope.