Skip to content

Commit

Permalink
Merge pull request #12223 from microsoft/main
Browse files Browse the repository at this point in the history
Fix SettingsTracking treating numerical loggingLevel as invalid. (#12
  • Loading branch information
sean-mcmanus committed Apr 18, 2024
2 parents dac96fe + 21ef2e3 commit 1d2bd10
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
16 changes: 7 additions & 9 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1625,11 +1625,9 @@ export class DefaultClient implements Client {
updateLanguageConfigurations();
}
if (changedSettings.loggingLevel) {
const oldLoggingLevelLogged: boolean = !!this.loggingLevel && this.loggingLevel !== 0 && this.loggingLevel !== 1;
const newLoggingLevel: string | undefined = changedSettings.loggingLevel;
this.loggingLevel = util.getNumericLoggingLevel(newLoggingLevel);
const newLoggingLevelLogged: boolean = !!newLoggingLevel && newLoggingLevel !== "None" && newLoggingLevel !== "Error";
if (oldLoggingLevelLogged || newLoggingLevelLogged) {
const oldLoggingLevelLogged: boolean = this.loggingLevel > 1;
this.loggingLevel = util.getNumericLoggingLevel(changedSettings.loggingLevel);
if (oldLoggingLevelLogged || this.loggingLevel > 1) {
const out: Logger = getOutputChannelLogger();
out.appendLine(localize({ key: "loggingLevel.changed", comment: ["{0} is the setting name 'loggingLevel', {1} is a string value such as 'Debug'"] }, "{0} has changed to: {1}", "loggingLevel", changedSettings.loggingLevel));
}
Expand Down Expand Up @@ -2598,7 +2596,7 @@ export class DefaultClient implements Client {
testHook.updateStatus(status);
} else if (message.endsWith("IntelliSense done")) {
const settings: CppSettings = new CppSettings();
if (settings.loggingLevel === "Debug") {
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
const out: Logger = getOutputChannelLogger();
const duration: number = Date.now() - timeStamp;
out.appendLine(localize("update.intellisense.time", "Update IntelliSense time (sec): {0}", duration / 1000));
Expand Down Expand Up @@ -3030,7 +3028,7 @@ export class DefaultClient implements Client {

const settings: CppSettings = new CppSettings();
const out: Logger = getOutputChannelLogger();
if (settings.loggingLevel === "Debug") {
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
out.appendLine(localize("configurations.received", "Custom configurations received:"));
}
const sanitized: SourceFileConfigurationItemAdapter[] = [];
Expand All @@ -3044,7 +3042,7 @@ export class DefaultClient implements Client {
uri = item.uri.toString();
}
this.configurationLogging.set(uri, JSON.stringify(item.configuration, null, 4));
if (settings.loggingLevel === "Debug") {
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
out.appendLine(` uri: ${uri}`);
out.appendLine(` config: ${JSON.stringify(item.configuration, null, 2)}`);
}
Expand Down Expand Up @@ -3148,7 +3146,7 @@ export class DefaultClient implements Client {
}

const settings: CppSettings = new CppSettings();
if (settings.loggingLevel === "Debug") {
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
const out: Logger = getOutputChannelLogger();
out.appendLine(localize("browse.configuration.received", "Custom browse configuration received: {0}", JSON.stringify(sanitized, null, 2)));
}
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/LanguageServer/settingsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class SettingsTracker {
return val;
}
const curEnum: any[] = curSetting["enum"];
if (curEnum && curEnum.indexOf(val) === -1) {
if (curEnum && curEnum.indexOf(val) === -1
&& (key !== "loggingLevel" || util.getNumericLoggingLevel(val) === -1)) {
return "<invalid>";
}
return val;
Expand Down
10 changes: 5 additions & 5 deletions Extension/src/SSH/sshCommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { CppSettings } from '../LanguageServer/settings';
import { ManualPromise } from '../Utility/Async/manualPromise';
import { ISshHostInfo, ProcessReturnType, splitLines, stripEscapeSequences } from '../common';
import { ISshHostInfo, ProcessReturnType, getNumericLoggingLevel, splitLines, stripEscapeSequences } from '../common';
import { isWindows } from '../constants';
import { getSshChannel } from '../logger';
import {
Expand Down Expand Up @@ -254,7 +254,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
const disposables: vscode.Disposable[] = [];
const { systemInteractor, command, interactors, nickname, token } = args;
let logIsPaused: boolean = false;
const loggingLevel: string | undefined = new CppSettings().loggingLevel;
const loggingLevel: number = getNumericLoggingLevel(new CppSettings().loggingLevel);
const result = new ManualPromise<ProcessReturnType>();

let stdout: string = '';
Expand Down Expand Up @@ -344,7 +344,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
};

const handleTerminalOutput = async (dataWrite: vscode.TerminalDataWriteEvent): Promise<void> => {
if (loggingLevel !== 'None') {
if (loggingLevel > 0) {
handleOutputLogging(dataWrite.data);
}

Expand Down Expand Up @@ -396,7 +396,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
const logOutput: string = interaction.isPassword
? interaction.response.replace(/./g, '*')
: interaction.response;
if (loggingLevel === 'Debug' || loggingLevel === 'Information') {
if (loggingLevel >= 5) {
getSshChannel().appendLine(localize('ssh.wrote.data.to.terminal', '"{0}" wrote data to terminal: "{1}".', nickname, logOutput));
}
}
Expand Down Expand Up @@ -460,7 +460,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
const sendText: string = terminalIsWindows ? `(${args.sendText})\nexit /b %ErrorLevel%` : `${args.sendText}\nexit $?`;

terminal.sendText(sendText);
if (loggingLevel === 'Debug' || loggingLevel === 'Information') {
if (loggingLevel >= 5) {
getSshChannel().appendLine(localize('ssh.wrote.data.to.terminal', '"{0}" wrote data to terminal: "{1}".', nickname, args.sendText));
}
}
Expand Down
11 changes: 6 additions & 5 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,7 @@ export async function spawnChildProcess(program: string, args: string[] = [], co
// Do not use CppSettings to avoid circular require()
if (skipLogging === undefined || !skipLogging) {
const settings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("C_Cpp", null);
const loggingLevel: string | undefined = settings.get<string>("loggingLevel");
if (loggingLevel === "Information" || loggingLevel === "Debug") {
if (getNumericLoggingLevel(settings.get<string>("loggingLevel")) >= 5) {
getOutputChannelLogger().appendLine(`$ ${program} ${args.join(' ')}`);
}
}
Expand Down Expand Up @@ -777,7 +776,7 @@ async function spawnChildProcessImpl(program: string, args: string[], continueOn

// Do not use CppSettings to avoid circular require()
const settings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("C_Cpp", null);
const loggingLevel: string | undefined = (skipLogging === undefined || !skipLogging) ? settings.get<string>("loggingLevel") : "None";
const loggingLevel: number = (skipLogging === undefined || !skipLogging) ? getNumericLoggingLevel(settings.get<string>("loggingLevel")) : 0;

let proc: child_process.ChildProcess;
if (await isExecutable(program)) {
Expand All @@ -803,7 +802,7 @@ async function spawnChildProcessImpl(program: string, args: string[], continueOn
if (proc.stdout) {
proc.stdout.on('data', data => {
const str: string = data.toString();
if (loggingLevel !== "None") {
if (loggingLevel > 0) {
getOutputChannelLogger().append(str);
}
stdout += str;
Expand Down Expand Up @@ -1579,8 +1578,10 @@ export function getNumericLoggingLevel(loggingLevel: string | undefined): number
return 5;
case "debug":
return 6;
default:
case "none":
return 0;
default:
return -1;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Extension/src/cppTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as nls from 'vscode-nls';
import { CustomConfigurationProvider1, CustomConfigurationProviderCollection, getCustomConfigProviders } from './LanguageServer/customProviders';
import * as LanguageServer from './LanguageServer/extension';
import { CppSettings } from './LanguageServer/settings';
import { getNumericLoggingLevel } from './common';
import { getOutputChannel } from './logger';
import * as test from './testHook';

Expand Down Expand Up @@ -61,7 +62,7 @@ export class CppTools implements CppToolsTestApi {
const added: CustomConfigurationProvider1 | undefined = providers.get(provider);
if (added) {
const settings: CppSettings = new CppSettings();
if (settings.loggingLevel === "Information" || settings.loggingLevel === "Debug") {
if (getNumericLoggingLevel(settings.loggingLevel) >= 5) {
getOutputChannel().appendLine(localize("provider.registered", "Custom configuration provider '{0}' registered", added.name));
}
this.providers.push(added);
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as os from 'os';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { getNumericLoggingLevel } from './common';
import { CppSourceStr } from './LanguageServer/extension';
import { getLocalizedString, LocalizeStringParams } from './LanguageServer/localization';

Expand Down Expand Up @@ -83,7 +84,7 @@ export function getOutputChannel(): vscode.OutputChannel {
// Do not use CppSettings to avoid circular require()
const settings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("C_Cpp", null);
const loggingLevel: string | undefined = settings.get<string>("loggingLevel");
if (!!loggingLevel && loggingLevel !== "None" && loggingLevel !== "Error") {
if (getNumericLoggingLevel(loggingLevel) > 1) {
outputChannel.appendLine(`loggingLevel: ${loggingLevel}`);
}
}
Expand Down

0 comments on commit 1d2bd10

Please sign in to comment.