aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOrkun Tokdemir <orkun.tokdemir@qt.io>2024-11-20 16:39:02 +0100
committerOrkun Tokdemir <orkun.tokdemir@qt.io>2024-11-25 13:14:44 +0000
commit5928f1e4df631d0edce29e684de7c68b4ab1d4a7 (patch)
tree3fa1287ee30943a08602274e7aed87ff29ea781d
parent121abdb88f6b79f8e8d247212f76d06cadcf3c91 (diff)
qt-cpp: qt-qml: Add build directory
* Pass the build directory to qmlls with `-b` * Detect the build directory change from the CMake extension Change-Id: I8279b444036e174762f9d469fd8b4abdaba66e83 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
-rw-r--r--qt-cpp/src/extension.ts1
-rw-r--r--qt-cpp/src/project.ts27
-rw-r--r--qt-qml/src/extension.ts7
-rw-r--r--qt-qml/src/project.ts8
-rw-r--r--qt-qml/src/qmlls.ts12
5 files changed, 53 insertions, 2 deletions
diff --git a/qt-cpp/src/extension.ts b/qt-cpp/src/extension.ts
index 809435c..a3bad17 100644
--- a/qt-cpp/src/extension.ts
+++ b/qt-cpp/src/extension.ts
@@ -119,6 +119,7 @@ export async function initCoreValues() {
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);
}
diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts
index ad8fbf9..a7037a2 100644
--- a/qt-cpp/src/project.ts
+++ b/qt-cpp/src/project.ts
@@ -26,20 +26,26 @@ export async function createCppProject(
if (api) {
cmakeProject = await api.getProject(folder.uri);
}
- return Promise.resolve(new CppProject(folder, context, cmakeProject));
+ const buildDir = await cmakeProject?.getBuildDirectory();
+ return Promise.resolve(
+ new CppProject(folder, context, cmakeProject, buildDir)
+ );
}
// Project class represents a workspace folder in the extension.
export class CppProject implements Project {
private readonly _stateManager: WorkspaceStateManager;
private readonly _cmakeProject: cmakeApi.Project | undefined;
+ private _buildDir: string | undefined;
constructor(
private readonly _folder: vscode.WorkspaceFolder,
readonly _context: vscode.ExtensionContext,
- cmakeProject: cmakeApi.Project | undefined
+ cmakeProject: cmakeApi.Project | undefined,
+ buildDir: string | undefined
) {
this._cmakeProject = cmakeProject;
this._stateManager = new WorkspaceStateManager(_context, _folder);
+ this._buildDir = buildDir;
if (this._cmakeProject) {
this._cmakeProject.onSelectedConfigurationChanged(
@@ -56,6 +62,20 @@ export class CppProject implements Project {
}
}
);
+ this._cmakeProject.onCodeModelChanged(async () => {
+ const prevbuildDir = this._buildDir;
+ const currentBuildDir = await this._cmakeProject?.getBuildDirectory();
+ if (prevbuildDir !== currentBuildDir) {
+ logger.info(
+ 'Build directory changed:',
+ currentBuildDir ?? 'undefined'
+ );
+ this._buildDir = currentBuildDir;
+ const message = new QtWorkspaceConfigMessage(this.folder);
+ message.config.set('buildDir', currentBuildDir);
+ coreAPI?.update(message);
+ }
+ });
}
}
@@ -65,6 +85,9 @@ export class CppProject implements Project {
get folder() {
return this._folder;
}
+ get buildDir() {
+ return this._buildDir;
+ }
dispose() {
logger.info('Disposing project:', this._folder.uri.fsPath);
diff --git a/qt-qml/src/extension.ts b/qt-qml/src/extension.ts
index c580591..db80a7b 100644
--- a/qt-qml/src/extension.ts
+++ b/qt-qml/src/extension.ts
@@ -98,6 +98,13 @@ function processMessage(message: QtWorkspaceConfigMessage) {
}
continue;
}
+ if (key === 'buildDir') {
+ const buildDir = message.get<string>('buildDir');
+ if (buildDir !== project.buildDir) {
+ updateQmlls = true;
+ project.buildDir = buildDir;
+ }
+ }
}
if (updateQmlls) {
project.updateQmlls();
diff --git a/qt-qml/src/project.ts b/qt-qml/src/project.ts
index ac858f3..f896841 100644
--- a/qt-qml/src/project.ts
+++ b/qt-qml/src/project.ts
@@ -48,6 +48,7 @@ export class QMLProject implements Project {
_qmlls: Qmlls;
_qtpathsExe: string | undefined;
_kitPath: string | undefined;
+ _buildDir: string | undefined;
public constructor(
readonly _folder: vscode.WorkspaceFolder,
readonly _context: vscode.ExtensionContext
@@ -85,6 +86,13 @@ export class QMLProject implements Project {
}
void this.qmlls.restart();
}
+ set buildDir(buildDir: string | undefined) {
+ this._buildDir = buildDir;
+ this.qmlls.buildDir = buildDir;
+ }
+ get buildDir() {
+ return this._buildDir;
+ }
get folder() {
return this._folder;
}
diff --git a/qt-qml/src/qmlls.ts b/qt-qml/src/qmlls.ts
index 428d5af..4fe694e 100644
--- a/qt-qml/src/qmlls.ts
+++ b/qt-qml/src/qmlls.ts
@@ -97,6 +97,7 @@ export class Qmlls {
private readonly _importPaths = new Set<string>();
private _client: LanguageClient | undefined;
private _channel: vscode.OutputChannel | undefined;
+ private _buildDir: string | undefined;
constructor(readonly _folder: vscode.WorkspaceFolder) {
vscode.workspace.onDidChangeConfiguration((event) => {
@@ -105,6 +106,12 @@ export class Qmlls {
}
});
}
+ set buildDir(buildDir: string | undefined) {
+ this._buildDir = buildDir;
+ }
+ get buildDir() {
+ return this._buildDir;
+ }
addImportPath(importPath: string) {
this._importPaths.add(importPath);
@@ -225,6 +232,11 @@ export class Qmlls {
if (useQmlImportPathEnvVar) {
args.push('-E');
}
+
+ if (this._buildDir) {
+ args.push(`-b${this._buildDir}`);
+ }
+
const additionalImportPaths = configs.get<string[]>(
'additionalImportPaths',
[]