From 744fe060d545b379e787a52d1ac8777806f97931 Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Fri, 2 Aug 2024 01:20:39 +0200 Subject: [PATCH] added FOLDER grouping in default build target dropdown --- src/cmakeProject.ts | 73 ++++++++++++++++++++++++++------ src/drivers/cmakeDriver.ts | 4 +- src/drivers/cmakeFileApi.ts | 1 + src/drivers/cmakeServerDriver.ts | 2 +- 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/cmakeProject.ts b/src/cmakeProject.ts index 6e66b9b35..55cfe36ff 100644 --- a/src/cmakeProject.ts +++ b/src/cmakeProject.ts @@ -52,6 +52,7 @@ import { ProjectController } from './projectController'; import { MessageItem } from 'vscode'; import { DebugTrackerFactory, DebuggerInformation, getDebuggerPipeName } from './debug/debuggerConfigureDriver'; import { ConfigurationType } from 'vscode-cmake-tools'; +import { NamedTarget, RichTarget } from '@cmt/drivers/cmakeDriver'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); @@ -119,6 +120,15 @@ export interface DiagnosticsSettings { configureOnOpen: boolean | null; } +/** + * A target with a name, but no output. Only used for targets that have a + * folder property. + */ +interface FolderTarget { + type: 'folder'; + name: string; +} + /** * Class implementing the extension. It's all here! * @@ -2181,21 +2191,60 @@ export class CMakeProject { if (!drv.targets.length) { return await vscode.window.showInputBox({ prompt: localize('enter.target.name', 'Enter a target name') }) || null; } else { - const choices = drv.uniqueTargets.map((t): vscode.QuickPickItem => { - switch (t.type) { - case 'named': { - return { - label: t.name, - description: localize('target.to.build.description', 'Target to build') - }; + type Target = RichTarget | NamedTarget | FolderTarget; + let currentFolder: string | undefined; + + for (let i = 0; i < 2; i++) { + const items: Target[] = []; + const folders: string[] = []; + + drv.uniqueTargets.forEach((t) => { + if (!currentFolder) { + if (t.type === 'named') { + items.push(t); + } else if (t.type === 'rich') { + if (!t.folder) { + items.push(t); + } else if (t.folder && !folders.includes(t.folder.name)) { + folders.push(t.folder.name); + items.push({ type: 'folder', name: t.folder.name }); + } + } + } else { + if (t.type === 'rich' && t.folder && t.folder.name === currentFolder) { + items.push(t); + } } - case 'rich': { - return { label: t.name, description: t.targetType, detail: t.filepath }; + }); + + const choices = items.map((t): vscode.QuickPickItem => { + switch (t.type) { + case 'named': { + return { + label: t.name, + description: localize('target.to.build.description', 'Target to build') + }; + } + case 'rich': { + return { label: t.name, description: t.targetType, detail: t.filepath }; + } + case 'folder': { + return { label: t.name, description: 'FOLDER' }; + } } + }); + + const sel = await vscode.window.showQuickPick(choices, { placeHolder: localize('select.active.target.tooltip', 'Select the default build target') }); + if (!sel) { + return null; + } else if (!folders.includes(sel.label) || currentFolder === sel.label) { + return sel.label; + } else { + currentFolder = sel.label; } - }); - const sel = await vscode.window.showQuickPick(choices, { placeHolder: localize('select.active.target.tooltip', 'Select the default build target') }); - return sel ? sel.label : null; + } + + return null; } } diff --git a/src/drivers/cmakeDriver.ts b/src/drivers/cmakeDriver.ts index 4306e8d9b..ce486e72e 100644 --- a/src/drivers/cmakeDriver.ts +++ b/src/drivers/cmakeDriver.ts @@ -35,6 +35,7 @@ import { CacheEntry } from '@cmt/cache'; import { CMakeBuildRunner } from '@cmt/cmakeBuildRunner'; import { DebuggerInformation } from '@cmt/debug/debuggerConfigureDriver'; import { onBuildSettingsChange, onTestSettingsChange, onPackageSettingsChange } from '@cmt/ui/util'; +import { CodeModelKind } from '@cmt/drivers/cmakeFileApi'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); @@ -104,13 +105,14 @@ export interface NamedTarget { } /** - * A target with a name, path, and type. + * A target with a name, path, type and folder. */ export interface RichTarget { type: 'rich'; name: string; filepath: string; targetType: string; + folder?: CodeModelKind.TargetObject; installPaths?: InstallPath[]; } diff --git a/src/drivers/cmakeFileApi.ts b/src/drivers/cmakeFileApi.ts index 81f9eec5d..4fcebdb6d 100644 --- a/src/drivers/cmakeFileApi.ts +++ b/src/drivers/cmakeFileApi.ts @@ -419,6 +419,7 @@ async function convertTargetObjectFileToExtensionTarget(buildDirectory: string, name: targetObject.name, filepath: executablePath, targetType: targetObject.type, + folder: targetObject.folder, type: 'rich' as 'rich', installPaths: installPaths } as RichTarget; diff --git a/src/drivers/cmakeServerDriver.ts b/src/drivers/cmakeServerDriver.ts index 8e048565b..57f46c8db 100644 --- a/src/drivers/cmakeServerDriver.ts +++ b/src/drivers/cmakeServerDriver.ts @@ -470,7 +470,7 @@ export class CMakeServerDriver extends CMakeDriver { * @t the RichTarget currently being examined. */ function targetReducer(set: RichTarget[], t: RichTarget): RichTarget[] { - if (!set.find(t2 => t.name === t2.name && t.filepath === t2.filepath && t.targetType === t2.targetType)) { + if (!set.find(t2 => t.name === t2.name && t.filepath === t2.filepath && t.targetType === t2.targetType && t.folder === t2.folder)) { set.push(t); } return set;