blob: e27f3decf2b8468974e6cf7c711b8501d5b44472 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qqmlgotodefinitionsupport_p.h"
#include "qqmllsutils_p.h"
#include <QtLanguageServer/private/qlanguageserverspectypes_p.h>
#include <QtQmlDom/private/qqmldomexternalitems_p.h>
#include <QtQmlDom/private/qqmldomtop_p.h>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
QmlGoToDefinitionSupport::QmlGoToDefinitionSupport(QmlLsp::QQmlCodeModel *codeModel)
: BaseT(codeModel)
{
}
QString QmlGoToDefinitionSupport::name() const
{
return u"QmlDefinitionSupport"_s;
}
void QmlGoToDefinitionSupport::setupCapabilities(
const QLspSpecification::InitializeParams &,
QLspSpecification::InitializeResult &serverCapabilities)
{
// just assume serverCapabilities.capabilities.typeDefinitionProvider is a bool for now
// handle the TypeDefinitionOptions and TypeDefinitionRegistrationOptions cases later on, if
// needed (as they just allow more fancy go-to-type-definition action).
serverCapabilities.capabilities.definitionProvider = true;
}
void QmlGoToDefinitionSupport::registerHandlers(QLanguageServer *,
QLanguageServerProtocol *protocol)
{
protocol->registerDefinitionRequestHandler(getRequestHandler());
}
void QmlGoToDefinitionSupport::process(RequestPointerArgument request)
{
QList<QLspSpecification::Location> results;
ResponseScopeGuard guard(results, request->m_response);
auto itemsFound = itemsForRequest(request);
if (guard.setErrorFrom(itemsFound))
return;
auto &front = std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
auto location = QQmlLSUtils::findDefinitionOf(front.domItem);
if (!location)
return;
QLspSpecification::Location l;
l.uri = QUrl::fromLocalFile(location->filename()).toEncoded();
l.range = QQmlLSUtils::qmlLocationToLspLocation(*location);
results.append(l);
}
QT_END_NAMESPACE
|