Skip to content

Commit d146e0a

Browse files
Merge pull request #209 from forcedotcom/release-1.5.1
RELEASE: @W-18195076@: Releasing v1.5.1
2 parents 681df1c + 9475b78 commit d146e0a

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"color": "#ECECEC",
1414
"theme": "light"
1515
},
16-
"version": "1.5.0",
16+
"version": "1.5.1",
1717
"publisher": "salesforce",
1818
"license": "BSD-3-Clause",
1919
"engines": {

src/extension.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
6767
const onDidSaveTextDocument = (listener: (e: unknown) => unknown): void => {
6868
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(listener));
6969
}
70-
const onDidOpenTextDocument = (listener: (e: unknown) => unknown): void => {
71-
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(listener));
70+
const onDidChangeActiveTextEditor = (listener: (e: unknown) => unknown): void => {
71+
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(listener));
7272
}
7373

7474
// Prepare utilities
@@ -84,6 +84,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
8484
const diagnosticManager: DiagnosticManager = new DiagnosticManagerImpl(diagnosticCollection, telemetryService, logger);
8585
context.subscriptions.push(diagnosticManager);
8686
const codeAnalyzerRunner: CodeAnalyzerRunner = new CodeAnalyzerRunner(diagnosticManager, settingsManager, telemetryService, logger);
87+
const scanMonitor: ScanMonitor = new ScanMonitor();
88+
context.subscriptions.push(scanMonitor);
89+
8790

8891
// We need to do this first in case any other services need access to those provided by the core extension.
8992
// TODO: Soon we should get rid of this CoreExtensionService stuff in favor of putting things inside of the ExternalServiceProvider
@@ -108,16 +111,25 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
108111

109112
return codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
110113
});
111-
// ... also invoked by opening a file if the user has set things to do so.
112-
onDidOpenTextDocument(async (textDocument: vscode.TextDocument) => {
113-
if (settingsManager.getAnalyzeOnOpen() && _isValidFileForAnalysis(textDocument.uri)) {
114-
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [textDocument.fileName]);
114+
115+
onDidChangeActiveTextEditor(async (editor: vscode.TextEditor) => {
116+
const shouldScan: boolean = editor !== undefined && editor.document.uri.scheme === 'file' && settingsManager.getAnalyzeOnOpen() &&
117+
_isValidFileForAnalysis(editor.document.uri) && !scanMonitor.haveAlreadyScannedFile(editor.document.fileName);
118+
if (shouldScan) {
119+
scanMonitor.addFileToAlreadyScannedFiles(editor.document.fileName);
120+
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [editor.document.fileName]);
115121
}
116122
});
117-
// ... also invoked by saving a file if the user has set things to do so.
118-
onDidSaveTextDocument(async (textDocument: vscode.TextDocument) => {
119-
if (settingsManager.getAnalyzeOnSave() && _isValidFileForAnalysis(textDocument.uri)) {
120-
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [textDocument.fileName]);
123+
124+
onDidSaveTextDocument(async (document: vscode.TextDocument) => {
125+
if (document !== undefined && document.uri.scheme === 'file') {
126+
scanMonitor.removeFileFromAlreadyScannedFiles(document.fileName);
127+
128+
const shouldScan: boolean = settingsManager.getAnalyzeOnSave() && _isValidFileForAnalysis(document.uri);
129+
if (shouldScan) {
130+
scanMonitor.addFileToAlreadyScannedFiles(document.fileName);
131+
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
132+
}
121133
}
122134
});
123135

@@ -295,8 +307,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
295307
// Work Around: For reject & reject all, we really should be restoring the diagnostic that we removed
296308
// but CodeGenie doesn't let us keep the diagnostic information around at this point. So instead we must
297309
// rerun the scan instead to get the diagnostic restored.
298-
await document.save(); // TODO: saving the document should be built in to the runAndDisplay command in my opinion
299-
return codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
310+
await document.save(); // TODO: This whole space will be refactored soon so that we don't need to do a save and rerun.
311+
if (!settingsManager.getAnalyzeOnSave()) {
312+
return codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
313+
}
300314
});
301315

302316
// Invoked by the "Accept All" button on the CodeGenie Unified Diff tool
@@ -322,8 +336,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
322336
// Work Around: For reject & reject all, we really should be restoring the diagnostic that we removed
323337
// but CodeGenie doesn't let us keep the diagnostic information around at this point. So instead we must
324338
// rerun the scan instead to get the diagnostic restored.
325-
await document.save(); // TODO: saving the document should be built in to the runAndDisplay command in my opinion
326-
return codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
339+
await document.save(); // TODO: This whole space will be refactored soon so that we don't need to do a save and rerun.
340+
if (!settingsManager.getAnalyzeOnSave()) {
341+
return codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
342+
}
327343
});
328344

329345

@@ -364,7 +380,7 @@ export function deactivate(): void {
364380
// ....files. So We might not be able to get this perfect. Need to discuss this soon.
365381
export function _isValidFileForAnalysis(documentUri: vscode.Uri): boolean {
366382
const allowedFileTypes:string[] = ['.cls', '.js', '.apex', '.trigger', '.ts'];
367-
return allowedFileTypes.includes(path.extname(documentUri.path));
383+
return allowedFileTypes.includes(path.extname(documentUri.fsPath));
368384
}
369385

370386
// Inside our package.json you'll see things like:
@@ -376,4 +392,24 @@ async function establishVariableInContext(varUsedInPackageJson: string, getValue
376392
vscode.workspace.onDidChangeConfiguration(async () => {
377393
await vscode.commands.executeCommand('setContext', varUsedInPackageJson, await getValueFcn());
378394
});
395+
}
396+
397+
class ScanMonitor implements vscode.Disposable {
398+
private alreadyScannedFiles: Set<string> = new Set();
399+
400+
haveAlreadyScannedFile(file: string): boolean {
401+
return this.alreadyScannedFiles.has(file);
402+
}
403+
404+
removeFileFromAlreadyScannedFiles(file: string): void {
405+
this.alreadyScannedFiles.delete(file);
406+
}
407+
408+
addFileToAlreadyScannedFiles(file: string) {
409+
this.alreadyScannedFiles.add(file);
410+
}
411+
412+
public dispose(): void {
413+
this.alreadyScannedFiles.clear();
414+
}
379415
}

src/test/legacy/scanner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ suite('ScanRunner', () => {
344344

345345
test('Adds process Id to the cache', () => {
346346
// ===== SETUP =====
347-
const args:string[] = [];
347+
const args:string[] = ['scanner', 'run', 'dfa', '--target', 'doesNotMatter', '--json'];
348348
const scanner = new ScanRunner();
349349
void context.workspaceState.update(Constants.WORKSPACE_DFA_PROCESS, undefined);
350350

0 commit comments

Comments
 (0)