diff options
Diffstat (limited to 'tools/qmlls/qmllanguageservertool.cpp')
-rw-r--r-- | tools/qmlls/qmllanguageservertool.cpp | 96 |
1 files changed, 90 insertions, 6 deletions
diff --git a/tools/qmlls/qmllanguageservertool.cpp b/tools/qmlls/qmllanguageservertool.cpp index 896e0c049c..34138638b7 100644 --- a/tools/qmlls/qmllanguageservertool.cpp +++ b/tools/qmlls/qmllanguageservertool.cpp @@ -1,12 +1,14 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include "qqmllanguageserver.h" + +#include <QtQmlLS/private/qqmllanguageserver_p.h> #include <QtCore/qdebug.h> #include <QtCore/qfile.h> #include <QtCore/qdir.h> #include <QtCore/qfileinfo.h> #include <QtCore/qcoreapplication.h> -#include "../shared/qqmltoolingsettings.h" +#include <QtQmlToolingSettings/private/qqmltoolingsettings_p.h> +#include <QtQmlToolingSettings/private/qqmltoolingutils_p.h> #include <QtCore/qdiriterator.h> #include <QtCore/qjsonobject.h> #include <QtCore/qjsonarray.h> @@ -131,7 +133,7 @@ int main(int argv, char *argc[]) QCoreApplication app(argv, argc); QCoreApplication::setApplicationName("qmlls"); QCoreApplication::setApplicationVersion(QT_VERSION_STR); -#if QT_CONFIG(commandlineparser) + QCommandLineParser parser; QQmlToolingSettings settings(QLatin1String("qmlls")); parser.setApplicationDescription(QLatin1String(R"(QML languageserver)")); @@ -163,6 +165,17 @@ int main(int argv, char *argc[]) parser.addOption(buildDirOption); settings.addOption(buildDir); + QString qmlImportPath = QStringLiteral(u"qml-import-path"); + QCommandLineOption qmlImportPathOption( + QStringList() << "I", QLatin1String("Look for QML modules in the specified directory"), + qmlImportPath); + parser.addOption(qmlImportPathOption); + + QCommandLineOption environmentOption( + QStringList() << "E", + QLatin1String("Use the QML_IMPORT_PATH environment variable to look for QML Modules")); + parser.addOption(environmentOption); + QCommandLineOption writeDefaultsOption( QStringList() << "write-defaults", QLatin1String("Writes defaults settings to .qmlls.ini and exits (Warning: This " @@ -174,6 +187,12 @@ int main(int argv, char *argc[]) "command line options into consideration")); parser.addOption(ignoreSettings); + QCommandLineOption noCMakeCallsOption( + QStringList() << "no-cmake-calls", + QLatin1String("Disables automatic CMake rebuilds and C++ file watching.")); + parser.addOption(noCMakeCallsOption); + settings.addOption("no-cmake-calls", "false"); + parser.process(app); if (parser.isSet(writeDefaultsOption)) { @@ -203,7 +222,6 @@ int main(int argv, char *argc[]) QThread::sleep(waitSeconds); qDebug() << "starting"; } -#endif QMutex writeMutex; QQmlLanguageServer qmlServer( [&writeMutex](const QByteArray &data) { @@ -212,8 +230,74 @@ int main(int argv, char *argc[]) std::cout.flush(); }, (parser.isSet(ignoreSettings) ? nullptr : &settings)); - if (parser.isSet(buildDirOption)) - qmlServer.codeModel()->setBuildPathsForRootUrl(QByteArray(), parser.values(buildDirOption)); + + const bool disableCMakeCallsViaEnvironment = + qmlGetConfigOption<bool, qmlConvertBoolConfigOption>("QMLLS_NO_CMAKE_CALLS"); + + if (disableCMakeCallsViaEnvironment || parser.isSet(noCMakeCallsOption)) { + if (disableCMakeCallsViaEnvironment) { + qWarning() << "Disabling CMake calls via QMLLS_NO_CMAKE_CALLS environment variable."; + } else { + qWarning() << "Disabling CMake calls via command line switch."; + } + + qmlServer.codeModel()->disableCMakeCalls(); + } + + if (parser.isSet(buildDirOption)) { + const QStringList dirs = + QQmlToolingUtils::getAndWarnForInvalidDirsFromOption(parser, buildDirOption); + + qInfo().nospace().noquote() + << "Using build directories passed by -b: \"" << dirs.join(u"\", \""_s) << "\"."; + + qmlServer.codeModel()->setBuildPathsForRootUrl(QByteArray(), dirs); + } else if (QStringList dirsFromEnv = + QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv("QMLLS_BUILD_DIRS"); + !dirsFromEnv.isEmpty()) { + + // warn now at qmlls startup that those directories will be used later in qqmlcodemodel when + // searching for build folders. + qInfo().nospace().noquote() << "Using build directories passed from environment variable " + "\"QMLLS_BUILD_DIRS\": \"" + << dirsFromEnv.join(u"\", \""_s) << "\"."; + + } else { + qInfo() << "Using the build directories found in the .qmlls.ini file. Your build folder " + "might not be found if no .qmlls.ini files are present in the root source " + "folder."; + } + QStringList importPaths{ QLibraryInfo::path(QLibraryInfo::QmlImportsPath) }; + if (parser.isSet(qmlImportPathOption)) { + const QStringList pathsFromOption = + QQmlToolingUtils::getAndWarnForInvalidDirsFromOption(parser, qmlImportPathOption); + qInfo().nospace().noquote() << "Using import directories passed by -I: \"" + << pathsFromOption.join(u"\", \""_s) << "\"."; + importPaths << pathsFromOption; + } + if (parser.isSet(environmentOption)) { + if (const QStringList dirsFromEnv = + QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv(u"QML_IMPORT_PATH"_s); + !dirsFromEnv.isEmpty()) { + qInfo().nospace().noquote() + << "Using import directories passed from environment variable " + "\"QML_IMPORT_PATH\": \"" + << dirsFromEnv.join(u"\", \""_s) << "\"."; + importPaths << dirsFromEnv; + } + + if (const QStringList dirsFromEnv2 = + QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv(u"QML2_IMPORT_PATH"_s); + !dirsFromEnv2.isEmpty()) { + qInfo().nospace().noquote() + << "Using import directories passed from the deprecated environment variable " + "\"QML2_IMPORT_PATH\": \"" + << dirsFromEnv2.join(u"\", \""_s) << "\"."; + importPaths << dirsFromEnv2; + } + } + qmlServer.codeModel()->setImportPaths(importPaths); + StdinReader r; QObject::connect(&r, &StdinReader::receivedData, qmlServer.server(), &QLanguageServer::receiveData); |