blob: 6777f267cc1fe64ac2bee71dfff9502f24ff5fff (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qmllsclient.h"
#include "qmljseditortr.h"
#include <languageclient/languageclientinterface.h>
#include <languageclient/languageclientmanager.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljstools/qmljstoolsconstants.h>
#include <QLoggingCategory>
using namespace LanguageClient;
using namespace Utils;
namespace {
Q_LOGGING_CATEGORY(qmllsLog, "qtc.qmlls.client", QtWarningMsg);
}
namespace QmlJSEditor {
static QHash<FilePath, QmllsClient *> &qmllsClients()
{
static QHash<FilePath, QmllsClient *> clients;
return clients;
}
QmllsClient *QmllsClient::clientForQmlls(const FilePath &qmlls)
{
if (auto client = qmllsClients()[qmlls]) {
switch (client->state()) {
case Client::State::Uninitialized:
case Client::State::InitializeRequested:
case Client::State::Initialized:
return client;
case Client::State::ShutdownRequested:
case Client::State::Shutdown:
case Client::State::Error:
qCDebug(qmllsLog) << "client was stopping or failed, restarting";
break;
}
}
auto interface = new StdIOClientInterface;
interface->setCommandLine(CommandLine(qmlls));
auto client = new QmllsClient(interface);
client->setName(Tr::tr("Qmlls (%1)").arg(qmlls.toUserOutput()));
client->setActivateDocumentAutomatically(true);
LanguageFilter filter;
using namespace QmlJSTools::Constants;
filter.mimeTypes = QStringList()
<< QML_MIMETYPE << QMLUI_MIMETYPE << QBS_MIMETYPE << QMLPROJECT_MIMETYPE
<< QMLTYPES_MIMETYPE << JS_MIMETYPE << JSON_MIMETYPE;
client->setSupportedLanguage(filter);
client->start();
qmllsClients()[qmlls] = client;
return client;
}
QmllsClient::QmllsClient(StdIOClientInterface *interface)
: Client(interface)
{
}
QmllsClient::~QmllsClient()
{
qmllsClients().remove(qmllsClients().key(this));
}
} // namespace QmlJSEditor
|