Skip to content

Commit

Permalink
✨ Set cwd for kai-rpc-server to a .vscode/ path (#154)
Browse files Browse the repository at this point in the history
The `kai-rpc-server` processes generate some working directories that
are created in the process's given working directory. Set the process's
current working directory to a path under the workspace's `.vscode/`
directory. This will ensure that if multiple vscode windows are open,
the konveyor runtime binaries will not clash with each other.

The process will run with a cwd of:
   `{{workspace_root}}/.vscode/konveyor/kai-runtime`

Signed-off-by: Scott J Dickerson <[email protected]>
  • Loading branch information
sjd78 authored Dec 12, 2024
1 parent 29af6b5 commit 26e09a6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
25 changes: 23 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"@types/fs-extra": "^11.0.4",
"@types/js-yaml": "^4.0.9",
"@types/node": "22.x",
"@types/react": "^18.3.11",
Expand All @@ -78,7 +79,6 @@
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"eslint-plugin-unused-imports": "^4.1.4",
"fs-extra": "^11.2.0",
"globals": "^15.0.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
Expand All @@ -90,6 +90,7 @@
"unzipper": "^0.12.3"
},
"dependencies": {
"fs-extra": "^11.2.0",
"globby": "^14.0.2",
"immer": "10.1.1",
"js-yaml": "^4.1.0",
Expand Down
26 changes: 13 additions & 13 deletions vscode/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChildProcessWithoutNullStreams, spawn } from "node:child_process";
import * as fs from "node:fs";
import * as path from "node:path";
import { setTimeout } from "node:timers/promises";
import * as fs from "fs-extra";
import * as vscode from "vscode";
import * as rpc from "vscode-jsonrpc/node";
import { Incident, RuleSet, SolutionResponse, Violation } from "@editor-extensions/shared";
Expand Down Expand Up @@ -33,6 +33,7 @@ export class AnalyzerClient {
private outputChannel: vscode.OutputChannel;
private assetPaths: AssetPaths;
private kaiDir: string;
private kaiRuntimeDir: string;
private kaiConfigToml: string;
private fireStateChange: (state: ServerState) => void;
private fireAnalysisStateChange: (flag: boolean) => void;
Expand Down Expand Up @@ -60,8 +61,12 @@ export class AnalyzerClient {

this.assetPaths = buildAssetPaths(extContext);
this.kaiDir = path.join(buildDataFolderPath()!, "kai");
this.kaiRuntimeDir = path.join(buildDataFolderPath()!, "kai-runtime");
this.kaiConfigToml = path.join(this.kaiDir, "kai-config.toml");

fs.ensureDirSync(this.kaiDir);
fs.ensureDirSync(this.kaiRuntimeDir);

this.outputChannel.appendLine(
`current asset paths: ${JSON.stringify(this.assetPaths, null, 2)}`,
);
Expand All @@ -77,20 +82,19 @@ export class AnalyzerClient {
return;
}

// TODO: If the server generates files in cwd, we should set this to something else
const serverCwd = this.extContext.extensionPath;
const serverCwd = this.kaiRuntimeDir;
const serverEnv = await this.getKaiRpcServerEnv();
const serverPath = this.getKaiRpcServerPath();
const serverArgs = this.getKaiRpcServerArgs();

this.fireStateChange("starting");
this.outputChannel.appendLine(`Starting the kai rpc server ...`);
this.outputChannel.appendLine(`server cwd: ${serverCwd}`);
this.outputChannel.appendLine(`server path: ${this.getKaiRpcServerPath()}`);
this.outputChannel.appendLine(`server path: ${serverPath}`);
this.outputChannel.appendLine(`server args:`);
this.getKaiRpcServerArgs().forEach((arg) => this.outputChannel.appendLine(` ${arg}`));

// Retrieve the environment variables asynchronously
const serverEnv = await this.getKaiRpcServerEnv();
serverArgs.forEach((arg) => this.outputChannel.appendLine(` ${arg}`));

const kaiRpcServer = spawn(this.getKaiRpcServerPath(), this.getKaiRpcServerArgs(), {
const kaiRpcServer = spawn(serverPath, serverArgs, {
cwd: serverCwd,
env: serverEnv,
});
Expand Down Expand Up @@ -538,10 +542,6 @@ export class AnalyzerClient {
}

public getKaiConfigTomlPath(): string {
if (!fs.existsSync(this.kaiDir)) {
fs.mkdirSync(this.kaiDir, { recursive: true });
}

// Ensure the file exists with default content if it doesn't
// Consider making this more robust, maybe this is an asset we can get from kai?
if (!fs.existsSync(this.kaiConfigToml)) {
Expand Down

0 comments on commit 26e09a6

Please sign in to comment.