Skip to content

CHANGE: @W-17970149@: The beginnings of refactorings to start removin global state ... #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025

Conversation

stephen-carter-at-sf
Copy link
Collaborator

… and make the code more testable

  • Note that obviously there is still a lot of work to do. Sometimes you need to explode input arguments and restructure before they can collapse. Things will improve and unit tests will soon be added and migrated, etc.
  • Other than a tiny bit of logging behavior, no behavior change occurred with this change.

I'll have a part 2 refactoring in my next PR. But I don't want to overwhelm you both.

…g global state and make the code more testable
Comment on lines 62 to -63
let diagnosticCollection: vscode.DiagnosticCollection = null;

let telemetryService: TelemetryServiceImpl = null;

let customCancellationToken: vscode.CancellationTokenSource | null = null;

let outputChannel: vscode.LogOutputChannel;

let sfgeCachePath: string = null;

let settingsManager: SettingsManager = null;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal over time will be to remove all this global state slowly but surely.

this.coreTelemetryService.sendExtensionActivationEvent(hrStart);
}

sendCommandEvent(commandName: string, properties: Record<string, string>): void {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tomorrow I'll create a PR separately to fix the tabs vs spaces inconsistencies.

@@ -56,7 +56,7 @@ export async function runApexGuruOnFile(selection: vscode.Uri, runInfo: RunInfo)
// TODO: For testability, the diagnostic manager should probably be passed in, not instantiated here.
new DiagnosticManagerImpl(diagnosticCollection).displayAsDiagnostics([selection.fsPath], convertibles);
// TODO: For testability, the telemetry service should probably be passed in, not instantiated here.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

src/extension.ts Outdated
@@ -117,9 +134,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
throw new Error(messages.targeting.error.noFileSelected);
}
return _runAndDisplayScanner(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [vscode.window.activeTextEditor.document.fileName], {
telemetryService: telemetryService,
telemetryService: await externalServiceProvider.getTelemetryService(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use the telemetryService you instantiate at line 99?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I was cleaning up my calls and missed this one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

jfeingold35
jfeingold35 previously approved these changes Mar 5, 2025
@stephen-carter-at-sf stephen-carter-at-sf merged commit 20fdbd4 into dev Mar 5, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants