refactor(vscode-ide-companion): simplify openDiff tool implementation

- Remove redundant file reading logic from ide-server
- Leverage diffManager's new capability to read old content internally
- Simplify openDiff tool call site to pass only newContent
- Update comments to reflect the simplified implementation
This commit is contained in:
yiliang114
2025-12-09 15:53:41 +08:00
parent f2a74c74b6
commit e91ea3ac1a

View File

@@ -437,18 +437,8 @@ const createMcpServer = (diffManager: DiffManager) => {
inputSchema: OpenDiffRequestSchema.shape,
},
async ({ filePath, newContent }: z.infer<typeof OpenDiffRequestSchema>) => {
// Read old content if file exists, otherwise use empty string
let oldContent = '';
try {
const fileUri = vscode.Uri.file(filePath);
const document = await vscode.workspace.openTextDocument(fileUri);
oldContent = document.getText();
} catch (_error) {
// File doesn't exist, use empty string (creating new file)
oldContent = '';
}
await diffManager.showDiff(filePath, oldContent, newContent);
// Minimal call site: only pass newContent; DiffManager reads old content itself
await diffManager.showDiff(filePath, newContent);
return { content: [] };
},
);