diff --git a/src/cmakeTaskProvider.ts b/src/cmakeTaskProvider.ts index 0ab191c0f..e67f6f1e2 100644 --- a/src/cmakeTaskProvider.ts +++ b/src/cmakeTaskProvider.ts @@ -8,7 +8,7 @@ import * as proc from './proc'; import * as nls from 'vscode-nls'; import { Environment, EnvironmentUtils } from './environmentVariables'; import * as logging from './logging'; -import { getActiveProject } from './extension'; +import { extensionManager, getActiveProject } from './extension'; import { CMakeProject, ConfigureTrigger } from './cmakeProject'; import * as preset from '@cmt/preset'; import { UseCMakePresets } from './config'; @@ -120,12 +120,15 @@ export class CMakeTaskProvider implements vscode.TaskProvider { const result: CMakeTask[] = []; const project: CMakeProject | undefined = getActiveProject(); const targets: string[] | undefined = await project?.getDefaultBuildTargets() || ["all"]; - result.push(await CMakeTaskProvider.provideTask(CommandType.config, project?.useCMakePresets)); - result.push(await CMakeTaskProvider.provideTask(CommandType.build, project?.useCMakePresets, targets)); - result.push(await CMakeTaskProvider.provideTask(CommandType.install, project?.useCMakePresets)); - result.push(await CMakeTaskProvider.provideTask(CommandType.test, project?.useCMakePresets)); - result.push(await CMakeTaskProvider.provideTask(CommandType.clean, project?.useCMakePresets)); - result.push(await CMakeTaskProvider.provideTask(CommandType.cleanRebuild, project?.useCMakePresets, targets)); + if (extensionManager?.workspaceHasAtLeastOneProject()) { + result.push(await CMakeTaskProvider.provideTask(CommandType.config, project?.useCMakePresets)); + result.push(await CMakeTaskProvider.provideTask(CommandType.build, project?.useCMakePresets, targets)); + result.push(await CMakeTaskProvider.provideTask(CommandType.install, project?.useCMakePresets)); + result.push(await CMakeTaskProvider.provideTask(CommandType.test, project?.useCMakePresets)); + result.push(await CMakeTaskProvider.provideTask(CommandType.clean, project?.useCMakePresets)); + result.push(await CMakeTaskProvider.provideTask(CommandType.cleanRebuild, project?.useCMakePresets, targets)); + } + return result; }