aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOrkun Tokdemir <orkun.tokdemir@qt.io>2024-12-05 16:43:16 +0100
committerOrkun Tokdemir <orkun.tokdemir@qt.io>2024-12-12 11:07:09 +0000
commitb02c70db6ba873c3bea446eee15dae63759667a8 (patch)
tree6b6c849040e4544ad414588002a9fc85dfc98964
parent46127790594d2ca67a1cdfbfcea5dad32089b36d (diff)
Refactor communication between core and extensions
In the previous implementation, the extensions were using only one way to communicate with each other, which was getting a notification when a config value was set or changed. This was problematic on startup because there was no order in which the extensions were activated and when messages were handled. b5bf26ac084823758be18453bb61579fefceb57c partially fixed this issue by adding a way to wait for `qt-cpp` to be ready, but it was still not enough. The extension should read config values when they are ready, not when messages are sent from other extensions. Remove the `lazy` initialization parameter in `Project` classes. Instead of using that parameter, we remove the firing event from `addProject()` and only fire when the project is added after startup. This way, we don't need the `lazy` parameter anymore. Since `processMessage()` is not used during startup, this commit also fixes QTBUG-131702 on the extension side. qt-lib: This commit changes `QtWorkspaceConfigMessage` and removes values in it. `QtWorkspaceConfigMessage` is now used only to notify that a value or values were set. The value `CoreApi` can be accessed by `getValue` and `setValue`. * Update the `CoreApi` interface * Add `setValue` * Rename `update` to `notify` * Remove `get<T>()` from `QtWorkspaceConfigMessage` qt-core: * Remove the internal checking mechanism to understand if a value was set or changed. Instead, just store values. qt-cpp: * Update `processMessage()` for the new usage. * Initialize config values explicitly during startup. qt-qml: * Update `processMessage()` for the new usage. * Separate starting `qmlls` from the constructor. It should be started when the conditions are met. * Get config values and update parameters inside `onProjectAdded()` Task-number: QTBUG-131702 Change-Id: If9831ea1257d123f777e6ae2afb92f33942dd3da Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
-rw-r--r--qt-core/src/api.ts47
-rw-r--r--qt-core/src/extension.ts11
-rw-r--r--qt-core/src/installation-root.ts10
-rw-r--r--qt-core/src/project.ts21
-rw-r--r--qt-cpp/src/extension.ts46
-rw-r--r--qt-cpp/src/kit-manager.ts7
-rw-r--r--qt-cpp/src/project.ts55
-rw-r--r--qt-lib/src/core-api.ts30
-rw-r--r--qt-lib/src/project.ts6
-rw-r--r--qt-qml/src/extension.ts31
-rw-r--r--qt-qml/src/project.ts30
-rw-r--r--qt-qml/src/qmlls.ts10
-rw-r--r--qt-ui/src/extension.ts29
-rw-r--r--qt-ui/src/project.ts13
14 files changed, 219 insertions, 127 deletions
diff --git a/qt-core/src/api.ts b/qt-core/src/api.ts
index ec11984..b5f5e61 100644
--- a/qt-core/src/api.ts
+++ b/qt-core/src/api.ts
@@ -12,7 +12,8 @@ import {
QtWorkspaceConfig,
QtWorkspaceConfigMessage,
QtInfo,
- QtAdditionalPath
+ QtAdditionalPath,
+ ConfigType
} from 'qt-lib';
const logger = createLogger('api');
@@ -35,28 +36,6 @@ export class CoreAPIImpl implements CoreAPI {
return this._onValueChanged.event;
}
- private processMessage(message: QtWorkspaceConfigMessage) {
- let changed = false;
- for (const [key, value] of message.config) {
- if (value !== this._configs.get(message.workspaceFolder)?.get(key)) {
- logger.info('Config changed:', key);
- const config = this._configs.get(message.workspaceFolder);
- if (config) {
- config.set(key, value);
- } else {
- logger.info('New config: ' + JSON.stringify(value));
- const newConfig: QtWorkspaceConfig = new Map();
- newConfig.set(key, value);
- this._configs.set(message.workspaceFolder, newConfig);
- }
- changed = true;
- }
- }
- if (changed) {
- this._onValueChanged.fire(message);
- }
- }
-
private static obtainArch(content: string) {
const keysToCheck = ['QT_ARCHS', 'QT_TARGET_ARCH', 'QT_ARCH'];
for (const k of keysToCheck) {
@@ -112,8 +91,26 @@ export class CoreAPIImpl implements CoreAPI {
return ret;
}
- update(message: QtWorkspaceConfigMessage) {
- this.processMessage(message);
+ notify(message: QtWorkspaceConfigMessage) {
+ if (message.config.size === 0) {
+ throw new Error('Empty config');
+ }
+ this._onValueChanged.fire(message);
+ }
+
+ setValue(
+ folder: vscode.WorkspaceFolder | string,
+ key: string,
+ value: ConfigType
+ ) {
+ const workspaceConfig = this._configs.get(folder);
+ if (workspaceConfig) {
+ workspaceConfig.set(key, value);
+ } else {
+ const newConfig: QtWorkspaceConfig = new Map();
+ newConfig.set(key, value);
+ this._configs.set(folder, newConfig);
+ }
}
getValue<T>(
diff --git a/qt-core/src/extension.ts b/qt-core/src/extension.ts
index ba151e3..e8b373c 100644
--- a/qt-core/src/extension.ts
+++ b/qt-core/src/extension.ts
@@ -9,7 +9,6 @@ import {
initLogger,
QtInsRootConfigName,
AdditionalQtPathsName,
- QtWorkspaceConfigMessage,
telemetry
} from 'qt-lib';
import { CoreAPIImpl } from '@/api';
@@ -43,7 +42,7 @@ export async function activate(context: vscode.ExtensionContext) {
if (vscode.workspace.workspaceFolders !== undefined) {
for (const folder of vscode.workspace.workspaceFolders) {
const project = await createCoreProject(folder, context);
- projectManager.addProject(project, true);
+ projectManager.addProject(project);
}
}
context.subscriptions.push(...registerDocumentationCommands());
@@ -78,16 +77,16 @@ export function deactivate() {
}
export function initCoreValues() {
- const globalUpdateMessage = new QtWorkspaceConfigMessage(GlobalWorkspace);
- globalUpdateMessage.config.set(
+ coreAPI?.setValue(
+ GlobalWorkspace,
QtInsRootConfigName,
getCurrentGlobalQtInstallationRoot()
);
- globalUpdateMessage.config.set(
+ coreAPI?.setValue(
+ GlobalWorkspace,
AdditionalQtPathsName,
getCurrentGlobalAdditionalQtPaths()
);
- coreAPI?.update(globalUpdateMessage);
for (const project of projectManager.getProjects()) {
project.initConfigValues();
diff --git a/qt-core/src/installation-root.ts b/qt-core/src/installation-root.ts
index 638dcbf..a1765b2 100644
--- a/qt-core/src/installation-root.ts
+++ b/qt-core/src/installation-root.ts
@@ -194,8 +194,9 @@ export function onQtInsRootUpdated(
logger.info(`Qt installation root updated: "${newQtInstallationRoot}"`);
const message = new QtWorkspaceConfigMessage(folder);
- message.config.set(QtInsRootConfigName, newQtInstallationRoot);
- coreAPI?.update(message);
+ coreAPI?.setValue(folder, QtInsRootConfigName, newQtInstallationRoot);
+ message.config.add(QtInsRootConfigName);
+ coreAPI?.notify(message);
}
export function onAdditionalQtPathsUpdated(
@@ -216,6 +217,7 @@ export function onAdditionalQtPathsUpdated(
logger.info('Additional Qt Paths updated: ' + JSON.stringify(newPaths));
const message = new QtWorkspaceConfigMessage(folder);
- message.config.set(AdditionalQtPathsName, newPaths);
- coreAPI?.update(message);
+ coreAPI?.setValue(folder, AdditionalQtPathsName, newPaths);
+ message.config.add(AdditionalQtPathsName);
+ coreAPI?.notify(message);
}
diff --git a/qt-core/src/project.ts b/qt-core/src/project.ts
index 45f97f5..06e59f6 100644
--- a/qt-core/src/project.ts
+++ b/qt-core/src/project.ts
@@ -11,8 +11,7 @@ import {
GlobalWorkspace,
QtInsRootConfigName,
QtAdditionalPath,
- compareQtAdditionalPath,
- QtWorkspaceConfigMessage
+ compareQtAdditionalPath
} from 'qt-lib';
import { Project, ProjectManager } from 'qt-lib';
import { convertAdditionalQtPaths, getConfiguration } from '@/util';
@@ -96,17 +95,17 @@ export class CoreProject implements Project {
public initConfigValues() {
const folder = this.folder;
- const message = new QtWorkspaceConfigMessage(folder);
- message.config.set(
- QtInsRootConfigName,
- CoreProjectManager.getWorkspaceFolderQtInsRoot(folder)
+ const qtInsRoot = CoreProjectManager.getWorkspaceFolderQtInsRoot(folder);
+ coreAPI?.setValue(folder, QtInsRootConfigName, qtInsRoot);
+ logger.info(
+ `Setting Qt installation root for ${folder.uri.fsPath} to: ${qtInsRoot}`
);
- message.config.set(
- AdditionalQtPathsName,
- CoreProjectManager.getWorkspaceFolderAdditionalQtPaths(folder)
+ const additionalQtPaths =
+ CoreProjectManager.getWorkspaceFolderAdditionalQtPaths(folder);
+ coreAPI?.setValue(folder, AdditionalQtPathsName, additionalQtPaths);
+ logger.info(
+ `Setting additional Qt paths for ${folder.uri.fsPath} to: ${additionalQtPaths.join(', ')}`
);
- logger.info('Updating coreAPI with message:', message as unknown as string);
- coreAPI?.update(message);
}
dispose() {
diff --git a/qt-cpp/src/extension.ts b/qt-cpp/src/extension.ts
index 3813695..ecb1a0c 100644
--- a/qt-cpp/src/extension.ts
+++ b/qt-cpp/src/extension.ts
@@ -6,7 +6,6 @@ import * as vscode from 'vscode';
import {
CoreAPI,
getCoreApi,
- QtWorkspaceType,
createLogger,
initLogger,
QtWorkspaceConfigMessage,
@@ -16,11 +15,6 @@ import {
QtAdditionalPath,
telemetry
} from 'qt-lib';
-import {
- getQtInsRoot,
- getQtPathsExe,
- getSelectedKit
-} from '@cmd/register-qt-path';
import { registerMinGWgdbCommand } from '@cmd/mingw-gdb';
import { registerResetCommand } from '@cmd/reset-qt-ext';
import { registerNatvisCommand } from '@cmd/natvis';
@@ -58,8 +52,8 @@ export async function activate(context: vscode.ExtensionContext) {
if (vscode.workspace.workspaceFolders !== undefined) {
for (const folder of vscode.workspace.workspaceFolders) {
const project = await createCppProject(folder, context);
- projectManager.addProject(project, true);
- kitManager.addProject(project, true);
+ projectManager.addProject(project);
+ kitManager.addProject(project);
}
}
@@ -89,8 +83,8 @@ export async function activate(context: vscode.ExtensionContext) {
void tryToUseCMakeFromQtTools();
await kitManager.checkForAllQtInstallations();
- await initCoreValues();
- logger.info('Core values initialized');
+ await initConfigValues();
+ logger.info('Config values initialized');
}
export function deactivate() {
@@ -102,26 +96,9 @@ export function deactivate() {
}
}
-export async function initCoreValues() {
- if (!coreAPI) {
- throw new Error('CoreAPI is not initialized');
- }
-
+export async function initConfigValues() {
for (const project of projectManager.getProjects()) {
- const folder = project.folder;
- const kit = await getSelectedKit(folder, true);
- const message = new QtWorkspaceConfigMessage(folder);
- const selectedKitPath = kit ? getQtInsRoot(kit) : undefined;
- logger.info(
- `Setting selected kit path for ${folder.uri.fsPath} to ${selectedKitPath}`
- );
- message.config.set('selectedKitPath', selectedKitPath);
- const selectedQtPaths = kit ? getQtPathsExe(kit) : undefined;
- message.config.set('selectedQtPaths', selectedQtPaths);
- message.config.set('workspaceType', QtWorkspaceType.CMakeExt);
- message.config.set('buildDir', project.buildDir ?? '');
- logger.info('Updating coreAPI with message:', message as unknown as string);
- coreAPI.update(message);
+ await project.initConfigValues();
}
}
@@ -141,14 +118,21 @@ async function processMessage(message: QtWorkspaceConfigMessage) {
}
for (const key of message.config.keys()) {
if (key === QtInsRootConfigName) {
- const value = message.get<string>(QtInsRootConfigName) ?? '';
+ const value =
+ coreAPI?.getValue<string>(
+ message.workspaceFolder,
+ QtInsRootConfigName
+ ) ?? '';
await kitManager.onQtInstallationRootChanged(value, project?.folder);
continue;
}
if (key === AdditionalQtPathsName) {
const additionalQtPaths =
- message.get<QtAdditionalPath[]>(AdditionalQtPathsName) ?? [];
+ coreAPI?.getValue<QtAdditionalPath[]>(
+ message.workspaceFolder,
+ AdditionalQtPathsName
+ ) ?? [];
await kitManager.onQtPathsChanged(additionalQtPaths, project?.folder);
continue;
}
diff --git a/qt-cpp/src/kit-manager.ts b/qt-cpp/src/kit-manager.ts
index 2a80dbe..1540781 100644
--- a/qt-cpp/src/kit-manager.ts
+++ b/qt-cpp/src/kit-manager.ts
@@ -148,11 +148,8 @@ export class KitManager {
this.globalStateManager = new GlobalStateManager(context);
}
- public addProject(project: CppProject, lazy = false) {
+ public addProject(project: CppProject) {
this.projects.add(project);
- if (!lazy) {
- void this.checkForQtInstallations(project);
- }
}
public removeProject(project: CppProject) {
@@ -190,7 +187,7 @@ export class KitManager {
// If the project parameter is undefined, it means that it is a global check
// otherwise, it is a workspace folder check
- private async checkForQtInstallations(project?: CppProject) {
+ public async checkForQtInstallations(project?: CppProject) {
const currentQtInsRoot = project
? KitManager.getWorkspaceFolderQtInsRoot(project.folder)
: getCurrentGlobalQtInstallationRoot();
diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts
index 23d45fc..38e3550 100644
--- a/qt-cpp/src/project.ts
+++ b/qt-cpp/src/project.ts
@@ -6,7 +6,11 @@ import * as cmakeApi from 'vscode-cmake-tools';
import { WorkspaceStateManager } from '@/state';
import { coreAPI, kitManager } from '@/extension';
-import { createLogger, QtWorkspaceConfigMessage } from 'qt-lib';
+import {
+ createLogger,
+ QtWorkspaceConfigMessage,
+ QtWorkspaceType
+} from 'qt-lib';
import { Project, ProjectManager } from 'qt-lib';
import {
getQtInsRoot,
@@ -60,11 +64,21 @@ export class CppProject implements Project {
}
const selectedKitPath = kit ? getQtInsRoot(kit) : undefined;
const message = new QtWorkspaceConfigMessage(this.folder);
- message.config.set('selectedKitPath', selectedKitPath);
+ coreAPI?.setValue(
+ this.folder,
+ 'selectedKitPath',
+ selectedKitPath
+ );
+ message.config.add('selectedKitPath');
const selectedQtPaths = kit ? getQtPathsExe(kit) : undefined;
- message.config.set('selectedQtPaths', selectedQtPaths);
- coreAPI?.update(message);
+ coreAPI?.setValue(
+ this.folder,
+ 'selectedQtPaths',
+ selectedQtPaths
+ );
+ message.config.add('selectedQtPaths');
+ coreAPI?.notify(message);
}
}
);
@@ -79,8 +93,9 @@ export class CppProject implements Project {
);
this._buildDir = currentBuildDir;
const message = new QtWorkspaceConfigMessage(this.folder);
- message.config.set('buildDir', currentBuildDir);
- coreAPI?.update(message);
+ coreAPI?.setValue(this.folder, 'buildDir', currentBuildDir);
+ message.config.add('buildDir');
+ coreAPI?.notify(message);
}
}
);
@@ -88,7 +103,24 @@ export class CppProject implements Project {
this._disposables.push(onSelectedConfigurationChangedHandler);
}
}
-
+ async initConfigValues() {
+ if (!coreAPI) {
+ throw new Error('CoreAPI is not initialized');
+ }
+ const folder = this.folder;
+ const kit = await getSelectedKit(folder, true);
+ const message = new QtWorkspaceConfigMessage(folder);
+ const selectedKitPath = kit ? getQtInsRoot(kit) : undefined;
+ logger.info(
+ `Setting selected kit path for ${folder.uri.fsPath} to ${selectedKitPath}`
+ );
+ coreAPI.setValue(folder, 'selectedKitPath', selectedKitPath);
+ const selectedQtPaths = kit ? getQtPathsExe(kit) : undefined;
+ coreAPI.setValue(folder, 'selectedQtPaths', selectedQtPaths);
+ coreAPI.setValue(folder, 'workspaceType', QtWorkspaceType.CMakeExt);
+ coreAPI.setValue(folder, 'buildDir', this.buildDir);
+ logger.info('Updating coreAPI with message:', message as unknown as string);
+ }
public getStateManager() {
return this._stateManager;
}
@@ -112,9 +144,11 @@ export class CppProjectManager extends ProjectManager<CppProject> {
super(context, createCppProject);
this._disposables.push(
- this.onProjectAdded((project: CppProject) => {
+ this.onProjectAdded(async (project: CppProject) => {
logger.info('Adding project:', project.folder.uri.fsPath);
+ await project.initConfigValues();
kitManager.addProject(project);
+ void kitManager.checkForQtInstallations(project);
})
);
@@ -124,4 +158,9 @@ export class CppProjectManager extends ProjectManager<CppProject> {
})
);
}
+ initConfigValues() {
+ for (const project of this.getProjects()) {
+ void project.initConfigValues();
+ }
+ }
}
diff --git a/qt-lib/src/core-api.ts b/qt-lib/src/core-api.ts
index 157c35c..2630c4a 100644
--- a/qt-lib/src/core-api.ts
+++ b/qt-lib/src/core-api.ts
@@ -27,24 +27,21 @@ export function compareQtAdditionalPath(
return a.name.localeCompare(b.name);
}
-export type QtWorkspaceConfig = Map<
- string,
- string | QtAdditionalPath[] | QtWorkspaceType | undefined
->;
+export type ConfigType =
+ | string
+ | QtAdditionalPath[]
+ | QtWorkspaceType
+ | undefined;
+export type QtWorkspaceConfig = Map<string, ConfigType>;
+
+type MessageConfigs = Set<string>;
export class QtWorkspaceConfigMessage {
workspaceFolder: vscode.WorkspaceFolder | string;
- config: QtWorkspaceConfig;
+ config: MessageConfigs;
constructor(folder?: vscode.WorkspaceFolder | string) {
this.workspaceFolder = folder ?? 'global';
- this.config = new Map() as QtWorkspaceConfig;
- }
- get<T>(key: string, defaultValue?: T): T | undefined {
- const value = this.config.get(key);
- if (value === undefined) {
- return defaultValue;
- }
- return value as T;
+ this.config = new Set() as MessageConfigs;
}
}
@@ -75,11 +72,16 @@ export class QtInfo {
}
export interface CoreAPI {
- update(config: QtWorkspaceConfigMessage): void;
+ notify(config: QtWorkspaceConfigMessage): void;
getValue<T>(
folder: vscode.WorkspaceFolder | string,
key: string
): T | undefined;
+ setValue(
+ folder: vscode.WorkspaceFolder | string,
+ key: string,
+ value: ConfigType
+ ): void;
onValueChanged: vscode.Event<QtWorkspaceConfigMessage>;
getQtInfo(qtPathsExecutable: QtAdditionalPath): QtInfo | undefined;
getQtInfoFromPath(qtPathsExe: string): QtInfo | undefined;
diff --git a/qt-lib/src/project.ts b/qt-lib/src/project.ts
index 992b029..4a1c8fd 100644
--- a/qt-lib/src/project.ts
+++ b/qt-lib/src/project.ts
@@ -29,11 +29,8 @@ export class ProjectManager<ProjectType extends Project> {
this.watchProjects(context);
}
- public addProject(project: ProjectType, lazy = false) {
+ public addProject(project: ProjectType) {
this.projects.add(project);
- if (!lazy) {
- this._addEmitter.fire(project);
- }
}
public removeProject(project: ProjectType) {
@@ -88,6 +85,7 @@ export class ProjectManager<ProjectType extends Project> {
continue;
}
this.addProject(project);
+ this._addEmitter.fire(project);
}
});
}
diff --git a/qt-qml/src/extension.ts b/qt-qml/src/extension.ts
index c0ef95a..ebe2de8 100644
--- a/qt-qml/src/extension.ts
+++ b/qt-qml/src/extension.ts
@@ -16,7 +16,7 @@ import { registerColorProvider } from '@/color-provider';
import { registerRestartQmllsCommand } from '@cmd/restart-qmlls';
import { registerDownloadQmllsCommand } from '@cmd/download-qmlls';
import { registerCheckQmllsUpdateCommand } from '@cmd/check-qmlls-update';
-import { getDoNotAskForDownloadingQmlls, Qmlls } from '@/qmlls';
+import { getDoNotAskForDownloadingQmlls, Qmlls, QmllsStatus } from '@/qmlls';
import { EXTENSION_ID } from '@/constants';
import { QMLProjectManager, createQMLProject } from '@/project';
import { registerResetCommand } from '@cmd/reset';
@@ -62,10 +62,19 @@ export async function activate(context: vscode.ExtensionContext) {
registerResetCommand()
);
telemetry.sendEvent(`activated`);
+ projectManager.getConfigValues();
+ projectManager.updateQmllsParams();
+ void startQmlls();
+}
+async function startQmlls() {
const shouldCheck = !getDoNotAskForDownloadingQmlls();
+ let result: QmllsStatus | undefined;
if (shouldCheck) {
- void Qmlls.checkAssetAndDecide();
+ result = await Qmlls.checkAssetAndDecide();
+ }
+ if (!shouldCheck || result === QmllsStatus.stopped) {
+ void projectManager.startQmlls();
}
}
@@ -90,7 +99,10 @@ function processMessage(message: QtWorkspaceConfigMessage) {
let updateQmlls = false;
for (const key of message.config.keys()) {
if (key === 'selectedKitPath') {
- const selectedKitPath = message.get<string>('selectedKitPath');
+ const selectedKitPath = coreAPI?.getValue<string>(
+ message.workspaceFolder,
+ 'selectedKitPath'
+ );
if (selectedKitPath !== project.kitPath) {
updateQmlls = true;
project.kitPath = selectedKitPath;
@@ -98,7 +110,10 @@ function processMessage(message: QtWorkspaceConfigMessage) {
continue;
}
if (key === 'selectedQtPaths') {
- const selectedQtPaths = message.get<string>('selectedQtPaths');
+ const selectedQtPaths = coreAPI?.getValue<string>(
+ message.workspaceFolder,
+ 'selectedQtPaths'
+ );
if (selectedQtPaths !== project.qtpathsExe) {
updateQmlls = true;
project.qtpathsExe = selectedQtPaths;
@@ -106,7 +121,10 @@ function processMessage(message: QtWorkspaceConfigMessage) {
continue;
}
if (key === 'buildDir') {
- const buildDir = message.get<string>('buildDir');
+ const buildDir = coreAPI?.getValue<string>(
+ message.workspaceFolder,
+ 'buildDir'
+ );
if (buildDir !== project.buildDir) {
updateQmlls = true;
project.buildDir = buildDir;
@@ -114,7 +132,8 @@ function processMessage(message: QtWorkspaceConfigMessage) {
}
}
if (updateQmlls) {
- project.updateQmlls();
+ project.updateQmllsParams();
+ void project.qmlls.restart();
}
} catch (e) {
const err = e as Error;
diff --git a/qt-qml/src/project.ts b/qt-qml/src/project.ts
index 08eb7dd..6a2c9bf 100644
--- a/qt-qml/src/project.ts
+++ b/qt-qml/src/project.ts
@@ -20,6 +20,12 @@ export async function createQMLProject(
export class QMLProjectManager extends ProjectManager<QMLProject> {
constructor(override readonly context: vscode.ExtensionContext) {
super(context, createQMLProject);
+ this.onProjectAdded((project) => {
+ logger.info('Adding project:', project.folder.uri.fsPath);
+ project.getConfigValues();
+ project.updateQmllsParams();
+ void project.qmlls.start();
+ });
}
async stopQmlls() {
const promises = [];
@@ -42,6 +48,16 @@ export class QMLProjectManager extends ProjectManager<QMLProject> {
}
return Promise.all(promises);
}
+ updateQmllsParams() {
+ for (const project of this.getProjects()) {
+ project.updateQmllsParams();
+ }
+ }
+ getConfigValues() {
+ for (const project of this.getProjects()) {
+ project.getConfigValues();
+ }
+ }
}
// Project class represents a workspace folder in the extension.
export class QMLProject implements Project {
@@ -55,7 +71,9 @@ export class QMLProject implements Project {
) {
logger.info('Creating project:', _folder.uri.fsPath);
this._qmlls = new Qmlls(_folder);
- void this.qmlls.start();
+ }
+ async startQmlls() {
+ return this.qmlls.start();
}
get kitPath() {
return this._kitPath;
@@ -69,7 +87,14 @@ export class QMLProject implements Project {
set qtpathsExe(qtpathsExe: string | undefined) {
this._qtpathsExe = qtpathsExe;
}
- updateQmlls() {
+
+ getConfigValues() {
+ this.kitPath = coreAPI?.getValue<string>(this.folder, 'selectedKitPath');
+ this.qtpathsExe = coreAPI?.getValue<string>(this.folder, 'selectedQtPaths');
+ this.buildDir = coreAPI?.getValue<string>(this.folder, 'buildDir');
+ }
+
+ updateQmllsParams() {
this.qmlls.clearImportPaths();
if (this.kitPath) {
this.qmlls.addImportPath(path.join(this.kitPath, 'qml'));
@@ -84,7 +109,6 @@ export class QMLProject implements Project {
}
this.qmlls.addImportPath(qmlImportPath);
}
- void this.qmlls.restart();
}
set buildDir(buildDir: string | undefined) {
this._buildDir = buildDir;
diff --git a/qt-qml/src/qmlls.ts b/qt-qml/src/qmlls.ts
index 1ffd2a5..a3f3061 100644
--- a/qt-qml/src/qmlls.ts
+++ b/qt-qml/src/qmlls.ts
@@ -41,6 +41,11 @@ export enum DecisionCode {
ErrorOccured
}
+export enum QmllsStatus {
+ running,
+ stopped
+}
+
export async function setDoNotAskForDownloadingQmlls(value: boolean) {
await vscode.workspace
.getConfiguration(EXTENSION_ID)
@@ -169,14 +174,17 @@ export class Qmlls {
if (options?.restart) {
void projectManager.startQmlls();
+ return QmllsStatus.running;
}
+ return QmllsStatus.stopped;
}
public static async checkAssetAndDecide() {
// Do not show the progress bar during the startup
const result = await fetchAssetAndDecide({ silent: true });
if (result.code === DecisionCode.NeedToUpdate && result.asset) {
- await Qmlls.install(result.asset);
+ return Qmlls.install(result.asset);
}
+ return QmllsStatus.stopped;
}
public async start() {
diff --git a/qt-ui/src/extension.ts b/qt-ui/src/extension.ts
index e130199..14a497a 100644
--- a/qt-ui/src/extension.ts
+++ b/qt-ui/src/extension.ts
@@ -41,7 +41,7 @@ export async function activate(context: vscode.ExtensionContext) {
projectManager = new ProjectManager<UIProject>(context, createUIProject);
projectManager.onProjectAdded(async (project) => {
- logger.info('Project added:', project.folder.uri.fsPath);
+ logger.info('Adding project:', project.folder.uri.fsPath);
const selectedKitPath = coreAPI?.getValue<string>(
project.folder,
'selectedKitPath'
@@ -51,13 +51,10 @@ export async function activate(context: vscode.ExtensionContext) {
'selectedQtPaths'
);
- const workspaceType = coreAPI?.getValue<QtWorkspaceType>(
+ project.workspaceType = coreAPI?.getValue<QtWorkspaceType>(
project.folder,
'workspaceType'
);
- if (workspaceType) {
- project.workspaceType = workspaceType;
- }
if (selectedKitPath) {
await project.setBinDir(selectedKitPath);
@@ -91,9 +88,16 @@ export async function activate(context: vscode.ExtensionContext) {
openWidgetDesigner
)
);
+ getConfigValues();
telemetry.sendEvent(`activated`);
}
+function getConfigValues() {
+ for (const project of projectManager.getProjects()) {
+ project.getConfigValues();
+ }
+}
+
export function deactivate() {
logger.info(`Deactivating ${EXTENSION_ID}`);
telemetry.dispose();
@@ -113,23 +117,30 @@ function processMessage(message: QtWorkspaceConfigMessage) {
for (const key of message.config.keys()) {
if (key === 'selectedKitPath') {
- const selectedKitPath = message.get<string>('selectedKitPath');
+ const selectedKitPath = coreAPI?.getValue<string>(
+ message.workspaceFolder,
+ 'selectedKitPath'
+ );
if (selectedKitPath !== project.binDir) {
void project.setBinDir(selectedKitPath);
}
continue;
}
if (key === 'selectedQtPaths') {
- const selectedQtPaths = message.get<string>('selectedQtPaths');
+ const selectedQtPaths = coreAPI?.getValue<string>(
+ message.workspaceFolder,
+ 'selectedQtPaths'
+ );
if (selectedQtPaths !== project.qtpathsExe) {
project.qtpathsExe = selectedQtPaths;
}
continue;
}
if (key === 'workspaceType') {
- project.workspaceType = message.config.get(
+ project.workspaceType = coreAPI?.getValue<QtWorkspaceType>(
+ message.workspaceFolder,
'workspaceType'
- ) as QtWorkspaceType;
+ );
}
}
}
diff --git a/qt-ui/src/project.ts b/qt-ui/src/project.ts
index 2749f8e..f0f2232 100644
--- a/qt-ui/src/project.ts
+++ b/qt-ui/src/project.ts
@@ -15,6 +15,7 @@ import {
locateDesignerFromQtPaths
} from '@/util';
import { CONF_CUSTOM_WIDGETS_DESIGNER_EXE_PATH } from '@/constants';
+import { coreAPI } from '@/extension';
const logger = createLogger('project');
@@ -164,6 +165,18 @@ export class UIProject implements Project {
get folder() {
return this._folder;
}
+ public getConfigValues() {
+ const selectedKitPath = coreAPI?.getValue<string>(
+ this.folder,
+ 'selectedKitPath'
+ );
+ void this.setBinDir(selectedKitPath);
+ this.qtpathsExe = coreAPI?.getValue<string>(this.folder, 'selectedQtPaths');
+ this.workspaceType = coreAPI?.getValue<QtWorkspaceType>(
+ this.folder,
+ 'workspaceType'
+ );
+ }
private static checkCustomDesignerExePath(
customWidgetsDesignerExePath: string