Skip to content

Commit

Permalink
implement #2521 by adding output channel argument (#3785)
Browse files Browse the repository at this point in the history
* implement  #2521 by adding output channel argument

* fix failed configuration not showing output channel on "on error"

* implement review, add changelog

* fix changelog

---------

Co-authored-by: Garrett Campbell <[email protected]>
Co-authored-by: Garrett Campbell <[email protected]>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent eb4c00d commit 890fb56
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Improvements:

- Add `Unspecified` option for selecting a kit variant to allow CMake itself to select the build type. [#3821](https://github.com/microsoft/vscode-cmake-tools/issues/3821)
- Skip loading variants when using CMakePresets. [#3300](https://github.com/microsoft/vscode-cmake-tools/issues/3300)
- Add setting to only show the cmake log on target failure. [#3785](https://github.com/microsoft/vscode-cmake-tools/pull/3785) [@stepeos](https://github.com/stepeos)

Bug Fixes:

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3484,12 +3484,14 @@
"enum": [
"focus",
"always",
"never"
"never",
"error"
],
"enumDescriptions": [
"%cmake-tools.configuration.cmake.revealLog.focus.description%",
"%cmake-tools.configuration.cmake.revealLog.always.description%",
"%cmake-tools.configuration.cmake.revealLog.never.description%"
"%cmake-tools.configuration.cmake.revealLog.never.description%",
"%cmake-tools.configuration.cmake.revealLog.onError.description%"
],
"description": "%cmake-tools.configuration.cmake.revealLog.description%"
},
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"cmake-tools.configuration.cmake.revealLog.focus.description": "The log appears and the output channel takes the cursor focus.",
"cmake-tools.configuration.cmake.revealLog.always.description": "The log appears but the output channel doesn't take the cursor focus.",
"cmake-tools.configuration.cmake.revealLog.never.description": "The log neither appears nor takes the focus.",
"cmake-tools.configuration.cmake.revealLog.onError.description": "The log appears only when the build or the configuration fails.",
"cmake-tools.configuration.cmake.exportCompileCommandsFile.description": "Enables exporting compile_commands.json. This only is used in Kits scenarios. In Presets scenarios, please set this by using CMakePresets.json",
"cmake-tools.configuration.cmake.useCMakePresets.description": "Use CMakePresets.json to configure drive CMake configure, build, and test. When using CMakePresets.json, kits, variants, and some settings in settings.json will be ignored.",
"cmake-tools.configuration.cmake.useVsDeveloperEnvironment.description": "When using CMake Presets on Windows, use the Visual Studio environment as the parent environment. Selecting auto will only apply the Visual Studio environment when we detect a supported compiler (cl, clang, clang-cl, clang-cpp, clang++), or the Ninja generator is being used.",
Expand Down
16 changes: 15 additions & 1 deletion src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ export class CMakeProject {
const result: ConfigureResult = await drv.configure(trigger, []);
if (result.result === 0) {
await this.refreshCompileDatabase(drv.expansionOptions);
} else {
log.showChannel(true);
}
await this.cTestController.refreshTests(drv);
this.onReconfiguredEmitter.fire();
Expand All @@ -1555,7 +1557,7 @@ export class CMakeProject {
return { result: -1, resultType: ConfigureResultType.NoCache };
}

return vscode.window.withProgress(
const res = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Window,
title: localize('configuring.project', 'Configuring project'),
Expand Down Expand Up @@ -1633,6 +1635,7 @@ export class CMakeProject {
await enableFullFeatureSet(true);
await this.refreshCompileDatabase(drv.expansionOptions);
} else if (result.result !== 0 && (await this.getCMakeExecutable()).isDebuggerSupported && cmakeConfiguration.get(showDebuggerConfigurationString) && !forciblyCanceled && result.resultType === ConfigureResultType.NormalOperation) {
log.showChannel(true);
const yesButtonTitle: string = localize(
"yes.configureWithDebugger.button",
"Debug"
Expand Down Expand Up @@ -1682,6 +1685,11 @@ export class CMakeProject {
}
}
);
// check if the an error occured during the configuration
if (res.result !== 0) {
log.showChannel(true);
}
return res;
}

/**
Expand Down Expand Up @@ -1979,6 +1987,9 @@ export class CMakeProject {
buildLogger.info(localize('starting.build', 'Starting build'));
await setContextAndStore(isBuildingKey, true);
rc = await drv!.build(newTargets, taskConsumer, isBuildCommand);
if (rc !== 0) {
log.showChannel(true); // in case build has failed
}
await setContextAndStore(isBuildingKey, false);
if (rc === null) {
buildLogger.info(localize('build.was.terminated', 'Build was terminated'));
Expand Down Expand Up @@ -2009,6 +2020,9 @@ export class CMakeProject {
await setContextAndStore(isBuildingKey, true);
const rc = await drv!.build(newTargets, consumer, isBuildCommand);
await setContextAndStore(isBuildingKey, false);
if (rc !== 0) {
log.showChannel(true); // in case build has failed
}
if (rc === null) {
buildLogger.info(localize('build.was.terminated', 'Build was terminated'));
} else {
Expand Down
13 changes: 10 additions & 3 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum LogLevel {
Fatal,
}

type RevealLogKey = 'always' | 'never' | 'focus';
type RevealLogKey = 'always' | 'never' | 'focus' | 'error';

/**
* Get the name of a logging level
Expand Down Expand Up @@ -252,10 +252,17 @@ export class Logger {
SingletonLogger.instance().clearOutputChannel();
}

showChannel() {
showChannel(error_to_show?: boolean) {
const reveal_log = vscode.workspace.getConfiguration('cmake').get<RevealLogKey>('revealLog', 'always');

const should_show = (reveal_log !== 'never');
let should_show: boolean = false;
if (reveal_log === 'always') {
should_show = true;
}
// won't show if no target information
if (reveal_log === 'error' && error_to_show !== undefined) {
should_show = error_to_show;
}
const should_focus = (reveal_log === 'focus');

if (should_show) {
Expand Down

0 comments on commit 890fb56

Please sign in to comment.