1.0.4 将库函数外置,插件文件夹下api-functions.json
This commit is contained in:
90
dist/providers/apiParser.js
vendored
90
dist/providers/apiParser.js
vendored
@@ -1,12 +1,51 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApiParser = void 0;
|
||||
const vscode = __importStar(require("vscode"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
// API文档解析器类
|
||||
class ApiParser {
|
||||
constructor() {
|
||||
this.functions = [];
|
||||
this.classes = [];
|
||||
this.constants = [];
|
||||
// 获取扩展路径并设置JSON文件路径
|
||||
const extensionPath = vscode.extensions.getExtension('local.squirrel-nut-explorer')?.extensionPath || __dirname;
|
||||
this.jsonFilePath = path.join(extensionPath, 'api-functions.json');
|
||||
this.initializeApiDocumentation();
|
||||
}
|
||||
// 获取单例实例
|
||||
@@ -18,6 +57,33 @@ class ApiParser {
|
||||
}
|
||||
// 初始化API文档
|
||||
initializeApiDocumentation() {
|
||||
try {
|
||||
// 检查JSON文件是否存在
|
||||
if (fs.existsSync(this.jsonFilePath)) {
|
||||
// 读取JSON文件
|
||||
const jsonData = fs.readFileSync(this.jsonFilePath, 'utf8');
|
||||
const apiData = JSON.parse(jsonData);
|
||||
// 加载函数数据
|
||||
this.functions = apiData.functions || [];
|
||||
// 加载类数据
|
||||
this.classes = apiData.classes || [];
|
||||
// 加载常量数据
|
||||
this.constants = apiData.constants || [];
|
||||
}
|
||||
else {
|
||||
// 如果JSON文件不存在,使用默认数据并创建文件
|
||||
this.initializeDefaultApiDocumentation();
|
||||
this.saveApiDocumentation();
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('读取API函数JSON文件失败:', error);
|
||||
// 如果读取失败,使用默认数据
|
||||
this.initializeDefaultApiDocumentation();
|
||||
}
|
||||
}
|
||||
// 初始化默认API文档
|
||||
initializeDefaultApiDocumentation() {
|
||||
// 初始化内置函数
|
||||
this.functions = [
|
||||
{
|
||||
@@ -292,12 +358,6 @@ class ApiParser {
|
||||
description: '圆周率',
|
||||
category: 'math'
|
||||
},
|
||||
{
|
||||
name: 'E',
|
||||
value: '2.71828',
|
||||
description: '自然常数',
|
||||
category: 'math'
|
||||
},
|
||||
{
|
||||
name: 'true',
|
||||
value: 'true',
|
||||
@@ -318,6 +378,24 @@ class ApiParser {
|
||||
}
|
||||
];
|
||||
}
|
||||
// 保存API文档到JSON文件
|
||||
saveApiDocumentation() {
|
||||
try {
|
||||
const apiData = {
|
||||
functions: this.functions,
|
||||
classes: this.classes,
|
||||
constants: this.constants
|
||||
};
|
||||
fs.writeFileSync(this.jsonFilePath, JSON.stringify(apiData, null, 2), 'utf8');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('保存API函数JSON文件失败:', error);
|
||||
}
|
||||
}
|
||||
// 重新加载API文档
|
||||
reloadApiDocumentation() {
|
||||
this.initializeApiDocumentation();
|
||||
}
|
||||
// 获取所有函数
|
||||
getFunctions() {
|
||||
return this.functions;
|
||||
|
||||
2
dist/providers/apiParser.js.map
vendored
2
dist/providers/apiParser.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user