Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOLDER grouping in default build target dropdown #3953

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 61 additions & 12 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -123,6 +124,15 @@ export interface ConfigureCancelInformation {
canceled: boolean;
}

/**
* 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!
*
Expand Down Expand Up @@ -2258,21 +2268,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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/drivers/cmakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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();

Expand Down Expand Up @@ -105,13 +106,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[];
}

Expand Down
1 change: 1 addition & 0 deletions src/drivers/cmakeFileApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/cmakeServerDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down