Skip to content

Commit d272d97

Browse files
committed
cleanups
1 parent fbb07e6 commit d272d97

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,7 @@ export class DefaultClient implements Client {
27372737
const status: IntelliSenseStatus = { status: Status.IntelliSenseCompiling };
27382738
testHook.updateStatus(status);
27392739
} else if (message.endsWith("IntelliSense done")) {
2740-
getOutputChannelLogger().appendLine(6, localize("update.intellisense.time", "Update IntelliSense time (sec): {0}", (Date.now() - timeStamp) / 1000));
2740+
getOutputChannelLogger().appendLineAtLevel(6, localize("update.intellisense.time", "Update IntelliSense time (sec): {0}", (Date.now() - timeStamp) / 1000));
27412741
this.model.isUpdatingIntelliSense.Value = false;
27422742
const status: IntelliSenseStatus = { status: Status.IntelliSenseReady };
27432743
testHook.updateStatus(status);
@@ -3164,7 +3164,7 @@ export class DefaultClient implements Client {
31643164
}
31653165

31663166
const out: Logger = getOutputChannelLogger();
3167-
out.appendLine(6, localize("configurations.received", "Custom configurations received:"));
3167+
out.appendLineAtLevel(6, localize("configurations.received", "Custom configurations received:"));
31683168
const sanitized: SourceFileConfigurationItemAdapter[] = [];
31693169
configs.forEach(item => {
31703170
if (this.isSourceFileConfigurationItem(item, providerVersion)) {
@@ -3176,8 +3176,8 @@ export class DefaultClient implements Client {
31763176
uri = item.uri.toString();
31773177
}
31783178
this.configurationLogging.set(uri, JSON.stringify(item.configuration, null, 4));
3179-
out.appendLine(6, ` uri: ${uri}`);
3180-
out.appendLine(6, ` config: ${JSON.stringify(item.configuration, null, 2)}`);
3179+
out.appendLineAtLevel(6, ` uri: ${uri}`);
3180+
out.appendLineAtLevel(6, ` config: ${JSON.stringify(item.configuration, null, 2)}`);
31813181
if (item.configuration.includePath.some(path => path.endsWith('**'))) {
31823182
console.warn("custom include paths should not use recursive includes ('**')");
31833183
}
@@ -3281,7 +3281,7 @@ export class DefaultClient implements Client {
32813281
return;
32823282
}
32833283

3284-
getOutputChannelLogger().appendLine(6, localize("browse.configuration.received", "Custom browse configuration received: {0}", JSON.stringify(sanitized, null, 2)));
3284+
getOutputChannelLogger().appendLineAtLevel(6, localize("browse.configuration.received", "Custom browse configuration received: {0}", JSON.stringify(sanitized, null, 2)));
32853285

32863286
// Separate compiler path and args before sending to language client
32873287
if (util.isString(sanitized.compilerPath)) {

Extension/src/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ export interface ProcessReturnType {
759759
export async function spawnChildProcess(program: string, args: string[] = [], continueOn?: string, skipLogging?: boolean, cancellationToken?: vscode.CancellationToken): Promise<ProcessReturnType> {
760760
// Do not use CppSettings to avoid circular require()
761761
if (skipLogging === undefined || !skipLogging) {
762-
getOutputChannelLogger().appendLine(5, `$ ${program} ${args.join(' ')}`);
762+
getOutputChannelLogger().appendLineAtLevel(5, `$ ${program} ${args.join(' ')}`);
763763
}
764764
const programOutput: ProcessOutput = await spawnChildProcessImpl(program, args, continueOn, skipLogging, cancellationToken);
765765
const exitCode: number | NodeJS.Signals | undefined = programOutput.exitCode;
@@ -811,7 +811,7 @@ async function spawnChildProcessImpl(program: string, args: string[], continueOn
811811
proc.stdout.on('data', data => {
812812
const str: string = data.toString();
813813
if (skipLogging === undefined || !skipLogging) {
814-
getOutputChannelLogger().append(1, str);
814+
getOutputChannelLogger().appendAtLevel(1, str);
815815
}
816816
stdout += str;
817817
if (continueOn) {

Extension/src/cppTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class CppTools implements CppToolsTestApi {
5959
if (providers.add(provider, this.version)) {
6060
const added: CustomConfigurationProvider1 | undefined = providers.get(provider);
6161
if (added) {
62-
getOutputChannelLogger().appendLine(5, localize("provider.registered", "Custom configuration provider '{0}' registered", added.name));
62+
getOutputChannelLogger().appendLineAtLevel(5, localize("provider.registered", "Custom configuration provider '{0}' registered", added.name));
6363
this.providers.push(added);
6464
LanguageServer.getClients().forEach(client => void client.onRegisterCustomConfigurationProvider(added));
6565
this.addNotifyReadyTimer(added);

Extension/src/instrumentation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const services = {
3030
launchSettings: undefined as Record<string, any> | undefined
3131
};
3232

33+
/** Adds instrumentation to all the members of an object when instrumentation is enabled */
3334
export function instrument<T extends Record<string, any>>(instance: T, options?: { ignore?: string[]; name?: string }): T {
3435
return services.instrument(instance, options);
3536
}
@@ -44,22 +45,25 @@ export function isInstrumentationEnabled(): boolean {
4445
return !!(global as any).instrumentation;
4546
}
4647

47-
// if the instrumentation code is not globally loaded yet, then load it now
48+
// if the instrumentation code is not globally loaded *yet*, then load it now.
4849
if (!isInstrumentationEnabled()) {
4950
// pull the launch settings from the environment if the variable has been set.
5051
if (services.launchSettings === undefined) {
5152
services.launchSettings = process.env.PERFECTO_LAUNCH_SETTINGS ? JSON.parse(process.env.PERFECTO_LAUNCH_SETTINGS) as Record<string, any> : { tests: [], collector: undefined };
5253
}
5354

54-
// this loads the bootstrap module (global-instrumentation-support) which adds some global functions
55+
// this loads the bootstrap module (global-instrumentation-support) which adds some global functions.
5556
if (services.launchSettings?.bootstrapModule) {
56-
// work around for webpack to load the bootstrap module
57+
// work around for webpack to load the bootstrap module.
5758
eval(`require`)(services.launchSettings.bootstrapModule);
5859
}
5960
}
6061

61-
// If the instrumentation object was loaded then we can set the services from the global object
62-
if ((global as any).instrumentation) {
62+
// If the instrumentation object was *actually* loaded then we can set the services from the global object.
63+
// Having this separate ensures that this module is wired up to the global object.
64+
// It's not included in the previous block because if something else loads the instrumentation code first
65+
// this is still needed so that *this* module is properly connected to the global object.
66+
if (isInstrumentationEnabled()) {
6367
// instrumentation services provided by the tool
6468
services.instrument = (global as any).instrumentation.instrument;
6569
services.message = (global as any).instrumentation.message;

Extension/src/logger.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,26 @@ export class Logger {
2828
this.writer = writer;
2929
}
3030

31-
public append(level: number, message: string): void;
32-
public append(message: string): void;
33-
public append(levelOrMessage: string | number, message?: string): void {
34-
message = message || levelOrMessage as string;
35-
const hasLevel = typeof levelOrMessage === 'number';
36-
37-
if (!hasLevel || getLoggingLevel() >= levelOrMessage) {
31+
public appendAtLevel(level: number, message: string): void {
32+
if (getLoggingLevel() >= level) {
3833
this.writer(message);
3934
if (Subscriber) {
4035
Subscriber(message);
4136
}
4237
}
43-
sendInstrumentation({ name: 'log', text: message, context: { channel: 'log', source: 'extension' }, level: hasLevel ? levelOrMessage : undefined });
38+
sendInstrumentation({ name: 'log', text: message, context: { channel: 'log', source: 'extension' }, level });
39+
}
40+
41+
public append(message: string): void {
42+
this.appendAtLevel(0, message);
43+
}
44+
45+
public appendLineAtLevel(level: number, message: string): void {
46+
this.appendAtLevel(level, message + os.EOL);
4447
}
4548

46-
public appendLine(level: number, message: string): void;
47-
public appendLine(message: string): void;
48-
public appendLine(levelOrMessage: string | number, message?: string): void {
49-
this.append(levelOrMessage as number, message + os.EOL);
49+
public appendLine(message: string): void {
50+
this.appendAtLevel(0, message + os.EOL);
5051
}
5152

5253
// We should not await on this function.

0 commit comments

Comments
 (0)