1.1.1 优化自动补全和悬浮显示
This commit is contained in:
71
dist/providers/apiParser.js
vendored
71
dist/providers/apiParser.js
vendored
@@ -40,7 +40,8 @@ const path = __importStar(require("path"));
|
||||
// API文档解析器类
|
||||
class ApiParser {
|
||||
constructor() {
|
||||
this.functions = [];
|
||||
this.functions = []; // 普通函数,不自动填写第一个参数
|
||||
this.functionEx = []; // 扩展函数,自动填写所有参数
|
||||
this.classes = [];
|
||||
this.constants = [];
|
||||
// 获取扩展路径并设置JSON文件路径
|
||||
@@ -65,6 +66,7 @@ class ApiParser {
|
||||
const apiData = JSON.parse(jsonData);
|
||||
// 加载函数数据
|
||||
this.functions = apiData.functions || [];
|
||||
this.functionEx = apiData.functionEx || [];
|
||||
// 加载类数据
|
||||
this.classes = apiData.classes || [];
|
||||
// 加载常量数据
|
||||
@@ -383,6 +385,7 @@ class ApiParser {
|
||||
try {
|
||||
const apiData = {
|
||||
functions: this.functions,
|
||||
functionEx: this.functionEx,
|
||||
classes: this.classes,
|
||||
constants: this.constants
|
||||
};
|
||||
@@ -396,13 +399,27 @@ class ApiParser {
|
||||
reloadApiDocumentation() {
|
||||
this.initializeApiDocumentation();
|
||||
}
|
||||
// 获取所有函数
|
||||
// 获取所有普通函数
|
||||
getFunctions() {
|
||||
return this.functions;
|
||||
}
|
||||
// 根据名称获取函数
|
||||
// 获取所有扩展函数
|
||||
getFunctionEx() {
|
||||
return this.functionEx;
|
||||
}
|
||||
// 根据名称获取函数(包括普通函数和扩展函数)
|
||||
getFunctionByName(name) {
|
||||
return this.functions.find(func => func.name === name);
|
||||
// 先在普通函数中查找
|
||||
let func = this.functions.find(func => func.name === name);
|
||||
if (func) {
|
||||
return func;
|
||||
}
|
||||
// 再在扩展函数中查找
|
||||
return this.functionEx.find(func => func.name === name);
|
||||
}
|
||||
// 检查是否是扩展函数
|
||||
isFunctionEx(name) {
|
||||
return this.functionEx.some(func => func.name === name);
|
||||
}
|
||||
// 获取所有类
|
||||
getClasses() {
|
||||
@@ -425,19 +442,41 @@ class ApiParser {
|
||||
return this.constants.find(constant => constant.name === name);
|
||||
}
|
||||
// 生成函数签名
|
||||
generateFunctionSignature(func) {
|
||||
const params = func.params.map(param => {
|
||||
let paramStr = param.name;
|
||||
if (param.optional) {
|
||||
paramStr = `[${paramStr}`;
|
||||
if (param.defaultValue) {
|
||||
paramStr += `=${param.defaultValue}`;
|
||||
generateFunctionSignature(func, isFunctionEx = false) {
|
||||
// 检查是否是普通函数且有参数
|
||||
if (!isFunctionEx && func.params.length > 0) {
|
||||
// 对于普通函数,将第一个参数移到函数名前面
|
||||
const firstParam = func.params[0];
|
||||
const remainingParams = func.params.slice(1);
|
||||
const params = remainingParams.map(param => {
|
||||
let paramStr = param.name;
|
||||
if (param.optional) {
|
||||
paramStr = `[${paramStr}`;
|
||||
if (param.defaultValue) {
|
||||
paramStr += `=${param.defaultValue}`;
|
||||
}
|
||||
paramStr += ']';
|
||||
}
|
||||
paramStr += ']';
|
||||
}
|
||||
return paramStr;
|
||||
}).join(', ');
|
||||
return `function ${func.name}(${params})${func.returns ? `: ${func.returns.type}` : ': void'}`;
|
||||
return paramStr;
|
||||
}).join(', ');
|
||||
const paramPart = params ? `(${params})` : '()';
|
||||
return `function ${firstParam.name}.${func.name}${paramPart}${func.returns ? `: ${func.returns.type}` : ': void'}`;
|
||||
}
|
||||
else {
|
||||
// 对于扩展函数或无参数的函数,保持原有格式
|
||||
const params = func.params.map(param => {
|
||||
let paramStr = param.name;
|
||||
if (param.optional) {
|
||||
paramStr = `[${paramStr}`;
|
||||
if (param.defaultValue) {
|
||||
paramStr += `=${param.defaultValue}`;
|
||||
}
|
||||
paramStr += ']';
|
||||
}
|
||||
return paramStr;
|
||||
}).join(', ');
|
||||
return `function ${func.name}(${params})${func.returns ? `: ${func.returns.type}` : ': void'}`;
|
||||
}
|
||||
}
|
||||
// 生成类签名
|
||||
generateClassSignature(cls) {
|
||||
|
||||
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
33
dist/providers/completionProvider.js
vendored
33
dist/providers/completionProvider.js
vendored
@@ -96,21 +96,50 @@ class CompletionProvider {
|
||||
}
|
||||
// 获取API函数完成项
|
||||
getApiFunctionCompletions() {
|
||||
const completions = [];
|
||||
// 添加普通函数(不自动填写第一个参数)
|
||||
const functions = this.apiParser.getFunctions();
|
||||
return functions.map(func => {
|
||||
functions.forEach(func => {
|
||||
const item = new vscode.CompletionItem(func.name, vscode.CompletionItemKind.Function);
|
||||
item.detail = '内置函数';
|
||||
item.documentation = new vscode.MarkdownString(`\`\`\`squirrel\n${this.apiParser.generateFunctionSignature(func)}\n\`\`\`\n${func.description}`);
|
||||
// 为函数创建带参数的插入文本
|
||||
if (func.params.length > 0) {
|
||||
// 普通函数不自动填写第一个参数,用户需要手动输入
|
||||
if (func.params.length > 1) {
|
||||
// 从第二个参数开始添加占位符
|
||||
const remainingParams = func.params.slice(1);
|
||||
const paramText = remainingParams.map((param, index) => `\${${index + 1}:${param.name}}`).join(', ');
|
||||
item.insertText = new vscode.SnippetString(`${func.name}(${paramText})`);
|
||||
}
|
||||
else {
|
||||
// 只有一个参数或无参数
|
||||
item.insertText = new vscode.SnippetString(`${func.name}()`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
item.insertText = new vscode.SnippetString(`${func.name}()`);
|
||||
}
|
||||
completions.push(item);
|
||||
});
|
||||
// 添加扩展函数(自动填写所有参数)
|
||||
const functionEx = this.apiParser.getFunctionEx();
|
||||
functionEx.forEach(func => {
|
||||
const item = new vscode.CompletionItem(func.name, vscode.CompletionItemKind.Function);
|
||||
item.detail = '扩展函数';
|
||||
item.documentation = new vscode.MarkdownString(`\`\`\`squirrel\n${this.apiParser.generateFunctionSignature(func)}\n\`\`\`\n${func.description}`);
|
||||
// 为函数创建带参数的插入文本
|
||||
if (func.params.length > 0) {
|
||||
// 扩展函数自动填写所有参数
|
||||
const paramText = func.params.map((param, index) => `\${${index + 1}:${param.name}}`).join(', ');
|
||||
item.insertText = new vscode.SnippetString(`${func.name}(${paramText})`);
|
||||
}
|
||||
else {
|
||||
item.insertText = new vscode.SnippetString(`${func.name}()`);
|
||||
}
|
||||
return item;
|
||||
completions.push(item);
|
||||
});
|
||||
return completions;
|
||||
}
|
||||
// 获取API类完成项
|
||||
getApiClassCompletions() {
|
||||
|
||||
2
dist/providers/completionProvider.js.map
vendored
2
dist/providers/completionProvider.js.map
vendored
File diff suppressed because one or more lines are too long
3
dist/providers/hoverProvider.js
vendored
3
dist/providers/hoverProvider.js
vendored
@@ -60,7 +60,8 @@ class HoverProvider {
|
||||
// 首先检查是否是API函数
|
||||
const apiFunction = this.apiParser.getFunctionByName(word);
|
||||
if (apiFunction) {
|
||||
const signature = this.apiParser.generateFunctionSignature(apiFunction);
|
||||
const isFunctionEx = this.apiParser.isFunctionEx(apiFunction.name);
|
||||
const signature = this.apiParser.generateFunctionSignature(apiFunction, isFunctionEx);
|
||||
let hoverContent = `<span style="color:#4EC9B0;">★</span> <span style="color:#569CD6;">内置函数</span>: <code style="background-color:#2D2D30; color:#D4D4D4;">${signature}</code>\n\n`;
|
||||
hoverContent += `<span style="color:#6A9955;">${apiFunction.description}</span>\n\n`;
|
||||
if (apiFunction.params.length > 0) {
|
||||
|
||||
2
dist/providers/hoverProvider.js.map
vendored
2
dist/providers/hoverProvider.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user