QmlJsEditor: Code cosmetics in qmljseditordocument.cpp

Change-Id: I915fbabaefcc018f2fa5211f8d09da8136b446ce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2024-06-28 16:37:57 +02:00
parent d79d4f2527
commit 9671c426e4

View File

@@ -37,6 +37,7 @@ using namespace QmlJSEditor;
using namespace QmlJS; using namespace QmlJS;
using namespace QmlJS::AST; using namespace QmlJS::AST;
using namespace QmlJSTools; using namespace QmlJSTools;
using namespace Utils;
namespace { namespace {
@@ -502,7 +503,7 @@ QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *pare
connect(&m_updateOutlineModelTimer, &QTimer::timeout, connect(&m_updateOutlineModelTimer, &QTimer::timeout,
this, &QmlJSEditorDocumentPrivate::updateOutlineModel); this, &QmlJSEditorDocumentPrivate::updateOutlineModel);
modelManager->updateSourceFiles(Utils::FilePaths({parent->filePath()}), false); modelManager->updateSourceFiles({parent->filePath()}, false);
} }
QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate() QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate()
@@ -522,7 +523,7 @@ void QmlJSEditorDocumentPrivate::invalidateFormatterCache()
void QmlJSEditorDocumentPrivate::reparseDocument() void QmlJSEditorDocumentPrivate::reparseDocument()
{ {
ModelManagerInterface::instance()->updateSourceFiles(Utils::FilePaths({q->filePath()}), false); ModelManagerInterface::instance()->updateSourceFiles({q->filePath()}, false);
} }
void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc) void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc)
@@ -733,8 +734,7 @@ void QmlJSEditorDocumentPrivate::setSourcesWithCapabilities(
setSemanticHighlightSource(QmllsStatus::Source::EmbeddedCodeModel); setSemanticHighlightSource(QmllsStatus::Source::EmbeddedCodeModel);
} }
static Utils::FilePath qmllsForFile(const Utils::FilePath &file, static FilePath qmllsForFile(const FilePath &file, QmlJS::ModelManagerInterface *modelManager)
QmlJS::ModelManagerInterface *modelManager)
{ {
QmllsSettingsManager *settingsManager = QmllsSettingsManager::instance(); QmllsSettingsManager *settingsManager = QmllsSettingsManager::instance();
bool enabled = settingsManager->useQmlls(); bool enabled = settingsManager->useQmlls();
@@ -757,14 +757,15 @@ void QmlJSEditorDocumentPrivate::settingsChanged()
if (q->isTemporary()) if (q->isTemporary())
return; return;
Utils::FilePath newQmlls = qmllsForFile(q->filePath(), ModelManagerInterface::instance()); FilePath newQmlls = qmllsForFile(q->filePath(), ModelManagerInterface::instance());
if (m_qmllsStatus.qmllsPath == newQmlls) if (m_qmllsStatus.qmllsPath == newQmlls)
return; return;
using namespace LanguageClient;
m_qmllsStatus.qmllsPath = newQmlls; m_qmllsStatus.qmllsPath = newQmlls;
auto lspClientManager = LanguageClient::LanguageClientManager::instance();
if (newQmlls.isEmpty()) { if (newQmlls.isEmpty()) {
qCDebug(qmllsLog) << "disabling qmlls for" << q->filePath(); qCDebug(qmllsLog) << "disabling qmlls for" << q->filePath();
if (LanguageClient::Client *client = lspClientManager->clientForDocument(q)) { if (Client *client = LanguageClientManager::clientForDocument(q)) {
qCDebug(qmllsLog) << "deactivating " << q->filePath() << "in qmlls" << newQmlls; qCDebug(qmllsLog) << "deactivating " << q->filePath() << "in qmlls" << newQmlls;
client->deactivateDocument(q); client->deactivateDocument(q);
} else } else
@@ -775,32 +776,32 @@ void QmlJSEditorDocumentPrivate::settingsChanged()
setSemanticHighlightSource(QmllsStatus::Source::EmbeddedCodeModel); setSemanticHighlightSource(QmllsStatus::Source::EmbeddedCodeModel);
} else if (QmllsClient *client = QmllsClient::clientForQmlls(newQmlls)) { } else if (QmllsClient *client = QmllsClient::clientForQmlls(newQmlls)) {
bool shouldActivate = false; bool shouldActivate = false;
if (auto oldClient = lspClientManager->clientForDocument(q)) { if (auto oldClient = LanguageClientManager::clientForDocument(q)) {
// check if it was disabled // check if it was disabled
if (client == oldClient) if (client == oldClient)
shouldActivate = true; shouldActivate = true;
} }
switch (client->state()) { switch (client->state()) {
case LanguageClient::Client::State::Uninitialized: case Client::State::Uninitialized:
case LanguageClient::Client::State::InitializeRequested: case Client::State::InitializeRequested:
connect(client, connect(client,
&LanguageClient::Client::initialized, &Client::initialized,
this, this,
&QmlJSEditorDocumentPrivate::setSourcesWithCapabilities); &QmlJSEditorDocumentPrivate::setSourcesWithCapabilities);
break; break;
case LanguageClient::Client::State::Initialized: case Client::State::Initialized:
setSourcesWithCapabilities(client->capabilities()); setSourcesWithCapabilities(client->capabilities());
break; break;
case LanguageClient::Client::State::FailedToInitialize: case Client::State::FailedToInitialize:
case LanguageClient::Client::State::Error: case Client::State::Error:
qCWarning(qmllsLog) << "qmlls" << newQmlls << "requested for document" << q->filePath() qCWarning(qmllsLog) << "qmlls" << newQmlls << "requested for document" << q->filePath()
<< "had errors, skipping setSourcesWithCababilities"; << "had errors, skipping setSourcesWithCababilities";
break; break;
case LanguageClient::Client::State::Shutdown: case Client::State::Shutdown:
qCWarning(qmllsLog) << "qmlls" << newQmlls << "requested for document" << q->filePath() qCWarning(qmllsLog) << "qmlls" << newQmlls << "requested for document" << q->filePath()
<< "did stop, skipping setSourcesWithCababilities"; << "did stop, skipping setSourcesWithCababilities";
break; break;
case LanguageClient::Client::State::ShutdownRequested: case Client::State::ShutdownRequested:
qCWarning(qmllsLog) << "qmlls" << newQmlls << "requested for document" << q->filePath() qCWarning(qmllsLog) << "qmlls" << newQmlls << "requested for document" << q->filePath()
<< "is stopping, skipping setSourcesWithCababilities"; << "is stopping, skipping setSourcesWithCababilities";
break; break;
@@ -810,7 +811,7 @@ void QmlJSEditorDocumentPrivate::settingsChanged()
client->activateDocument(q); client->activateDocument(q);
} else { } else {
qCDebug(qmllsLog) << "opening " << q->filePath() << "in qmlls" << newQmlls; qCDebug(qmllsLog) << "opening " << q->filePath() << "in qmlls" << newQmlls;
lspClientManager->openDocumentWithClient(q, client); LanguageClientManager::openDocumentWithClient(q, client);
} }
} else { } else {
qCWarning(qmllsLog) << "could not start qmlls " << newQmlls << "for" << q->filePath(); qCWarning(qmllsLog) << "could not start qmlls " << newQmlls << "for" << q->filePath();
@@ -874,7 +875,7 @@ void QmlJSEditorDocument::setIsDesignModePreferred(bool value)
d->m_isDesignModePreferred = value; d->m_isDesignModePreferred = value;
if (value) { if (value) {
if (infoBar()->canInfoBeAdded(QML_UI_FILE_WARNING)) { if (infoBar()->canInfoBeAdded(QML_UI_FILE_WARNING)) {
Utils::InfoBarEntry info(QML_UI_FILE_WARNING, InfoBarEntry info(QML_UI_FILE_WARNING,
Tr::tr("This file should only be edited in <b>Design</b> mode.")); Tr::tr("This file should only be edited in <b>Design</b> mode."));
info.addCustomButton(Tr::tr("Switch Mode"), []() { info.addCustomButton(Tr::tr("Switch Mode"), []() {
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN); Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);