修改保存逻辑:先检查C++服务连接性再决定上传流程

- 添加checkCppServiceConnection函数用于检查C++服务是否可连接
- 修改保存逻辑:如果C++服务可连接,先发送文件内容到C++服务,只有在收到200状态码后才继续保存到服务器
- 如果C++服务不可连接,则直接使用API函数保存到服务器
- 完善输出信息,帮助用户了解当前处理流程

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
睿 安
2025-10-03 19:54:53 +08:00
parent 8742b1d7d4
commit 95dfc4397e
6 changed files with 168 additions and 39 deletions

54
dist/extension.js vendored
View File

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