cwd option in subprocess

This commit is contained in:
Nate 2024-10-08 08:32:06 -07:00
parent 71a517be23
commit 3aee3ca08c
8 changed files with 11 additions and 13 deletions

View file

@ -64,9 +64,7 @@ const getSubprocess = async (extras: ContextProviderExtras) => {
const workingDir = await extras.ide.getWorkspaceDirs().then(trimFirstElement);
return (command: string) =>
extras.ide
.subprocess(`cd ${workingDir}; ${command}`)
.then(trimFirstElement);
extras.ide.subprocess(command, workingDir).then(trimFirstElement);
};
class GitLabMergeRequestContextProvider extends BaseContextProvider {
@ -269,7 +267,7 @@ class GitLabMergeRequestContextProvider extends BaseContextProvider {
if (ex instanceof AxiosError) {
if (ex.response) {
const errorMessage = ex.response?.data
? ex.response.data.message ?? JSON.stringify(ex.response?.data)
? (ex.response.data.message ?? JSON.stringify(ex.response?.data))
: `${ex.response.status}: ${ex.response.statusText}`;
content += `GitLab Error: ${errorMessage}`;
} else {

2
core/index.d.ts vendored
View file

@ -500,7 +500,7 @@ export interface IDE {
getCurrentFile(): Promise<string | undefined>;
getPinnedFiles(): Promise<string[]>;
getSearchResults(query: string): Promise<string>;
subprocess(command: string): Promise<[string, string]>;
subprocess(command: string, cwd?: string): Promise<[string, string]>;
getProblems(filepath?: string | undefined): Promise<Problem[]>;
getBranch(dir: string): Promise<string>;
getTags(artifactId: string): Promise<IndexTag[]>;

View file

@ -29,7 +29,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
openFile: [{ path: string }, void];
runCommand: [{ command: string }, void];
getSearchResults: [{ query: string }, string];
subprocess: [{ command: string }, [string, string]];
subprocess: [{ command: string; cwd?: string }, [string, string]];
saveFile: [{ filepath: string }, void];
fileExists: [{ filepath: string }, boolean];
readFile: [{ filepath: string }, string];

View file

@ -237,7 +237,7 @@ class FileSystemIde implements IDE {
return Promise.resolve([]);
}
async subprocess(command: string): Promise<[string, string]> {
async subprocess(command: string, cwd?: string): Promise<[string, string]> {
return ["", ""];
}
}

View file

@ -193,8 +193,8 @@ export class MessageIde implements IDE {
return this.request("getProblems", { filepath });
}
subprocess(command: string): Promise<[string, string]> {
return this.request("subprocess", { command });
subprocess(command: string, cwd?: string): Promise<[string, string]> {
return this.request("subprocess", { command, cwd });
}
async getBranch(dir: string): Promise<string> {

View file

@ -182,7 +182,7 @@ export class ReverseMessageIde {
});
this.on("subprocess", (data) => {
return this.ide.subprocess(data.command);
return this.ide.subprocess(data.command, data.cwd);
});
this.on("getBranch", (data) => {

View file

@ -512,9 +512,9 @@ class VsCodeIde implements IDE {
});
}
async subprocess(command: string): Promise<[string, string]> {
async subprocess(command: string, cwd?: string): Promise<[string, string]> {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
exec(command, { cwd }, (error, stdout, stderr) => {
if (error) {
console.warn(error);
reject(stderr);

View file

@ -325,7 +325,7 @@ export class VsCodeMessenger {
return ide.getSearchResults(msg.data.query);
});
this.onWebviewOrCore("subprocess", async (msg) => {
return ide.subprocess(msg.data.command);
return ide.subprocess(msg.data.command, msg.data.cwd);
});
this.onWebviewOrCore("getProblems", async (msg) => {
return ide.getProblems(msg.data.filepath);