修改保存逻辑:在上传文件前先通过C++编译服务验证脚本
- 修改model.ts的saveFileContent方法,在上传文件前先通过C++服务验证脚本 - 如果C++服务可连接,则先发送脚本进行编译验证,只有在返回200状态码(编译通过)后才上传到服务器 - 如果C++服务返回非200状态码(编译失败),则不允许上传并提示错误 - 如果C++服务不可连接,则直接上传到服务器 - 简化extension.ts中的保存事件监听器,仅执行UI更新和缓存更新 - 保持原有错误处理机制,确保在C++服务故障时也能正常上传文件 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
50
dist/extension.js
vendored
50
dist/extension.js
vendored
@@ -49,7 +49,6 @@ const onTypeFormattingProvider_1 = require("./providers/onTypeFormattingProvider
|
||||
const documentFormattingProvider_1 = require("./providers/documentFormattingProvider");
|
||||
const codeErrorProvider_1 = require("./providers/codeErrorProvider");
|
||||
const apiParser_1 = require("./providers/apiParser");
|
||||
const localClient_1 = require("./localClient");
|
||||
function activate(context) {
|
||||
console.log('Squirrel NUT Explorer 正在激活...');
|
||||
// 初始化API解析器
|
||||
@@ -133,50 +132,11 @@ function activate(context) {
|
||||
const saveListener = vscode.workspace.onDidSaveTextDocument(async (doc) => {
|
||||
if (doc.uri.scheme === 'squirrel') {
|
||||
const filePath = doc.uri.path.substring(1); // 去掉开头的 '/'
|
||||
const fileContent = doc.getText();
|
||||
// 检查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} 发送到C++服务失败,跳过保存到服务器`);
|
||||
}
|
||||
}
|
||||
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} 保存到服务器失败`);
|
||||
}
|
||||
}
|
||||
// 当文件保存成功后执行UI更新和缓存更新
|
||||
output.appendLine(`[Squirrel] 文件 ${filePath} 已保存到服务器`);
|
||||
provider.refresh();
|
||||
// 更新函数缓存
|
||||
await functionExtractor.updateFileCache(model, filePath);
|
||||
}
|
||||
});
|
||||
// 注册文件关闭事件以清理缓存
|
||||
|
||||
Reference in New Issue
Block a user