Skip to content

Commit

Permalink
Hover provider bug fixes (#66)
Browse files Browse the repository at this point in the history
* fixed hovering effect should activate in dependency only and other minor fixes

* fixed policy violation not triggering when manifest file is already opened
  • Loading branch information
rajpreet-s authored Sep 26, 2024
1 parent 66582fb commit 4daae48
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export async function activate(context: vscode.ExtensionContext) {

await debrickedCommand.commands(context);
await providers.registerHover(context);
await providers.registerDependencyPolicyProvider(context);

const debCommandsProvider = new DebrickedCommandsTreeDataProvider();
vscode.window.registerTreeDataProvider(Organization.debrickedCommand, debCommandsProvider);
Expand Down Expand Up @@ -64,6 +63,7 @@ export async function activate(context: vscode.ExtensionContext) {

// Add file watcher for all files found from 'debricked files find'
await watchers.registerWatcher(context);
await providers.registerDependencyPolicyProvider(context); // after adding watcher and scanning we should add the policy provider

progress.report({ message: "Debricked extension is ready to use", increment: 100 - progressCount });
await new Promise((resolve) => setTimeout(resolve, 1000)); // added for showing the last progress info
Expand Down
4 changes: 4 additions & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Providers {
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, {
Expand Down
12 changes: 9 additions & 3 deletions src/providers/manifestDependencyHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ManifestDependencyHoverProvider implements vscode.HoverProvider {
}

const lineText = document.lineAt(position.line).text;
const dependencyName = this.parseDependencyName(lineText, currentManifestFile);
const dependencyName = this.parseDependencyName(lineText, currentManifestFile, document.getText());

if (!dependencyName) {
return null;
Expand Down Expand Up @@ -82,13 +82,19 @@ export class ManifestDependencyHoverProvider implements vscode.HoverProvider {
return contents;
}

private parseDependencyName(lineText: string, fileName: string): string | null {
private parseDependencyName(lineText: string, fileName: string, documentText: string): string | null {
lineText = lineText.trim();

switch (fileName) {
case "package.json": {
const manifestData = JSON.parse(documentText) || {};
const allDependencies = {
...manifestData.dependencies,
...manifestData.devDependencies,
};
const match = commonHelper.extractValueFromStringUsingRegex(lineText, Regex.packageJson);
if (match) {

if (match && match in allDependencies) {
return match;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/services/scanService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ScanService {
}
}

vscode.window.withProgress(
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Window,
title: Organization.nameCaps,
Expand All @@ -66,7 +66,7 @@ export class ScanService {
`${Organization.debrickedCli} ${cmdParams.join(" ")}`,
true,
);
if (!output.includes(SecondService.repositoryBaseUrl)) {
if (output.includes(SecondService.repositoryBaseUrl)) {
if (
DebrickedCommands.SCAN.flags &&
DebrickedCommands.SCAN.flags[2].report &&
Expand Down

0 comments on commit 4daae48

Please sign in to comment.