Skip to content
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

Hover provider bug fixes #66

Merged
merged 2 commits into from
Sep 26, 2024
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 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