Skip to content

Commit

Permalink
Add flag for rpc-server
Browse files Browse the repository at this point in the history
  • Loading branch information
hhpatel14 committed Oct 25, 2024
1 parent f1b0606 commit 096bf09
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 11 deletions.
Binary file removed vscode/assets/bin/kai-analyzer.darwin.amd64
Binary file not shown.
2 changes: 2 additions & 0 deletions vscode/media/walkthroughs/enable-generativeAI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enable GenerativeAI

39 changes: 38 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
"category": "Konveyor",
"icon": "$(gear)"
},
{
"command": "konveyor.overriderpcServerBinaries",
"title": "Override Analyzer Binaries",
"category": "Konveyor",
"icon": "$(gear)"
},
{
"command": "konveyor.configureCustomRules",
"title": "Configure Custom Rules",
Expand Down Expand Up @@ -75,6 +81,12 @@
"title": "Run Analysis",
"category": "Konveyor",
"icon": "$(play}"
},
{
"command": "konveyor.toggleGenerativeAI",
"title": "Toggle GenerativeAI",
"category": "Konveyor",
"icon": "$(gear}"
}
],
"submenus": [
Expand Down Expand Up @@ -136,6 +148,13 @@
"scope": "machine",
"order": 0
},
"konveyor.rpcServerPath": {
"type": "string",
"default": "",
"description": "Path to the rpc-server binary. If not set, the extension will use the bundled binary.",
"scope": "machine",
"order": 0
},
"konveyor.incidentLimit": {
"type": "number",
"default": 10000,
Expand Down Expand Up @@ -201,6 +220,13 @@
"description": "Whether analysis of file should be run when saved",
"scope": "window",
"order": 9
},
"konveyor.enableGenerativeAI": {
"type": "boolean",
"default": true,
"description": "Enable Generative AI set ",
"scope": "window",
"order": 10
}
}
},
Expand All @@ -210,10 +236,21 @@
"title": "Set up Konveyor",
"description": "Configure Konveyor for your project",
"steps": [
{
"id": "enable-generativeAI",
"title": "Configure GenerativeAI",
"description": "Generative AI is enabled by default. Use the buttons to toggle. \n[Enable](command:konveyor.toggleGenerativeAI)",
"completionEvents": [
"onCommand:konveyor.toggleGenerativeAI"
],
"media": {
"markdown": "media/walkthroughs/enable-generativeAI.md"
}
},
{
"id": "override-analyzer",
"title": "Override Analyzer Binary",
"description": "Specify a custom path for the analyzer binary\n[Override Analyzer Binary](command:konveyor.overrideAnalyzerBinaries)",
"description": "Specify a custom path for the analyzer binary\n[Override Analyzer Binary](command:konveyor.overrideAnalyzerBinaries)\n[Override GenerativeAI Binary](command:konveyor.overriderpcServerBinaries)",
"completionEvents": [],
"media": {
"markdown": "media/walkthroughs/override-analyzer.md"
Expand Down
84 changes: 74 additions & 10 deletions vscode/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class AnalyzerClient {
private config: vscode.WorkspaceConfiguration | null = null;
private extContext: vscode.ExtensionContext | null = null;
private analyzerServer: ChildProcessWithoutNullStreams | null = null;
private rpcServer: ChildProcessWithoutNullStreams | null = null;
private outputChannel: vscode.OutputChannel;
// private rpcConnection: rpc.MessageConnection | null = null;
private requestId: number = 1;
Expand All @@ -24,7 +25,7 @@ export class AnalyzerClient {
}

public start(): void {
if (!this.canAnalyze) {
if (!this.canAnalyze()) {
return;
}
exec("java -version", (err) => {
Expand All @@ -40,16 +41,33 @@ export class AnalyzerClient {
}
});

this.analyzerServer = spawn(this.getAnalyzerPath(), this.getAnalyzerArgs(), {
cwd: this.extContext!.extensionPath,
});
let serverType: string;
// Determine the server type and path
if (this.isGenAiEnabled()) {
serverType = "Generative AI (rpcServer)";
this.analyzerServer = spawn(this.getRpcServerPath(), {
cwd: this.extContext!.extensionPath,
});
} else {
serverType = "Analyzer";
this.analyzerServer = spawn(this.getAnalyzerPath(), this.getAnalyzerArgs(), {
cwd: this.extContext!.extensionPath,
});
}
this.analyzerServer.stderr.on("data", (data) => {
this.outputChannel.appendLine(`${data.toString()}`);
this.outputChannel.appendLine(`${serverType} Error: ${data.toString()}`);
});

this.analyzerServer.on("exit", (code) => {
this.outputChannel.appendLine(`Analyzer exited with code ${code}`);
this.outputChannel.appendLine(`${serverType} server exited with code ${code}`);
});

this.outputChannel.appendLine(`${serverType} server started successfully.`);
}

// Check if Generative AI is enabled
public isGenAiEnabled(): boolean {
return this.config?.get<boolean>("enableGenerativeAI", true) || false;
}

// Stops the analyzer server
Expand Down Expand Up @@ -222,6 +240,12 @@ export class AnalyzerClient {
}

public getAnalyzerPath(): string {
const analyzerPath = this.config?.get<string>("analyzerPath");
if (analyzerPath && fs.existsSync(analyzerPath)) {
vscode.window.showInformationMessage(`passed by user: ${analyzerPath}`);
return analyzerPath;
}

const platform = os.platform();
const arch = os.arch();

Expand All @@ -231,14 +255,54 @@ export class AnalyzerClient {
}

// Full path to the analyzer binary
const analyzerPath = path.join(this.extContext!.extensionPath, "assets", "bin", binaryName);
const defaultAnalyzerPath = path.join(
this.extContext!.extensionPath,
"assets",
"bin",
binaryName,
);

// Check if the binary exists
if (!fs.existsSync(analyzerPath)) {
vscode.window.showErrorMessage(`Analyzer binary doesn't exist at ${analyzerPath}`);
if (!fs.existsSync(defaultAnalyzerPath)) {
vscode.window.showErrorMessage(`Analyzer binary doesn't exist at ${defaultAnalyzerPath}`);
}

return defaultAnalyzerPath;
}
public getRpcServerPath(): string {
// Retrieve the rpcServerPath
const rpcServerPath = this.config?.get<string>("rpcServerPath");
vscode.window.showInformationMessage(`passed by user:---- ${rpcServerPath}`);
if (rpcServerPath && fs.existsSync(rpcServerPath)) {
vscode.window.showInformationMessage(`passed by user: ${rpcServerPath}`);
return rpcServerPath;
}

// Fallback to default rpc-server binary path if user did not provid path
const platform = os.platform();
const arch = os.arch();

let binaryName = `kai-rpc-server.${platform}.${arch}`;
if (platform === "win32") {
binaryName += ".exe";
}

// Construct the full path
const defaultRpcServerPath = path.join(
this.extContext!.extensionPath,
"assets",
"bin",
binaryName,
);

// Check if the default rpc-server binary exists, else show an error message
if (!fs.existsSync(defaultRpcServerPath)) {
vscode.window.showErrorMessage(`RPC server binary doesn't exist at ${defaultRpcServerPath}`);
throw new Error(`RPC server binary not found at ${defaultRpcServerPath}`);
}

return analyzerPath;
// Return the default path
return defaultRpcServerPath;
}

public getAnalyzerArgs(): string[] {
Expand Down
40 changes: 40 additions & 0 deletions vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ const commandsMap: (state: ExtensionState) => {
vscode.window.showInformationMessage("No analyzer binary selected.");
}
},
"konveyor.overriderpcServerBinaries": async () => {
const options: vscode.OpenDialogOptions = {
canSelectMany: false,
openLabel: "Select GenAI Binary",
filters: {
"Executable Files": ["exe", "sh", "bat", ""],
"All Files": ["*"],
},
};

const fileUri = await vscode.window.showOpenDialog(options);

if (fileUri && fileUri[0]) {
const filePath = fileUri[0].fsPath;

// Update the user settings
const config = vscode.workspace.getConfiguration("konveyor");
await config.update("rpcServerPath", filePath, vscode.ConfigurationTarget.Global);

vscode.window.showInformationMessage(`rpc server binary path updated to: ${filePath}`);
} else {
vscode.window.showInformationMessage("No rpc-server binary selected.");
}
},
"konveyor.configureCustomRules": async () => {
const options: vscode.OpenDialogOptions = {
canSelectMany: true,
Expand Down Expand Up @@ -299,6 +323,22 @@ const commandsMap: (state: ExtensionState) => {
vscode.ConfigurationTarget.Workspace,
);
},
"konveyor.toggleGenerativeAI": async () => {
const options = ["Yes", "No"];
const selection = await vscode.window.showQuickPick(options, {
placeHolder: "Enable Generative AI?",
});

if (selection === "Yes") {
const config = vscode.workspace.getConfiguration("konveyor");
await config.update("enableGenerativeAI", true, vscode.ConfigurationTarget.Workspace);
vscode.window.showInformationMessage("Generative AI is now enabled.");
} else if (selection === "No") {
const config = vscode.workspace.getConfiguration("konveyor");
await config.update("enableGenerativeAI", false, vscode.ConfigurationTarget.Workspace);
vscode.window.showInformationMessage("Generative AI is now disabled.");
}
},
};
};

Expand Down

0 comments on commit 096bf09

Please sign in to comment.