Skip to content

Commit

Permalink
implement microsoft#2521 by adding output channel argument
Browse files Browse the repository at this point in the history
  • Loading branch information
stepeos committed May 21, 2024
1 parent cb43dba commit f72a9cb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3466,12 +3466,14 @@
"enum": [
"focus",
"always",
"never"
"never",
"on 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 @@ -249,6 +249,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.allowCommentsInPresetsFile.description": "Allow the use of JSON extensions such as comments in CMakePresets.json. Please note that your CMakePresets.json file may be considered invalid by other IDEs or on the command line if you use non-standard JSON.",
Expand Down
7 changes: 7 additions & 0 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,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 @@ -1947,6 +1948,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 @@ -1977,6 +1981,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' | 'on error';

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

showChannel() {
showChannel(target_failed?: 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 === 'on error' && target_failed !== undefined) {
should_show = target_failed;
}
const should_focus = (reveal_log === 'focus');

if (should_show) {
Expand Down

0 comments on commit f72a9cb

Please sign in to comment.