aboutsummaryrefslogtreecommitdiffstats
path: root/qt-cpp
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 /qt-cpp
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>
Diffstat (limited to 'qt-cpp')
-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
3 files changed, 64 insertions, 44 deletions
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();
+ }
+ }
}