Skip to content

Commit 1d2bd10

Browse files
authored
Merge pull request #12223 from microsoft/main
Fix SettingsTracking treating numerical loggingLevel as invalid. (#12
2 parents dac96fe + 21ef2e3 commit 1d2bd10

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

Extension/src/LanguageServer/client.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1625,11 +1625,9 @@ export class DefaultClient implements Client {
16251625
updateLanguageConfigurations();
16261626
}
16271627
if (changedSettings.loggingLevel) {
1628-
const oldLoggingLevelLogged: boolean = !!this.loggingLevel && this.loggingLevel !== 0 && this.loggingLevel !== 1;
1629-
const newLoggingLevel: string | undefined = changedSettings.loggingLevel;
1630-
this.loggingLevel = util.getNumericLoggingLevel(newLoggingLevel);
1631-
const newLoggingLevelLogged: boolean = !!newLoggingLevel && newLoggingLevel !== "None" && newLoggingLevel !== "Error";
1632-
if (oldLoggingLevelLogged || newLoggingLevelLogged) {
1628+
const oldLoggingLevelLogged: boolean = this.loggingLevel > 1;
1629+
this.loggingLevel = util.getNumericLoggingLevel(changedSettings.loggingLevel);
1630+
if (oldLoggingLevelLogged || this.loggingLevel > 1) {
16331631
const out: Logger = getOutputChannelLogger();
16341632
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));
16351633
}
@@ -2598,7 +2596,7 @@ export class DefaultClient implements Client {
25982596
testHook.updateStatus(status);
25992597
} else if (message.endsWith("IntelliSense done")) {
26002598
const settings: CppSettings = new CppSettings();
2601-
if (settings.loggingLevel === "Debug") {
2599+
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
26022600
const out: Logger = getOutputChannelLogger();
26032601
const duration: number = Date.now() - timeStamp;
26042602
out.appendLine(localize("update.intellisense.time", "Update IntelliSense time (sec): {0}", duration / 1000));
@@ -3030,7 +3028,7 @@ export class DefaultClient implements Client {
30303028

30313029
const settings: CppSettings = new CppSettings();
30323030
const out: Logger = getOutputChannelLogger();
3033-
if (settings.loggingLevel === "Debug") {
3031+
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
30343032
out.appendLine(localize("configurations.received", "Custom configurations received:"));
30353033
}
30363034
const sanitized: SourceFileConfigurationItemAdapter[] = [];
@@ -3044,7 +3042,7 @@ export class DefaultClient implements Client {
30443042
uri = item.uri.toString();
30453043
}
30463044
this.configurationLogging.set(uri, JSON.stringify(item.configuration, null, 4));
3047-
if (settings.loggingLevel === "Debug") {
3045+
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
30483046
out.appendLine(` uri: ${uri}`);
30493047
out.appendLine(` config: ${JSON.stringify(item.configuration, null, 2)}`);
30503048
}
@@ -3148,7 +3146,7 @@ export class DefaultClient implements Client {
31483146
}
31493147

31503148
const settings: CppSettings = new CppSettings();
3151-
if (settings.loggingLevel === "Debug") {
3149+
if (util.getNumericLoggingLevel(settings.loggingLevel) >= 6) {
31523150
const out: Logger = getOutputChannelLogger();
31533151
out.appendLine(localize("browse.configuration.received", "Custom browse configuration received: {0}", JSON.stringify(sanitized, null, 2)));
31543152
}

Extension/src/LanguageServer/settingsTracker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ export class SettingsTracker {
103103
return val;
104104
}
105105
const curEnum: any[] = curSetting["enum"];
106-
if (curEnum && curEnum.indexOf(val) === -1) {
106+
if (curEnum && curEnum.indexOf(val) === -1
107+
&& (key !== "loggingLevel" || util.getNumericLoggingLevel(val) === -1)) {
107108
return "<invalid>";
108109
}
109110
return val;

Extension/src/SSH/sshCommandRunner.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as vscode from 'vscode';
99
import * as nls from 'vscode-nls';
1010
import { CppSettings } from '../LanguageServer/settings';
1111
import { ManualPromise } from '../Utility/Async/manualPromise';
12-
import { ISshHostInfo, ProcessReturnType, splitLines, stripEscapeSequences } from '../common';
12+
import { ISshHostInfo, ProcessReturnType, getNumericLoggingLevel, splitLines, stripEscapeSequences } from '../common';
1313
import { isWindows } from '../constants';
1414
import { getSshChannel } from '../logger';
1515
import {
@@ -254,7 +254,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
254254
const disposables: vscode.Disposable[] = [];
255255
const { systemInteractor, command, interactors, nickname, token } = args;
256256
let logIsPaused: boolean = false;
257-
const loggingLevel: string | undefined = new CppSettings().loggingLevel;
257+
const loggingLevel: number = getNumericLoggingLevel(new CppSettings().loggingLevel);
258258
const result = new ManualPromise<ProcessReturnType>();
259259

260260
let stdout: string = '';
@@ -344,7 +344,7 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
344344
};
345345

346346
const handleTerminalOutput = async (dataWrite: vscode.TerminalDataWriteEvent): Promise<void> => {
347-
if (loggingLevel !== 'None') {
347+
if (loggingLevel > 0) {
348348
handleOutputLogging(dataWrite.data);
349349
}
350350

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

462462
terminal.sendText(sendText);
463-
if (loggingLevel === 'Debug' || loggingLevel === 'Information') {
463+
if (loggingLevel >= 5) {
464464
getSshChannel().appendLine(localize('ssh.wrote.data.to.terminal', '"{0}" wrote data to terminal: "{1}".', nickname, args.sendText));
465465
}
466466
}

Extension/src/common.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,7 @@ export async function spawnChildProcess(program: string, args: string[] = [], co
745745
// Do not use CppSettings to avoid circular require()
746746
if (skipLogging === undefined || !skipLogging) {
747747
const settings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("C_Cpp", null);
748-
const loggingLevel: string | undefined = settings.get<string>("loggingLevel");
749-
if (loggingLevel === "Information" || loggingLevel === "Debug") {
748+
if (getNumericLoggingLevel(settings.get<string>("loggingLevel")) >= 5) {
750749
getOutputChannelLogger().appendLine(`$ ${program} ${args.join(' ')}`);
751750
}
752751
}
@@ -777,7 +776,7 @@ async function spawnChildProcessImpl(program: string, args: string[], continueOn
777776

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

782781
let proc: child_process.ChildProcess;
783782
if (await isExecutable(program)) {
@@ -803,7 +802,7 @@ async function spawnChildProcessImpl(program: string, args: string[], continueOn
803802
if (proc.stdout) {
804803
proc.stdout.on('data', data => {
805804
const str: string = data.toString();
806-
if (loggingLevel !== "None") {
805+
if (loggingLevel > 0) {
807806
getOutputChannelLogger().append(str);
808807
}
809808
stdout += str;
@@ -1579,8 +1578,10 @@ export function getNumericLoggingLevel(loggingLevel: string | undefined): number
15791578
return 5;
15801579
case "debug":
15811580
return 6;
1582-
default:
1581+
case "none":
15831582
return 0;
1583+
default:
1584+
return -1;
15841585
}
15851586
}
15861587

Extension/src/cppTools.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as nls from 'vscode-nls';
1010
import { CustomConfigurationProvider1, CustomConfigurationProviderCollection, getCustomConfigProviders } from './LanguageServer/customProviders';
1111
import * as LanguageServer from './LanguageServer/extension';
1212
import { CppSettings } from './LanguageServer/settings';
13+
import { getNumericLoggingLevel } from './common';
1314
import { getOutputChannel } from './logger';
1415
import * as test from './testHook';
1516

@@ -61,7 +62,7 @@ export class CppTools implements CppToolsTestApi {
6162
const added: CustomConfigurationProvider1 | undefined = providers.get(provider);
6263
if (added) {
6364
const settings: CppSettings = new CppSettings();
64-
if (settings.loggingLevel === "Information" || settings.loggingLevel === "Debug") {
65+
if (getNumericLoggingLevel(settings.loggingLevel) >= 5) {
6566
getOutputChannel().appendLine(localize("provider.registered", "Custom configuration provider '{0}' registered", added.name));
6667
}
6768
this.providers.push(added);

Extension/src/logger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import * as os from 'os';
88
import * as vscode from 'vscode';
99
import * as nls from 'vscode-nls';
10+
import { getNumericLoggingLevel } from './common';
1011
import { CppSourceStr } from './LanguageServer/extension';
1112
import { getLocalizedString, LocalizeStringParams } from './LanguageServer/localization';
1213

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

0 commit comments

Comments
 (0)