mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -07:00
refactor(ide ext): Update port file name + switch to 1-based index for characters + remove truncation text (#10501)
This commit is contained in:
@@ -43,9 +43,8 @@ const IDE_AUTH_TOKEN_ENV_VAR = 'GEMINI_CLI_IDE_AUTH_TOKEN';
|
||||
interface WritePortAndWorkspaceArgs {
|
||||
context: vscode.ExtensionContext;
|
||||
port: number;
|
||||
portFile: string;
|
||||
ppidPortFile: string;
|
||||
authToken: string;
|
||||
portFile: string | undefined;
|
||||
log: (message: string) => void;
|
||||
}
|
||||
|
||||
@@ -53,7 +52,6 @@ async function writePortAndWorkspace({
|
||||
context,
|
||||
port,
|
||||
portFile,
|
||||
ppidPortFile,
|
||||
authToken,
|
||||
log,
|
||||
}: WritePortAndWorkspaceArgs): Promise<void> {
|
||||
@@ -76,23 +74,21 @@ async function writePortAndWorkspace({
|
||||
authToken,
|
||||
);
|
||||
|
||||
if (!portFile) {
|
||||
log('Missing portFile, cannot write port and workspace info.');
|
||||
return;
|
||||
}
|
||||
|
||||
const content = JSON.stringify({
|
||||
port,
|
||||
workspacePath,
|
||||
ppid: process.ppid,
|
||||
authToken,
|
||||
});
|
||||
|
||||
log(`Writing port file to: ${portFile}`);
|
||||
log(`Writing ppid port file to: ${ppidPortFile}`);
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
fs.writeFile(portFile, content).then(() => fs.chmod(portFile, 0o600)),
|
||||
fs
|
||||
.writeFile(ppidPortFile, content)
|
||||
.then(() => fs.chmod(ppidPortFile, 0o600)),
|
||||
]);
|
||||
await fs.writeFile(portFile, content).then(() => fs.chmod(portFile, 0o600));
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
log(`Failed to write port to file: ${message}`);
|
||||
@@ -121,7 +117,7 @@ export class IDEServer {
|
||||
private context: vscode.ExtensionContext | undefined;
|
||||
private log: (message: string) => void;
|
||||
private portFile: string | undefined;
|
||||
private ppidPortFile: string | undefined;
|
||||
|
||||
private port: number | undefined;
|
||||
private authToken: string | undefined;
|
||||
private transports: { [sessionId: string]: StreamableHTTPServerTransport } =
|
||||
@@ -344,26 +340,28 @@ export class IDEServer {
|
||||
const address = (this.server as HTTPServer).address();
|
||||
if (address && typeof address !== 'string') {
|
||||
this.port = address.port;
|
||||
this.portFile = path.join(
|
||||
os.tmpdir(),
|
||||
`gemini-ide-server-${this.port}.json`,
|
||||
);
|
||||
this.ppidPortFile = path.join(
|
||||
os.tmpdir(),
|
||||
`gemini-ide-server-${process.ppid}.json`,
|
||||
);
|
||||
this.log(`IDE server listening on http://127.0.0.1:${this.port}`);
|
||||
|
||||
if (this.authToken) {
|
||||
await writePortAndWorkspace({
|
||||
context,
|
||||
port: this.port,
|
||||
portFile: this.portFile,
|
||||
ppidPortFile: this.ppidPortFile,
|
||||
authToken: this.authToken,
|
||||
log: this.log,
|
||||
});
|
||||
let portFile: string | undefined;
|
||||
try {
|
||||
const portDir = path.join(os.tmpdir(), 'gemini', 'ide');
|
||||
await fs.mkdir(portDir, { recursive: true });
|
||||
portFile = path.join(
|
||||
portDir,
|
||||
`gemini-ide-server-${process.ppid}-${this.port}.json`,
|
||||
);
|
||||
this.portFile = portFile;
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
this.log(`Failed to create IDE port file: ${message}`);
|
||||
}
|
||||
|
||||
await writePortAndWorkspace({
|
||||
context,
|
||||
port: this.port,
|
||||
portFile: this.portFile,
|
||||
authToken: this.authToken ?? '',
|
||||
log: this.log,
|
||||
});
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
@@ -392,19 +390,11 @@ export class IDEServer {
|
||||
}
|
||||
|
||||
async syncEnvVars(): Promise<void> {
|
||||
if (
|
||||
this.context &&
|
||||
this.server &&
|
||||
this.port &&
|
||||
this.portFile &&
|
||||
this.ppidPortFile &&
|
||||
this.authToken
|
||||
) {
|
||||
if (this.context && this.server && this.port && this.authToken) {
|
||||
await writePortAndWorkspace({
|
||||
context: this.context,
|
||||
port: this.port,
|
||||
portFile: this.portFile,
|
||||
ppidPortFile: this.ppidPortFile,
|
||||
authToken: this.authToken,
|
||||
log: this.log,
|
||||
});
|
||||
@@ -437,13 +427,6 @@ export class IDEServer {
|
||||
// Ignore errors if the file doesn't exist.
|
||||
}
|
||||
}
|
||||
if (this.ppidPortFile) {
|
||||
try {
|
||||
await fs.unlink(this.ppidPortFile);
|
||||
} catch (_err) {
|
||||
// Ignore errors if the file doesn't exist.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,15 +460,9 @@ const createMcpServer = (
|
||||
description: '(IDE Tool) Close an open diff view for a specific file.',
|
||||
inputSchema: CloseDiffRequestSchema.shape,
|
||||
},
|
||||
async ({
|
||||
filePath,
|
||||
suppressNotification,
|
||||
}: z.infer<typeof CloseDiffRequestSchema>) => {
|
||||
async ({ filePath }: z.infer<typeof CloseDiffRequestSchema>) => {
|
||||
log(`Received closeDiff request for filePath: ${filePath}`);
|
||||
const content = await diffManager.closeDiff(
|
||||
filePath,
|
||||
suppressNotification,
|
||||
);
|
||||
const content = await diffManager.closeDiff(filePath);
|
||||
const response = { content: content ?? undefined };
|
||||
return {
|
||||
content: [
|
||||
|
||||
Reference in New Issue
Block a user