diff options
| author | Orkun Tokdemir <orkun.tokdemir@qt.io> | 2024-11-01 15:49:40 +0100 |
|---|---|---|
| committer | Orkun Tokdemir <orkun.tokdemir@qt.io> | 2024-11-07 09:48:25 +0000 |
| commit | c76f0735e87b575313bdf7490f98fb59f576480a (patch) | |
| tree | da767867ffbce45de53d0700526d0f4e3c9dfc1f /qt-cpp | |
| parent | 69416853364c08782dd0c6b87700cae02f96d58d (diff) | |
qt-cpp: Add `qt-cpp.QML_IMPORT_PATH`
When a qml project built with vcpkg is debugged, we get a missing qml
module errors like `module "QtQuick.Layouts" is not installed`.
So we should set the `QML_IMPORT_PATH` environment variable explicitly.
Fixes: VSCODEEXT-107
Change-Id: I3f717a9b8b94e9948f2cf3c4d62383e4d84e4477
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Diffstat (limited to 'qt-cpp')
| -rw-r--r-- | qt-cpp/package.json | 12 | ||||
| -rw-r--r-- | qt-cpp/src/commands/launch-variables.ts | 41 | ||||
| -rw-r--r-- | qt-cpp/src/extension.ts | 4 |
3 files changed, 56 insertions, 1 deletions
diff --git a/qt-cpp/package.json b/qt-cpp/package.json index 7081e6e..e4c056c 100644 --- a/qt-cpp/package.json +++ b/qt-cpp/package.json @@ -105,6 +105,10 @@ { "name": "QT_QPA_PLATFORM_PLUGIN_PATH", "value": "^\"\\${command:qt-cpp.qpaPlatformPluginPath}\"" + }, + { + "name": "QML_IMPORT_PATH", + "value": "^\"\\${command:qt-cpp.QML_IMPORT_PATH}\"" } ], "MIMode": "gdb", @@ -140,6 +144,10 @@ { "name": "QT_QPA_PLATFORM_PLUGIN_PATH", "value": "^\"\\${command:qt-cpp.qpaPlatformPluginPath}\"" + }, + { + "name": "QML_IMPORT_PATH", + "value": "^\"\\${command:qt-cpp.QML_IMPORT_PATH}\"" } ], "MIMode": "lldb" @@ -166,6 +174,10 @@ { "name": "QT_QPA_PLATFORM_PLUGIN_PATH", "value": "^\"\\${command:qt-cpp.qpaPlatformPluginPath}\"" + }, + { + "name": "QML_IMPORT_PATH", + "value": "^\"\\${command:qt-cpp.QML_IMPORT_PATH}\"" } ] } diff --git a/qt-cpp/src/commands/launch-variables.ts b/qt-cpp/src/commands/launch-variables.ts index 2bbde43..1fc4edd 100644 --- a/qt-cpp/src/commands/launch-variables.ts +++ b/qt-cpp/src/commands/launch-variables.ts @@ -152,3 +152,44 @@ export function qpaPlatformPluginPathCommand() { } ); } + +export function qmlImportPathCommand() { + return vscode.commands.registerCommand( + `${EXTENSION_ID}.QML_IMPORT_PATH`, + async () => { + const kit = await getSelectedKit(); + if (kit?.environmentVariables?.VSCODE_QT_QTPATHS_EXE) { + if (kit.toolchainFile && inVCPKGRoot(kit.toolchainFile)) { + const info = coreAPI?.getQtInfoFromPath( + kit.environmentVariables.VSCODE_QT_QTPATHS_EXE + ); + if (info) { + const buildType = + await vscode.commands.executeCommand('cmake.buildType'); + let importPath = info.get('QT_INSTALL_QML'); + if (importPath) { + importPath = path.normalize(importPath); + if (buildType !== 'Debug') { + return importPath; + } + // If code reaches here, it means that the build type is Debug and + // we need to return the debug version of the import path + const installPrefix = info.get('QT_INSTALL_PREFIX'); + if (installPrefix) { + const installPrefixDebug = path.join(installPrefix, 'debug'); + if (importPath) { + const importPathDebug = importPath.replace( + path.normalize(installPrefix), + installPrefixDebug + ); + return importPathDebug; + } + } + } + } + } + } + return process.env.QML_IMPORT_PATH ?? ''; + } + ); +} diff --git a/qt-cpp/src/extension.ts b/qt-cpp/src/extension.ts index 91aef3d..8fb5d70 100644 --- a/qt-cpp/src/extension.ts +++ b/qt-cpp/src/extension.ts @@ -29,7 +29,8 @@ import { registerlaunchTargetFilenameWithoutExtension, registerKitDirectoryCommand, qtDirCommand, - qpaPlatformPluginPathCommand + qpaPlatformPluginPathCommand, + qmlImportPathCommand } from '@cmd/launch-variables'; import { createCppProject, CppProjectManager, CppProject } from '@/project'; import { KitManager } from '@/kit-manager'; @@ -62,6 +63,7 @@ export async function activate(context: vscode.ExtensionContext) { context.subscriptions.push( qpaPlatformPluginPathCommand(), + qmlImportPathCommand(), registerKitDirectoryCommand(), qtDirCommand(), registerMinGWgdbCommand(), |
