Filter out duplicate targets from the target selector (#992)

* Filter out duplicate targets from the target selector

* remove duplicates for launch targets
This commit is contained in:
Bob Brown 2020-01-22 11:02:08 -08:00 коммит произвёл GitHub
Родитель fb93df3890
Коммит bfa6a904c7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -852,7 +852,7 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {
if (!drv.targets.length) {
return (await vscode.window.showInputBox({prompt: localize('enter.target.name', 'Enter a target name')})) || null;
} else {
const choices = drv.targets.map((t): vscode.QuickPickItem => {
const choices = drv.uniqueTargets.map((t): vscode.QuickPickItem => {
switch (t.type) {
case 'named': {
return {

Просмотреть файл

@ -215,10 +215,13 @@ export class CMakeServerClientDriver extends codemodel.CodeModelDriver {
}
get executableTargets(): ExecutableTarget[] {
return this.targets.filter(t => t.targetType === 'EXECUTABLE').map(t => ({
name: t.name,
path: t.filepath,
}));
return this.targets.filter(t => t.targetType === 'EXECUTABLE')
.reduce(targetReducer, [])
.map(t => ({name: t.name, path: t.filepath}));
}
get uniqueTargets(): api.Target[] {
return this.targets.reduce(targetReducer, []);
}
get generatorName(): string|null { return this._globalSettings ? this._globalSettings.generator : null; }
@ -322,3 +325,16 @@ export class CMakeServerClientDriver extends codemodel.CodeModelDriver {
return this.createDerived(new CMakeServerClientDriver(cmake, config, workspaceFolder, preconditionHandler), kit, preferredGenerators);
}
}
/**
* Helper function for Array.reduce
*
* @param set the accumulator
* @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)) {
set.push(t);
}
return set;
}

Просмотреть файл

@ -82,6 +82,11 @@ export abstract class CMakeDriver implements vscode.Disposable {
*/
abstract get executableTargets(): api.ExecutableTarget[];
/**
* List of unique targets known to CMake
*/
abstract get uniqueTargets(): api.Target[];
/**
* Do any necessary disposal for the driver. For the CMake Server driver,
* this entails shutting down the server process and closing the open pipes.

Просмотреть файл

@ -101,6 +101,7 @@ export class LegacyCMakeDriver extends CMakeDriver {
get targets() { return []; }
get executableTargets() { return []; }
get uniqueTargets() { return []; }
/**
* Watcher for the CMake cache file on disk.