Automatic qmlls support (experimental)

Looks for qmlls (the qml language server of Qt) and if available
and set in the preferences uses it instead of the embedded code
model for the supported features.

Its usage is driven by two flags that can be set in the QtQuick > QML/JS
Editing preferences: "use qmlls" activates the use of qmlls if available;
"use latest qmlls" always uses the qmlls of the latest Qt, instead of
the one of the target (with the one used to compile QtCreator as
fallback).

To support disabling/enabling of qmlls as soon as one changes the
preferences the singleton QmllsSettingsManager can emit a signal
on changes.
It also keeps track of the latest qmlls binary known.

QmlJS::ModelmanagerInterface::ProjectInfo is also extended to keep track
of the qmlls binary.

QmlJSEditorDocument uses the ProjectInfo and QmllsSettingsManager to
decide if a LanguageClient::Client should be started for that
document.

The client uses the QmllsClient subclass to keep track of the path of
the qmlls clients and use the same qmlls process or all files that
use the same binary.

Currently qmlls <6.4.0 are not considered because they might have too
many issues.

The enabling/disabling of warnings and highlight is a bit cumbersome
because they are handled together in the semantic highlighter, but
must be handled separately depending on the qmlls capabilities.

The disabling is done at the latest moment stopping the visualization
of the embedded model warnings/highlights/suggestions.
The computation of the semantic info is not suppressed to support the
other features (find usages, semantic highlighting if active,...).
When qmlls supports more features a complete removal of the semantic
info construction could be evaluated.

Change-Id: I3487e1680841025cabba6b339fbfe820ef83f858
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Fawzi Mohamed
2022-09-28 11:16:49 +02:00
parent 634ac23af7
commit 3baf305f9b
17 changed files with 575 additions and 44 deletions

View File

@@ -113,6 +113,9 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent)
m_defaultProjectInfo.qtQmlPath =
FilePath::fromUserInput(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath));
m_defaultProjectInfo.qmllsPath = ModelManagerInterface::qmllsForBinPath(
FilePath::fromUserInput(QLibraryInfo::location(QLibraryInfo::BinariesPath)),
QLibraryInfo::version());
m_defaultProjectInfo.qtVersionString = QLibraryInfo::version().toString();
updateImportPaths();
@@ -216,6 +219,16 @@ ModelManagerInterface::WorkingCopy ModelManagerInterface::workingCopy()
return WorkingCopy();
}
FilePath ModelManagerInterface::qmllsForBinPath(const Utils::FilePath &binPath, const QVersionNumber &version)
{
if (version < QVersionNumber(6,4,0))
return {};
QString qmllsExe = "qmlls";
if (HostOsInfo::isWindowsHost())
qmllsExe = "qmlls.exe";
return binPath.resolvePath(qmllsExe);
}
void ModelManagerInterface::activateScan()
{
if (!m_shouldScanImports) {
@@ -415,6 +428,10 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1,
return true;
if (p1.qtQmlPath > p2.qtQmlPath)
return false;
if (p1.qmllsPath < p2.qmllsPath)
return true;
if (p1.qmllsPath > p2.qmllsPath)
return false;
const PathsAndLanguages &s1 = p1.importPaths;
const PathsAndLanguages &s2 = p2.importPaths;
if (s1.size() < s2.size())
@@ -628,6 +645,8 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
res.qtQmlPath = pInfo.qtQmlPath;
res.qtVersionString = pInfo.qtVersionString;
}
if (res.qmllsPath.isEmpty())
res.qmllsPath = pInfo.qmllsPath;
res.applicationDirectories.append(pInfo.applicationDirectories);
for (const auto &importPath : pInfo.importPaths)
res.importPaths.maybeInsert(importPath);