修改保存逻辑:先发送文件到本地C++服务,成功后再保存到服务器

- 调整文件保存流程:首先向本地C++服务发送文件内容
- 只有在收到C++服务返回200状态码后才继续执行保存到服务器操作
- 如果C++服务响应失败,则跳过服务器保存,并提供相应提示

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
睿 安
2025-10-03 19:32:02 +08:00
parent 32108d0d2b
commit 8742b1d7d4
3 changed files with 38 additions and 33 deletions

34
dist/extension.js vendored
View File

@@ -134,28 +134,30 @@ function activate(context) {
if (doc.uri.scheme === 'squirrel') { if (doc.uri.scheme === 'squirrel') {
const filePath = doc.uri.path.substring(1); // 去掉开头的 '/' const filePath = doc.uri.path.substring(1); // 去掉开头的 '/'
const fileContent = doc.getText(); const fileContent = doc.getText();
const success = await model.saveFileContent(filePath, fileContent); // 先发送文件内容到本地C++服务
if (success) { try {
output.appendLine(`[Squirrel] 文件 ${filePath} 保存成功`); const sendSuccess = await (0, localClient_1.sendFileToCppService)(filePath, fileContent);
provider.refresh(); if (sendSuccess) {
// 更新函数缓存 output.appendLine(`[Squirrel] 文件 ${filePath} 已发送到C++服务`);
await functionExtractor.updateFileCache(model, filePath); // C++服务返回200后继续执行保存到服务器
// 发送文件内容到本地C++服务 const success = await model.saveFileContent(filePath, fileContent);
try { if (success) {
const sendSuccess = await (0, localClient_1.sendFileToCppService)(filePath, fileContent); output.appendLine(`[Squirrel] 文件 ${filePath} 保存成功`);
if (sendSuccess) { provider.refresh();
output.appendLine(`[Squirrel] 文件 ${filePath} 已发送到C++服务`); // 更新函数缓存
await functionExtractor.updateFileCache(model, filePath);
} }
else { else {
output.appendLine(`[Squirrel] 文件 ${filePath} 发送到C++服务失败`); output.appendLine(`[Squirrel] 文件 ${filePath} 保存到服务失败`);
} }
} }
catch (error) { else {
output.appendLine(`[Squirrel] 发送文件到C++服务时发生错误: ${error}`); output.appendLine(`[Squirrel] 文件 ${filePath} 发送到C++服务失败,跳过保存到服务器`);
} }
} }
else { catch (error) {
output.appendLine(`[Squirrel] 文件 ${filePath} 保存失败`); output.appendLine(`[Squirrel] 发送文件到C++服务时发生错误: ${error}`);
output.appendLine(`[Squirrel] 跳过保存文件 ${filePath} 到服务器`);
} }
} }
}); });

File diff suppressed because one or more lines are too long

View File

@@ -142,28 +142,31 @@ export function activate(context: vscode.ExtensionContext) {
if (doc.uri.scheme === 'squirrel') { if (doc.uri.scheme === 'squirrel') {
const filePath = doc.uri.path.substring(1); // 去掉开头的 '/' const filePath = doc.uri.path.substring(1); // 去掉开头的 '/'
const fileContent = doc.getText(); const fileContent = doc.getText();
const success = await model.saveFileContent(filePath, fileContent);
if (success) { // 先发送文件内容到本地C++服务
output.appendLine(`[Squirrel] 文件 ${filePath} 保存成功`); try {
provider.refresh(); const sendSuccess = await sendFileToCppService(filePath, fileContent);
if (sendSuccess) {
output.appendLine(`[Squirrel] 文件 ${filePath} 已发送到C++服务`);
// 更新函数缓存 // C++服务返回200后继续执行保存到服务器
await functionExtractor.updateFileCache(model, filePath); const success = await model.saveFileContent(filePath, fileContent);
// 发送文件内容到本地C++服务 if (success) {
try { output.appendLine(`[Squirrel] 文件 ${filePath} 保存成功`);
const sendSuccess = await sendFileToCppService(filePath, fileContent); provider.refresh();
if (sendSuccess) {
output.appendLine(`[Squirrel] 文件 ${filePath} 已发送到C++服务`); // 更新函数缓存
await functionExtractor.updateFileCache(model, filePath);
} else { } else {
output.appendLine(`[Squirrel] 文件 ${filePath} 发送到C++服务失败`); output.appendLine(`[Squirrel] 文件 ${filePath} 保存到服务失败`);
} }
} catch (error) { } else {
output.appendLine(`[Squirrel] 发送文件到C++服务时发生错误: ${error}`); output.appendLine(`[Squirrel] 文件 ${filePath} 发送到C++服务失败,跳过保存到服务器`);
} }
} else { } catch (error) {
output.appendLine(`[Squirrel] 文件 ${filePath} 保存失败`); output.appendLine(`[Squirrel] 发送文件到C++服务时发生错误: ${error}`);
output.appendLine(`[Squirrel] 跳过保存文件 ${filePath} 到服务器`);
} }
} }
}); });