Skip to content

Commit

Permalink
✨ the new analyzer stuff
Browse files Browse the repository at this point in the history
Signed-off-by: David Zager <dzager@redhat.com>
  • Loading branch information
djzager committed Oct 14, 2024
1 parent 6db9f41 commit 6f30bd4
Show file tree
Hide file tree
Showing 89 changed files with 320 additions and 366 deletions.
Empty file.
Empty file.
Binary file not shown.

This file was deleted.

This file was deleted.

Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified vscode/assets/bin/kai-analyzer
Binary file not shown.
8 changes: 7 additions & 1 deletion vscode/media/walkthroughs/start-analyzer.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Start Analyzer

Not yet implemented.
Start using the rules-based analysis engine.

Remember to configure your analysis settings beforehand for the best results:

Set up custom rules if needed.
Configure label selector directly or through choosing sources and targets.
These settings can be modified in the Konveyor extension settings or through the walkthrough steps you've already completed.
25 changes: 11 additions & 14 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@
"icon": "$(gear)"
},
{
"command": "konveyor.startAnalysis",
"title": "Start Analysis",
"command": "konveyor.startAnalyzer",
"title": "Start Analyzer",
"category": "Konveyor",
"icon": "$(gear)"
"icon": "$(play}"
},
{
"command": "konveyor.runAnalysis",
"title": "Run Analysis",
"category": "Konveyor",
"icon": "$(play}"
}
],
"submenus": [
Expand Down Expand Up @@ -109,10 +115,6 @@
"command": "konveyor.toggleFullScreen",
"group": "navigation@1",
"when": "activeWebviewPanelId == konveyor.konveyorGUIView"
},
{
"command": "konveyor.startAnalysis",
"group": "navigation@1"
}
],
"explorer/context": [
Expand All @@ -121,12 +123,7 @@
"group": "navigation@1"
}
],
"konveyor.submenu": [
{
"command": "konveyor.startAnalysis",
"group": "navigation@1"
}
]
"konveyor.submenu": []
},
"configuration": {
"type": "object",
Expand Down Expand Up @@ -248,7 +245,7 @@
{
"id": "start-analyzer",
"title": "Start Analyzer",
"description": "Start the analyzer",
"description": "Start the analyzer\n[Start Analyzer](command:konveyor.startAnalyzer)",
"completionEvents": [],
"media": {
"markdown": "media/walkthroughs/start-analyzer.md"
Expand Down
100 changes: 6 additions & 94 deletions vscode/src/VsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { KonveyorGUIWebviewViewProvider } from "./KonveyorGUIWebviewViewProvider
import { registerAllCommands } from "./commands";
import { setupWebviewMessageListener } from "./webviewMessageHandler";
import { ExtensionState, SharedState } from "./extensionState";
import { mockResults } from "./webview/mockResults";
import { ViolationCodeActionProvider } from "./ViolationCodeActionProvider";
import { AnalyzerClient } from "./client/analyzerClient";

export class VsCodeExtension {
private extensionContext: vscode.ExtensionContext;
Expand All @@ -17,6 +17,7 @@ export class VsCodeExtension {
this.windowId = uuidv4();

this.state = {
analyzerClient: new AnalyzerClient(context),
sharedState: new SharedState(),
webviewProviders: new Set<KonveyorGUIWebviewViewProvider>(),
sidebarProvider: undefined as any,
Expand Down Expand Up @@ -46,99 +47,6 @@ export class VsCodeExtension {
sidebarProvider.onWebviewReady((webview) => {
setupWebviewMessageListener(webview, this.state);
});
//DEBUG USE ONLY
setTimeout(() => {
const diagnosticCollection = vscode.languages.createDiagnosticCollection("konveyor");

const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;

function updateIncidentPaths(incidents: any[], workspaceFolderPath: string): any[] {
return incidents.map((incident) => {
if (incident.uri.startsWith("file:///opt/input/source")) {
incident.uri = incident.uri.replace(
"file:///opt/input/source",
vscode.Uri.file(workspaceFolderPath).toString(),
);
}
return incident;
});
}

// Update incident paths
const updatedResults = mockResults.map((ruleset: any) => {
const violations = ruleset.violations ?? {};
Object.keys(violations).forEach((ruleId) => {
const incidents = violations[ruleId].incidents;
if (incidents) {
violations[ruleId].incidents = updateIncidentPaths(
incidents,
workspaceFolderPath || "",
);
}
});
return ruleset;
});

// Prepare diagnostics
const diagnosticsMap: Map<string, vscode.Diagnostic[]> = new Map();

mockResults.forEach((ruleset: any) => {
Object.keys(ruleset.violations ?? {}).forEach((ruleId) => {
const category = ruleset.violations[ruleId].category;

ruleset.violations[ruleId].incidents?.forEach((incident: any) => {
const fileUriString = incident.uri;
const fileUri = vscode.Uri.parse(fileUriString);
const fileKey = fileUri.toString();

let lineNumber = incident.lineNumber ? incident.lineNumber - 1 : 0;
if (lineNumber < 0) {
lineNumber = 0;
}

const severity = (category: string) => {
if (category === "mandatory") {
return vscode.DiagnosticSeverity.Error;
}
if (category === "potential") {
return vscode.DiagnosticSeverity.Warning;
}
if (category === "optional") {
return vscode.DiagnosticSeverity.Information;
}
return vscode.DiagnosticSeverity.Hint;
};

const diagnostic = new vscode.Diagnostic(
new vscode.Range(lineNumber, 0, lineNumber, Number.MAX_SAFE_INTEGER),
incident.message,
severity(category),
);

// Collect diagnostics per file
let diagnostics = diagnosticsMap.get(fileKey);
if (!diagnostics) {
diagnostics = [];
diagnosticsMap.set(fileKey, diagnostics);
}
diagnostics.push(diagnostic);
});
});
});

// Set diagnostics per file
diagnosticsMap.forEach((diagnostics, fileKey) => {
const fileUri = vscode.Uri.parse(fileKey);
diagnosticCollection.set(fileUri, diagnostics);
});

vscode.window.showInformationMessage("Diagnostics created.");
sidebarProvider?.webview?.postMessage({
type: "analysisComplete",
data: mockResults,
});
}, 5000);
//

registerAllCommands(this.state);

Expand All @@ -152,4 +60,8 @@ export class VsCodeExtension {
);
}
}

getAnalyzerClient(): AnalyzerClient {
return this.state.analyzerClient;
}
}
Loading

0 comments on commit 6f30bd4

Please sign in to comment.