From 3f0d31dd62f93d55d4b25aa1c69f3b8a4447dde8 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Thu, 27 Jul 2023 23:40:46 +0300 Subject: [PATCH 1/9] Prototype outline update --- src/extension.ts | 30 +++++++++++++++++++++--------- src/projectOutline.ts | 31 ++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index c0402dda8..226b44e27 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -265,7 +265,7 @@ export class ExtensionManager implements vscode.Disposable { /** * The project outline tree data provider */ - private readonly projectOutline = new ProjectOutline(); + private readonly projectOutline = new ProjectOutline(this.projectController); private readonly projectOutlineTreeView = vscode.window.createTreeView('cmake.outline', { treeDataProvider: this.projectOutline, showCollapseAll: true @@ -1064,7 +1064,7 @@ export class ExtensionManager implements vscode.Disposable { return 0; } - private getProjectFromFolder(folder?: vscode.WorkspaceFolder | string) { + private getProjectFromFolder(folder?: vscode.WorkspaceFolder | string, sourceDir?: string) { const workspaceFolder: vscode.WorkspaceFolder | undefined = this.getWorkspaceFolder(folder); if (workspaceFolder) { const activeProject: CMakeProject | undefined = this.getActiveProject(); @@ -1072,6 +1072,14 @@ export class ExtensionManager implements vscode.Disposable { if (!projects || projects.length === 0) { return activeProject; } else { + if (sourceDir) { + for (const project of projects) { + // Choose the active project. + if (path.normalize(sourceDir) === path.normalize(project.folderPath)) { + return project; + } + } + } for (const project of projects) { // Choose the active project. if (activeProject?.folderPath === project.folderPath) { @@ -1085,11 +1093,11 @@ export class ExtensionManager implements vscode.Disposable { return undefined; } - runCMakeCommand(command: RunCMakeCommand, folder?: vscode.WorkspaceFolder, precheck?: (cmakeProject: CMakeProject) => Promise, cleanOutputChannel?: boolean): Promise { + runCMakeCommand(command: RunCMakeCommand, folder?: vscode.WorkspaceFolder, precheck?: (cmakeProject: CMakeProject) => Promise, cleanOutputChannel?: boolean, sourceDir?: string): Promise { if (cleanOutputChannel) { this.cleanOutputChannel(); } - const project = this.getProjectFromFolder(folder); + const project = this.getProjectFromFolder(folder, sourceDir); if (project) { return this.runCMakeCommandForProject(command, project, precheck); } @@ -1177,13 +1185,17 @@ export class ExtensionManager implements vscode.Disposable { return this.runCMakeCommand(cmakeProject => cmakeProject.editCacheUI()); } - build(folder?: vscode.WorkspaceFolder, name?: string, showCommandOnly?: boolean, isBuildCommand?: boolean) { + build(folder?: vscode.WorkspaceFolder, name?: string, sourceDir?: string, showCommandOnly?: boolean, isBuildCommand?: boolean) { telemetry.logEvent("build", { all: "false"}); - return this.runCMakeCommand(cmakeProject => cmakeProject.build(name ? [name] : undefined, showCommandOnly, (isBuildCommand === undefined) ? true : isBuildCommand), folder, this.ensureActiveBuildPreset, true); + return this.runCMakeCommand(cmakeProject => cmakeProject.build(name ? [name] : undefined, showCommandOnly, (isBuildCommand === undefined) ? true : isBuildCommand), + folder, + this.ensureActiveBuildPreset, + true, + sourceDir); } showBuildCommand(folder?: vscode.WorkspaceFolder, name?: string) { - return this.build(folder, name, true, false); + return this.build(folder, name, undefined, true, false); } buildAll(name?: string | string[]) { @@ -1238,7 +1250,7 @@ export class ExtensionManager implements vscode.Disposable { clean(folder?: vscode.WorkspaceFolder) { telemetry.logEvent("clean", { all: "false"}); - return this.build(folder, 'clean', undefined, false); + return this.build(folder, 'clean', undefined, undefined, false); } cleanAll() { @@ -1860,7 +1872,7 @@ async function setup(context: vscode.ExtensionContext, progress?: ProgressHandle vscode.commands.registerCommand('cmake.outline.editCacheUI', () => runCommand('editCacheUI')), vscode.commands.registerCommand('cmake.outline.cleanRebuildAll', () => runCommand('cleanRebuildAll')), // Commands for outline items - vscode.commands.registerCommand('cmake.outline.buildTarget', (what: TargetNode) => runCommand('build', what.folder, what.name)), + vscode.commands.registerCommand('cmake.outline.buildTarget', (what: TargetNode) => runCommand('build', what.folder, what.name, what.sourceDir)), vscode.commands.registerCommand('cmake.outline.runUtilityTarget', (what: TargetNode) => runCommand('build', what.folder, what.name)), vscode.commands.registerCommand('cmake.outline.debugTarget', (what: TargetNode) => runCommand('debugTarget', what.folder, what.name)), vscode.commands.registerCommand('cmake.outline.launchTarget', (what: TargetNode) => runCommand('launchTarget', what.folder, what.name)), diff --git a/src/projectOutline.ts b/src/projectOutline.ts index ce1d308ad..474cfa9e1 100644 --- a/src/projectOutline.ts +++ b/src/projectOutline.ts @@ -4,6 +4,8 @@ import * as nls from 'vscode-nls'; import * as codeModel from '@cmt/drivers/codeModel'; import rollbar from '@cmt/rollbar'; import { lexicographicalCompare, splitPath } from '@cmt/util'; +import { ProjectController} from '@cmt/projectController'; +import CMakeProject from '@cmt/cmakeProject'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); @@ -489,19 +491,31 @@ export class WorkspaceFolderNode extends BaseNode { get codeModel() { return this._codeModel; } - updateCodeModel(model: codeModel.CodeModelContent | null, ctx: TreeUpdateContext) { + updateCodeModel(model: codeModel.CodeModelContent | null, ctx: TreeUpdateContext, projects: CMakeProject[] | undefined) { if (!model || model.configurations.length < 1) { this._children = []; ctx.nodesToUpdate.push(this); return; } this._codeModel = model; - const config = model.configurations[0]; + // const config = model.configurations[0]; const new_children: BaseNode[] = []; - for (const pr of config.projects) { - const item = new ProjectNode(pr.name, ctx.folder, pr.sourceDirectory); - item.update(pr, ctx); - new_children.push(item); + if (projects) { + for (const cmakeProj of projects) { + const amodel: codeModel.CodeModelContent | null = cmakeProj.codeModelContent; + if (amodel) { + for (const modelProj of amodel.configurations[0].projects) { + const item = new ProjectNode(modelProj.name, ctx.folder, cmakeProj.folderPath); + item.update(modelProj, + { + ...ctx, + defaultTarget: cmakeProj.defaultBuildTarget || undefined, + launchTargetName: cmakeProj.launchTargetName + }); + new_children.push(item); + } + } + } } this._children = new_children; } @@ -512,6 +526,9 @@ export class WorkspaceFolderNode extends BaseNode { } export class ProjectOutline implements vscode.TreeDataProvider { + constructor(readonly projectController: ProjectController) { + + } private readonly _changeEvent = new vscode.EventEmitter(); get onDidChangeTreeData() { return this._changeEvent.event; @@ -546,7 +563,7 @@ export class ProjectOutline implements vscode.TreeDataProvider { } const updates: BaseNode[] = []; - existing.updateCodeModel(model, { ...ctx, nodesToUpdate: updates, folder }); + existing.updateCodeModel(model, { ...ctx, nodesToUpdate: updates, folder }, this.projectController.getProjectsForWorkspaceFolder(folder)); this._changeEvent.fire(null); } From 8dfdc78139632bf654f7fb4e92326fa5c34f2809 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Sat, 29 Jul 2023 12:39:40 +0300 Subject: [PATCH 2/9] Replace "for" by "find" --- src/extension.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 226b44e27..91fbae3aa 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1072,22 +1072,12 @@ export class ExtensionManager implements vscode.Disposable { if (!projects || projects.length === 0) { return activeProject; } else { - if (sourceDir) { - for (const project of projects) { - // Choose the active project. - if (path.normalize(sourceDir) === path.normalize(project.folderPath)) { - return project; - } - } - } - for (const project of projects) { - // Choose the active project. - if (activeProject?.folderPath === project.folderPath) { - return project; - } - } - // Choose the first project folder. - return projects[0]; + // Choose project by corresponding source directory + return projects.find(project => sourceDir && (path.normalize(sourceDir) === path.normalize(project.folderPath))) ?? + // Choose project by folder of active project + projects.find(project => activeProject?.folderPath === project.folderPath) ?? + // Fallback to first project + projects[0]; } } return undefined; From a55f45a05e242a81d0e0a63d35ec90b71189e450 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Sat, 29 Jul 2023 14:15:28 +0300 Subject: [PATCH 3/9] Provide source dir for target node commands --- src/extension.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 91fbae3aa..0f2cd0858 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1198,8 +1198,8 @@ export class ExtensionManager implements vscode.Disposable { true); } - setDefaultTarget(folder?: vscode.WorkspaceFolder, name?: string) { - return this.runCMakeCommand(cmakeProject => cmakeProject.setDefaultTarget(name), folder); + setDefaultTarget(folder?: vscode.WorkspaceFolder, name?: string, sourceDir?: string) { + return this.runCMakeCommand(cmakeProject => cmakeProject.setDefaultTarget(name), folder, undefined, undefined, sourceDir); } setVariant(folder?: vscode.WorkspaceFolder, name?: string) { @@ -1423,9 +1423,9 @@ export class ExtensionManager implements vscode.Disposable { return this.queryCMakeProject(cmakeProject => cmakeProject.tasksBuildCommand(), folder); } - debugTarget(folder?: vscode.WorkspaceFolder, name?: string): Promise { + debugTarget(folder?: vscode.WorkspaceFolder, name?: string, sourceDir?: string): Promise { telemetry.logEvent("debug", { all: "false" }); - return this.runCMakeCommand(cmakeProject => cmakeProject.debugTarget(name), folder); + return this.runCMakeCommand(cmakeProject => cmakeProject.debugTarget(name), folder, undefined, undefined, sourceDir); } async debugTargetAll(): Promise<(vscode.DebugSession | null)[]> { @@ -1437,9 +1437,9 @@ export class ExtensionManager implements vscode.Disposable { return debugSessions; } - launchTarget(folder?: vscode.WorkspaceFolder, name?: string): Promise { + launchTarget(folder?: vscode.WorkspaceFolder, name?: string, sourceDir?: string): Promise { telemetry.logEvent("launch", { all: "false" }); - return this.runCMakeCommand(cmakeProject => cmakeProject.launchTarget(name), folder); + return this.runCMakeCommand(cmakeProject => cmakeProject.launchTarget(name), folder, undefined, undefined, sourceDir); } async launchTargetAll(): Promise<(vscode.Terminal | null)[]> { @@ -1451,8 +1451,8 @@ export class ExtensionManager implements vscode.Disposable { return terminals; } - selectLaunchTarget(folder?: vscode.WorkspaceFolder, name?: string) { - return this.runCMakeCommand(cmakeProject => cmakeProject.selectLaunchTarget(name), folder); + selectLaunchTarget(folder?: vscode.WorkspaceFolder, name?: string, sourceDir?: string) { + return this.runCMakeCommand(cmakeProject => cmakeProject.selectLaunchTarget(name), folder, undefined, undefined, sourceDir); } async resetState(folder?: vscode.WorkspaceFolder) { @@ -1863,11 +1863,11 @@ async function setup(context: vscode.ExtensionContext, progress?: ProgressHandle vscode.commands.registerCommand('cmake.outline.cleanRebuildAll', () => runCommand('cleanRebuildAll')), // Commands for outline items vscode.commands.registerCommand('cmake.outline.buildTarget', (what: TargetNode) => runCommand('build', what.folder, what.name, what.sourceDir)), - vscode.commands.registerCommand('cmake.outline.runUtilityTarget', (what: TargetNode) => runCommand('build', what.folder, what.name)), - vscode.commands.registerCommand('cmake.outline.debugTarget', (what: TargetNode) => runCommand('debugTarget', what.folder, what.name)), - vscode.commands.registerCommand('cmake.outline.launchTarget', (what: TargetNode) => runCommand('launchTarget', what.folder, what.name)), - vscode.commands.registerCommand('cmake.outline.setDefaultTarget', (what: TargetNode) => runCommand('setDefaultTarget', what.folder, what.name)), - vscode.commands.registerCommand('cmake.outline.setLaunchTarget', (what: TargetNode) => runCommand('selectLaunchTarget', what.folder, what.name)), + vscode.commands.registerCommand('cmake.outline.runUtilityTarget', (what: TargetNode) => runCommand('build', what.folder, what.name, what.sourceDir)), + vscode.commands.registerCommand('cmake.outline.debugTarget', (what: TargetNode) => runCommand('debugTarget', what.folder, what.name, what.sourceDir)), + vscode.commands.registerCommand('cmake.outline.launchTarget', (what: TargetNode) => runCommand('launchTarget', what.folder, what.name, what.sourceDir)), + vscode.commands.registerCommand('cmake.outline.setDefaultTarget', (what: TargetNode) => runCommand('setDefaultTarget', what.folder, what.name, what.sourceDir)), + vscode.commands.registerCommand('cmake.outline.setLaunchTarget', (what: TargetNode) => runCommand('selectLaunchTarget', what.folder, what.name, what.sourceDir)), vscode.commands.registerCommand('cmake.outline.revealInCMakeLists', (what: TargetNode) => what.openInCMakeLists()), vscode.commands.registerCommand('cmake.outline.compileFile', (what: SourceFileNode) => runCommand('compileFile', what.filePath)), // vscode.commands.registerCommand('cmake.outline.selectWorkspace', (what: WorkspaceFolderNode) => runCommand('selectWorkspace', what.wsFolder)) From 0ade525325f5a9437078c86e5730b0d36bb5f454 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Sat, 29 Jul 2023 14:31:41 +0300 Subject: [PATCH 4/9] Make formating the same --- src/extension.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 0f2cd0858..7b815d4a4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1177,11 +1177,14 @@ export class ExtensionManager implements vscode.Disposable { build(folder?: vscode.WorkspaceFolder, name?: string, sourceDir?: string, showCommandOnly?: boolean, isBuildCommand?: boolean) { telemetry.logEvent("build", { all: "false"}); - return this.runCMakeCommand(cmakeProject => cmakeProject.build(name ? [name] : undefined, showCommandOnly, (isBuildCommand === undefined) ? true : isBuildCommand), - folder, - this.ensureActiveBuildPreset, - true, - sourceDir); + return this.runCMakeCommand(cmakeProject => { + const targets = name ? [name] : undefined; + return cmakeProject.build(targets, showCommandOnly, (isBuildCommand === undefined) ? true : isBuildCommand); + }, + folder, + this.ensureActiveBuildPreset, + true, + sourceDir); } showBuildCommand(folder?: vscode.WorkspaceFolder, name?: string) { From ac7396dfc9d7afbf3565e9eadc2731e77805ed76 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Sat, 29 Jul 2023 16:05:07 +0300 Subject: [PATCH 5/9] Update by code model update not projectcontroller --- src/extension.ts | 2 ++ src/projectOutline.ts | 65 +++++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7b815d4a4..9694a4f4b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -630,6 +630,7 @@ export class ExtensionManager implements vscode.Disposable { } const folder: vscode.WorkspaceFolder = cmakeProject.workspaceFolder; this.projectOutline.updateCodeModel( + cmakeProject, cmakeProject.workspaceContext.folder, cmakeProject.codeModelContent, { @@ -698,6 +699,7 @@ export class ExtensionManager implements vscode.Disposable { codeModelContent = drv.codeModelContent; this.configProvider.updateConfigurationData({ cache, codeModelContent, clCompilerPath, activeTarget: cmakeProject.defaultBuildTarget, activeBuildTypeVariant: actualBuildType, folder: cmakeProject.folderPath }); this.projectOutline.updateCodeModel( + cmakeProject, cmakeProject.workspaceContext.folder, codeModelContent, { diff --git a/src/projectOutline.ts b/src/projectOutline.ts index 474cfa9e1..653abbed1 100644 --- a/src/projectOutline.ts +++ b/src/projectOutline.ts @@ -402,7 +402,7 @@ class ProjectNode extends BaseNode { private readonly _rootDir = new DirectoryNode(this.id, '', ''); getOrderTuple() { - return []; + return [this.sourceDirectory, this.name]; } getChildren() { @@ -461,7 +461,6 @@ export class WorkspaceFolderNode extends BaseNode { constructor(readonly wsFolder: vscode.WorkspaceFolder) { super(`wsf/${wsFolder.uri.fsPath}`); } - private _children: BaseNode[] = []; private _active: boolean = false; setActive(active: boolean) { @@ -487,47 +486,53 @@ export class WorkspaceFolderNode extends BaseNode { return item; } - private _codeModel: codeModel.CodeModelContent = { configurations: [], toolchains: new Map() }; - get codeModel() { - return this._codeModel; + private readonly _projects = new Map>(); + + private getNode(cmakeProject: CMakeProject, modelProjectName: string) { + return this._projects.get(cmakeProject.folderPath)?.get(modelProjectName); + } + + private setNode(cmakeProject: CMakeProject, modelProjectName: string, node: ProjectNode) { + let sub_map = this._projects.get(cmakeProject.folderPath); + if (!sub_map) { + sub_map = new Map(); + this._projects.set(cmakeProject.folderPath, sub_map); + } + return sub_map.set(modelProjectName, node); + } + + private removeNodes(cmakeProject: CMakeProject) { + this._projects.delete(cmakeProject.folderPath); } - updateCodeModel(model: codeModel.CodeModelContent | null, ctx: TreeUpdateContext, projects: CMakeProject[] | undefined) { + + updateCodeModel(model: codeModel.CodeModelContent | null, ctx: TreeUpdateContext, cmakeProject: CMakeProject) { if (!model || model.configurations.length < 1) { - this._children = []; + this.removeNodes(cmakeProject); ctx.nodesToUpdate.push(this); return; } - this._codeModel = model; - // const config = model.configurations[0]; - const new_children: BaseNode[] = []; - if (projects) { - for (const cmakeProj of projects) { - const amodel: codeModel.CodeModelContent | null = cmakeProj.codeModelContent; - if (amodel) { - for (const modelProj of amodel.configurations[0].projects) { - const item = new ProjectNode(modelProj.name, ctx.folder, cmakeProj.folderPath); - item.update(modelProj, - { - ...ctx, - defaultTarget: cmakeProj.defaultBuildTarget || undefined, - launchTargetName: cmakeProj.launchTargetName - }); - new_children.push(item); - } - } + + for (const modelProj of model.configurations[0].projects) { + let item = this.getNode(cmakeProject, modelProj.name); + if (!item) { + item = new ProjectNode(modelProj.name, this.wsFolder, cmakeProject.folderPath); + this.setNode(cmakeProject, modelProj.name, item); } + item?.update(modelProj, ctx); } - this._children = new_children; } getChildren() { - return this._children; + const children: BaseNode[] = []; + for (const sub_map of this._projects.values()) { + children.push(...sub_map.values()); + } + return children.sort((a, b) => lexicographicalCompare(a.getOrderTuple(), b.getOrderTuple())); } } export class ProjectOutline implements vscode.TreeDataProvider { constructor(readonly projectController: ProjectController) { - } private readonly _changeEvent = new vscode.EventEmitter(); get onDidChangeTreeData() { @@ -553,7 +558,7 @@ export class ProjectOutline implements vscode.TreeDataProvider { this._changeEvent.fire(null); } - updateCodeModel(folder: vscode.WorkspaceFolder, model: codeModel.CodeModelContent | null, ctx: ExternalUpdateContext) { + updateCodeModel(cmakeProject: CMakeProject, folder: vscode.WorkspaceFolder, model: codeModel.CodeModelContent | null, ctx: ExternalUpdateContext) { let existing = this._folders.get(folder.uri.fsPath); if (!existing) { rollbar.error(localize('error.update.code.model.on.nonexist.folder', 'Updating code model on folder that has not yet been loaded.')); @@ -563,7 +568,7 @@ export class ProjectOutline implements vscode.TreeDataProvider { } const updates: BaseNode[] = []; - existing.updateCodeModel(model, { ...ctx, nodesToUpdate: updates, folder }, this.projectController.getProjectsForWorkspaceFolder(folder)); + existing.updateCodeModel(model, { ...ctx, nodesToUpdate: updates, folder }, cmakeProject); this._changeEvent.fire(null); } From 32fd2698aaae52c0c9099636fad952ff763f2abc Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Sat, 29 Jul 2023 16:20:27 +0300 Subject: [PATCH 6/9] Pass cmake project to remove duplication --- src/extension.ts | 20 ++------------------ src/projectOutline.ts | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9694a4f4b..a38485798 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -629,15 +629,7 @@ export class ExtensionManager implements vscode.Disposable { return; } const folder: vscode.WorkspaceFolder = cmakeProject.workspaceFolder; - this.projectOutline.updateCodeModel( - cmakeProject, - cmakeProject.workspaceContext.folder, - cmakeProject.codeModelContent, - { - defaultTarget: cmakeProject.defaultBuildTarget || undefined, - launchTargetName: cmakeProject.launchTargetName - } - ); + this.projectOutline.updateCodeModel(cmakeProject, cmakeProject.codeModelContent); rollbar.invokeAsync(localize('update.code.model.for.cpptools', 'Update code model for cpptools'), {}, async () => { if (vscode.workspace.getConfiguration('C_Cpp', folder.uri).get('intelliSenseEngine')?.toLocaleLowerCase() === 'disabled') { log.debug(localize('update.intellisense.disabled', 'Not updating the configuration provider because {0} is set to {1}', '"C_Cpp.intelliSenseEngine"', '"Disabled"')); @@ -698,15 +690,7 @@ export class ExtensionManager implements vscode.Disposable { } else if (drv && drv.codeModelContent) { codeModelContent = drv.codeModelContent; this.configProvider.updateConfigurationData({ cache, codeModelContent, clCompilerPath, activeTarget: cmakeProject.defaultBuildTarget, activeBuildTypeVariant: actualBuildType, folder: cmakeProject.folderPath }); - this.projectOutline.updateCodeModel( - cmakeProject, - cmakeProject.workspaceContext.folder, - codeModelContent, - { - defaultTarget: cmakeProject.defaultBuildTarget || undefined, - launchTargetName: cmakeProject.launchTargetName - } - ); + this.projectOutline.updateCodeModel(cmakeProject, codeModelContent); } // Inform cpptools that custom CppConfigurationProvider will be able to service the current workspace. this.ensureCppToolsProviderRegistered(); diff --git a/src/projectOutline.ts b/src/projectOutline.ts index 653abbed1..db81969e3 100644 --- a/src/projectOutline.ts +++ b/src/projectOutline.ts @@ -505,7 +505,7 @@ export class WorkspaceFolderNode extends BaseNode { this._projects.delete(cmakeProject.folderPath); } - updateCodeModel(model: codeModel.CodeModelContent | null, ctx: TreeUpdateContext, cmakeProject: CMakeProject) { + updateCodeModel(cmakeProject: CMakeProject, model: codeModel.CodeModelContent | null, ctx: TreeUpdateContext) { if (!model || model.configurations.length < 1) { this.removeNodes(cmakeProject); ctx.nodesToUpdate.push(this); @@ -558,7 +558,8 @@ export class ProjectOutline implements vscode.TreeDataProvider { this._changeEvent.fire(null); } - updateCodeModel(cmakeProject: CMakeProject, folder: vscode.WorkspaceFolder, model: codeModel.CodeModelContent | null, ctx: ExternalUpdateContext) { + updateCodeModel(cmakeProject: CMakeProject, model: codeModel.CodeModelContent | null) { + const folder = cmakeProject.workspaceContext.folder; let existing = this._folders.get(folder.uri.fsPath); if (!existing) { rollbar.error(localize('error.update.code.model.on.nonexist.folder', 'Updating code model on folder that has not yet been loaded.')); @@ -568,7 +569,15 @@ export class ProjectOutline implements vscode.TreeDataProvider { } const updates: BaseNode[] = []; - existing.updateCodeModel(model, { ...ctx, nodesToUpdate: updates, folder }, cmakeProject); + existing.updateCodeModel( + cmakeProject, + model, + { + defaultTarget: cmakeProject.defaultBuildTarget || undefined, + launchTargetName: cmakeProject.launchTargetName, + nodesToUpdate: updates, + folder + }); this._changeEvent.fire(null); } From e88d844ac351e56a8ac29b34a1b7ba52656f0841 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Sat, 29 Jul 2023 18:41:19 +0300 Subject: [PATCH 7/9] Remove unused project controller --- src/extension.ts | 2 +- src/projectOutline.ts | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a38485798..653915737 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -265,7 +265,7 @@ export class ExtensionManager implements vscode.Disposable { /** * The project outline tree data provider */ - private readonly projectOutline = new ProjectOutline(this.projectController); + private readonly projectOutline = new ProjectOutline(); private readonly projectOutlineTreeView = vscode.window.createTreeView('cmake.outline', { treeDataProvider: this.projectOutline, showCollapseAll: true diff --git a/src/projectOutline.ts b/src/projectOutline.ts index db81969e3..b333af277 100644 --- a/src/projectOutline.ts +++ b/src/projectOutline.ts @@ -4,7 +4,6 @@ import * as nls from 'vscode-nls'; import * as codeModel from '@cmt/drivers/codeModel'; import rollbar from '@cmt/rollbar'; import { lexicographicalCompare, splitPath } from '@cmt/util'; -import { ProjectController} from '@cmt/projectController'; import CMakeProject from '@cmt/cmakeProject'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); @@ -452,11 +451,6 @@ class ProjectNode extends BaseNode { } } -interface ExternalUpdateContext { - launchTargetName: string | null; - defaultTarget?: string; -} - export class WorkspaceFolderNode extends BaseNode { constructor(readonly wsFolder: vscode.WorkspaceFolder) { super(`wsf/${wsFolder.uri.fsPath}`); @@ -518,7 +512,7 @@ export class WorkspaceFolderNode extends BaseNode { item = new ProjectNode(modelProj.name, this.wsFolder, cmakeProject.folderPath); this.setNode(cmakeProject, modelProj.name, item); } - item?.update(modelProj, ctx); + item.update(modelProj, ctx); } } @@ -532,8 +526,6 @@ export class WorkspaceFolderNode extends BaseNode { } export class ProjectOutline implements vscode.TreeDataProvider { - constructor(readonly projectController: ProjectController) { - } private readonly _changeEvent = new vscode.EventEmitter(); get onDidChangeTreeData() { return this._changeEvent.event; From 7e14c2f5d484de36eaab87968ff48dd2fafa1b70 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Fri, 8 Sep 2023 21:27:02 +0300 Subject: [PATCH 8/9] Indent long return statement --- src/extension.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 3ed74063b..7d792f1bf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1039,11 +1039,11 @@ export class ExtensionManager implements vscode.Disposable { return activeProject; } else { // Choose project by corresponding source directory - return projects.find(project => sourceDir && (path.normalize(sourceDir) === path.normalize(project.folderPath))) ?? - // Choose project by folder of active project - projects.find(project => activeProject?.folderPath === project.folderPath) ?? - // Fallback to first project - projects[0]; + return projects.find(project => sourceDir && (path.normalize(sourceDir) === path.normalize(project.folderPath))) + // Choose project by folder of active project + ?? projects.find(project => activeProject?.folderPath === project.folderPath) + // Fallback to first project + ?? projects[0]; } } return undefined; From 014acc7a69972ca5846b9a143ee8a74d9c219e94 Mon Sep 17 00:00:00 2001 From: VlaVaTi Date: Thu, 14 Sep 2023 21:30:02 +0300 Subject: [PATCH 9/9] Add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3a954a8a..0184aa1a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Features: - Support different debug config for different targets. [PR #2801](https://github.com/microsoft/vscode-cmake-tools/pull/2801) [@RichardLuo0](https://github.com/RichardLuo0) +Improvements: +- In multi-root workspace, the Project Outline View now shows all configured projects. [PR #3270](https://github.com/microsoft/vscode-cmake-tools/pull/3270) [@vlavati](https://github.com/vlavati) + ## 1.15 Features: - Added support for the CMake Debugger. [#3093](https://github.com/microsoft/vscode-cmake-tools/issues/3093)