Skip to content

Commit

Permalink
bug fix (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: Nagarjun Sanji <[email protected]>
  • Loading branch information
nagarjunsanji and Nagarjun Sanji authored Oct 10, 2024
1 parent d59b183 commit e6a831c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export async function activate(context: vscode.ExtensionContext) {
},
);
// Add file watcher for all manifest files
await watchers.registerWatcher(context);
providers.registerDependencyPolicyProvider(context); // after adding watcher and scanning we should add the policy provider
watchers.registerWatcher(context);
}

// This method is called when your extension is deactivated
Expand Down
41 changes: 1 addition & 40 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,6 @@ class Providers {
Logger.logInfo("Command registration has been completed");
}
}

public async registerDependencyPolicyProvider(context: vscode.ExtensionContext) {
try {
Logger.logInfo("Started registering policy provider");
const selectedRepoName = await gitHelper.getUpstream();

if (selectedRepoName !== MessageStatus.UNKNOWN) {
const diagnosticCollection = vscode.languages.createDiagnosticCollection("dependencyPolicyChecker");
context.subscriptions.push(diagnosticCollection);

const provider = new DependencyPolicyProvider(diagnosticCollection);
//added to activate the policy violation provider when the manifest file is already open
if (vscode.window.activeTextEditor?.document) {
provider.checkPolicyViolation(vscode.window.activeTextEditor?.document);
}

context.subscriptions.push(
vscode.languages.registerCodeActionsProvider({ scheme: "file" }, provider, {
providedCodeActionKinds: [vscode.CodeActionKind.QuickFix],
}),
);

// Trigger the check when a file is opened or saved
context.subscriptions.push(
vscode.workspace.onDidOpenTextDocument((doc) => provider.checkPolicyViolation(doc)),
vscode.workspace.onDidSaveTextDocument((doc) => provider.checkPolicyViolation(doc)),
vscode.window.onDidChangeActiveTextEditor((editor) => {
if (editor) {
provider.checkPolicyViolation(editor.document);
}
}),
);
}
} catch (error) {
errorHandler.handleError(error);
} finally {
Logger.logInfo("Command registration has been completed");
}
}
}
const providers = new Providers();
export { DebrickedCommandsTreeDataProvider, ManifestDependencyHoverProvider, providers };
export { DebrickedCommandsTreeDataProvider, ManifestDependencyHoverProvider, providers, DependencyPolicyProvider };
2 changes: 1 addition & 1 deletion src/watcher/reportWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ReportWatcher {
public async start(context: vscode.ExtensionContext): Promise<void> {
const reportFilePath = DebrickedCommands.SCAN.flags?.[2]?.report;
if (!reportFilePath) {
console.log("No report file path found");
Logger.logInfo("No report file path found");
return;
}

Expand Down
13 changes: 13 additions & 0 deletions src/watcher/workspaceWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SupportedFilesToScan } from "../constants";
import { scanService } from "services";
import { errorHandler, globalStore, Logger, statusBarMessageHelper } from "../helpers";
import * as path from "path";
import { DependencyPolicyProvider } from "../providers";

export class WorkSpaceWatcher {
private context: vscode.ExtensionContext;
Expand Down Expand Up @@ -56,13 +57,25 @@ export class WorkSpaceWatcher {

try {
await scanService.scan();
this.updatePackageJsonContent(this.context);
} catch (error) {
errorHandler.handleError(error);
} finally {
globalStore.setScanningProgress(false);
}
}

private async updatePackageJsonContent(context: vscode.ExtensionContext): Promise<void> {
const diagnosticCollection = vscode.languages.createDiagnosticCollection("dependencyPolicyChecker");
context.subscriptions.push(diagnosticCollection);

const provider = new DependencyPolicyProvider(diagnosticCollection);
//added to activate the policy violation provider when the manifest file is already open
if (vscode.window.activeTextEditor?.document) {
await provider.checkPolicyViolation(vscode.window.activeTextEditor?.document);
}
}

public dispose(): void {
if (this.packageJsonWatcher) {
this.packageJsonWatcher.dispose();
Expand Down

0 comments on commit e6a831c

Please sign in to comment.