Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"color": "#ECECEC",
"theme": "light"
},
"version": "1.5.0",
"version": "1.5.1",
"publisher": "salesforce",
"license": "BSD-3-Clause",
"engines": {
Expand Down
66 changes: 51 additions & 15 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
const onDidSaveTextDocument = (listener: (e: unknown) => unknown): void => {
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(listener));
}
const onDidOpenTextDocument = (listener: (e: unknown) => unknown): void => {
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(listener));
const onDidChangeActiveTextEditor = (listener: (e: unknown) => unknown): void => {
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(listener));
}

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


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

return codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
});
// ... also invoked by opening a file if the user has set things to do so.
onDidOpenTextDocument(async (textDocument: vscode.TextDocument) => {
if (settingsManager.getAnalyzeOnOpen() && _isValidFileForAnalysis(textDocument.uri)) {
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [textDocument.fileName]);

onDidChangeActiveTextEditor(async (editor: vscode.TextEditor) => {
const shouldScan: boolean = editor !== undefined && editor.document.uri.scheme === 'file' && settingsManager.getAnalyzeOnOpen() &&
_isValidFileForAnalysis(editor.document.uri) && !scanMonitor.haveAlreadyScannedFile(editor.document.fileName);
if (shouldScan) {
scanMonitor.addFileToAlreadyScannedFiles(editor.document.fileName);
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [editor.document.fileName]);
}
});
// ... also invoked by saving a file if the user has set things to do so.
onDidSaveTextDocument(async (textDocument: vscode.TextDocument) => {
if (settingsManager.getAnalyzeOnSave() && _isValidFileForAnalysis(textDocument.uri)) {
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [textDocument.fileName]);

onDidSaveTextDocument(async (document: vscode.TextDocument) => {
if (document !== undefined && document.uri.scheme === 'file') {
scanMonitor.removeFileFromAlreadyScannedFiles(document.fileName);

const shouldScan: boolean = settingsManager.getAnalyzeOnSave() && _isValidFileForAnalysis(document.uri);
if (shouldScan) {
scanMonitor.addFileToAlreadyScannedFiles(document.fileName);
await codeAnalyzerRunner.runAndDisplay(Constants.COMMAND_RUN_ON_ACTIVE_FILE, [document.fileName]);
}
}
});

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

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


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

// Inside our package.json you'll see things like:
Expand All @@ -376,4 +392,24 @@ async function establishVariableInContext(varUsedInPackageJson: string, getValue
vscode.workspace.onDidChangeConfiguration(async () => {
await vscode.commands.executeCommand('setContext', varUsedInPackageJson, await getValueFcn());
});
}

class ScanMonitor implements vscode.Disposable {
private alreadyScannedFiles: Set<string> = new Set();

haveAlreadyScannedFile(file: string): boolean {
return this.alreadyScannedFiles.has(file);
}

removeFileFromAlreadyScannedFiles(file: string): void {
this.alreadyScannedFiles.delete(file);
}

addFileToAlreadyScannedFiles(file: string) {
this.alreadyScannedFiles.add(file);
}

public dispose(): void {
this.alreadyScannedFiles.clear();
}
}
2 changes: 1 addition & 1 deletion src/test/legacy/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ suite('ScanRunner', () => {

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

Expand Down