开始修复的备份

This commit is contained in:
睿 安
2025-10-03 19:05:22 +08:00
parent 8f5ddd7dec
commit 32108d0d2b
4 changed files with 58 additions and 2 deletions

17
dist/extension.js vendored
View File

@@ -49,6 +49,7 @@ 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解析器
@@ -132,12 +133,26 @@ function activate(context) {
const saveListener = vscode.workspace.onDidSaveTextDocument(async (doc) => {
if (doc.uri.scheme === 'squirrel') {
const filePath = doc.uri.path.substring(1); // 去掉开头的 '/'
const success = await model.saveFileContent(filePath, doc.getText());
const fileContent = doc.getText();
const success = await model.saveFileContent(filePath, fileContent);
if (success) {
output.appendLine(`[Squirrel] 文件 ${filePath} 保存成功`);
provider.refresh();
// 更新函数缓存
await functionExtractor.updateFileCache(model, filePath);
// 发送文件内容到本地C++服务
try {
const sendSuccess = await (0, localClient_1.sendFileToCppService)(filePath, fileContent);
if (sendSuccess) {
output.appendLine(`[Squirrel] 文件 ${filePath} 已发送到C++服务`);
}
else {
output.appendLine(`[Squirrel] 文件 ${filePath} 发送到C++服务失败`);
}
}
catch (error) {
output.appendLine(`[Squirrel] 发送文件到C++服务时发生错误: ${error}`);
}
}
else {
output.appendLine(`[Squirrel] 文件 ${filePath} 保存失败`);

File diff suppressed because one or more lines are too long

Binary file not shown.

41
客户端.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "httplib.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
#include <string>
std::string buildJsonData(const std::string& str1, const std::string& str2) {
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
writer.StartObject();
writer.Key(str1.c_str()); // 使用 str1 作为 key
writer.String(str2.c_str()); // 使用 str2 作为 value
writer.EndObject();
return sb.GetString();
}
int main() {
httplib::Client cli("http://127.0.0.1:26000");
// 准备数据
std::string str1 = "load.nut";
std::string str2 = "\r\nlocal job = sq_getJob();\r\nprint(job);\r\n ";
// 构建 JSON
std::string jsonStr = buildJsonData(str1, str2);
std::cout << "发送的 JSON: " << jsonStr << std::endl;
// 发送数据
auto res = cli.Post("/send_data", jsonStr, "application/json");
if (res && res->status == 200) {
std::cout << "服务端回复: " << res->body << std::endl;
} else {
std::cerr << "发送失败,状态码: " << (res ? res->status : 0) << std::endl;
}
return 0;
}