优化格式化功能中的自动换行
This commit is contained in:
113
CLAUDE.md
113
CLAUDE.md
@@ -1,113 +0,0 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
Squirrel NUT Explorer is a VS Code extension for browsing and editing NUT (Squirrel script) files through the pvfUtility API. The extension provides comprehensive language support features including code completion, hover information, definition jumping, function signature help, code formatting, and error detection.
|
||||
|
||||
## Build Commands
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Compile TypeScript
|
||||
npm run compile
|
||||
|
||||
# Watch mode compilation
|
||||
npm run watch
|
||||
|
||||
# Build project
|
||||
npm run build
|
||||
|
||||
# VS Code pre-publish build
|
||||
npm run vscode:prepublish
|
||||
```
|
||||
|
||||
## High-Level Architecture
|
||||
|
||||
### Core Components
|
||||
|
||||
1. **Extension Entry Point** (`src/extension.ts`):
|
||||
- Registers all providers and commands
|
||||
- Initializes core services and manages extension lifecycle
|
||||
|
||||
2. **Data Model** (`src/model.ts`):
|
||||
- `FileModel` class manages file state, content, and API communication
|
||||
- Handles connection to pvfUtility API and file operations
|
||||
- Manages file list and content caching
|
||||
|
||||
3. **Tree View Provider** (`src/provider.ts`):
|
||||
- Implements `vscode.TreeDataProvider` for displaying files in the explorer view
|
||||
- Manages UI representation of files and folders
|
||||
|
||||
4. **File System Provider** (`src/fileSystemProvider.ts`):
|
||||
- Implements `vscode.FileSystemProvider` for virtual file handling
|
||||
- Bridges VS Code file operations with pvfUtility API
|
||||
|
||||
### Language Feature Providers (`src/providers/`)
|
||||
|
||||
1. **Completion Provider** (`src/providers/completionProvider.ts`):
|
||||
- Provides code completion for functions, keywords, constants, and variables
|
||||
- Includes both basic completion and dot notation completion for object methods
|
||||
|
||||
2. **Hover Provider** (`src/providers/hoverProvider.ts`):
|
||||
- Shows detailed information when hovering over code elements
|
||||
- Displays function signatures, descriptions, and parameter details
|
||||
|
||||
3. **Definition Provider** (`src/providers/definitionProvider.ts`):
|
||||
- Enables "Go to Definition" functionality for cross-file function references
|
||||
|
||||
4. **Signature Help Provider** (`src/providers/signatureHelpProvider.ts`):
|
||||
- Shows function parameter information during typing
|
||||
|
||||
5. **Formatting Providers** (`src/providers/onTypeFormattingProvider.ts`, `src/providers/documentFormattingProvider.ts`):
|
||||
- Handle code formatting on type and document formatting
|
||||
|
||||
6. **Code Error Provider** (`src/providers/codeErrorProvider.ts`):
|
||||
- Implements code diagnostics and quick fixes
|
||||
|
||||
### Core Functionality Modules
|
||||
|
||||
1. **Function Extractor** (`src/functionExtractor.ts`):
|
||||
- Parses NUT files to extract function definitions
|
||||
- Manages function caching for performance
|
||||
- Provides cross-file function reference capabilities
|
||||
|
||||
2. **API Client** (`src/apiClient.ts`):
|
||||
- Handles all HTTP communication with pvfUtility API
|
||||
- Manages file listing, content retrieval, and file saving
|
||||
|
||||
3. **API Parser** (`src/providers/apiParser.ts`):
|
||||
- Provides built-in Squirrel language documentation
|
||||
- Manages API functions, classes, and constants information
|
||||
|
||||
## Key Dependencies
|
||||
|
||||
- **VS Code API**: Foundation for extension development
|
||||
- **TypeScript**: Development language
|
||||
- **Node.js HTTP/HTTPS modules**: For API communication (no external HTTP libraries)
|
||||
|
||||
## Configuration Options
|
||||
|
||||
The extension provides these configuration options:
|
||||
|
||||
- `squirrel.api.baseUrl`: pvfUtility API base URL (default: http://localhost)
|
||||
- `squirrel.api.port`: pvfUtility API port (default: 8080)
|
||||
- `squirrel.defaultDirectory`: Default directory to browse (default: sqr)
|
||||
- `squirrel.nutEncoding`: NUT file encoding type (default: UTF8)
|
||||
|
||||
## Development Notes
|
||||
|
||||
1. **Caching Mechanism**: FunctionExtractor uses caching to improve performance. File caches are updated when files are saved.
|
||||
|
||||
2. **Batch Processing**: Files are processed in batches to prevent memory overflow and blocking.
|
||||
|
||||
3. **Error Handling**: All API calls include exception handling to ensure extension stability.
|
||||
|
||||
4. **Chinese Support**: The project primarily uses Chinese for UI and comments, maintaining consistency in code documentation.
|
||||
|
||||
5. **Virtual File System**: The extension uses VS Code's virtual file system API to provide a seamless editing experience for remote files.
|
||||
|
||||
6. **Performance Monitoring**: Function extraction includes performance monitoring to track efficiency.
|
||||
41
dist/utils/beautifyHelper.js
vendored
41
dist/utils/beautifyHelper.js
vendored
@@ -1,8 +1,42 @@
|
||||
"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.getSquirrelBeautifyOptions = getSquirrelBeautifyOptions;
|
||||
exports.beautifyCode = beautifyCode;
|
||||
exports.isSquirrelCode = isSquirrelCode;
|
||||
const vscode = __importStar(require("vscode"));
|
||||
// 由于 js-beautify.js 文件体积较大且复杂,我们将创建专门的存根函数
|
||||
// 将使用原生的 js-beautify 功能
|
||||
let _jsBeauifyInstance = null;
|
||||
@@ -74,7 +108,7 @@ function createBasicJsBeautify() {
|
||||
brace_style: 'collapse',
|
||||
space_before_conditional: true,
|
||||
space_after_anon_function: false,
|
||||
wrap_line_length: 120,
|
||||
wrap_line_length: 0, // 默认禁用自动换行
|
||||
end_with_newline: false
|
||||
};
|
||||
// 合并选项
|
||||
@@ -139,6 +173,9 @@ const jsBeautify = {
|
||||
* Squirrel 语言的 js-beautify 选项配置
|
||||
*/
|
||||
function getSquirrelBeautifyOptions(options) {
|
||||
// 从用户配置中读取换行长度设置
|
||||
const config = vscode.workspace.getConfiguration('squirrel.formatting');
|
||||
const wrapLineLength = config.get('wrapLineLength', 0);
|
||||
return {
|
||||
indent_size: options.tabSize,
|
||||
indent_char: options.insertSpaces ? ' ' : '\t',
|
||||
@@ -149,7 +186,7 @@ function getSquirrelBeautifyOptions(options) {
|
||||
space_before_conditional: true,
|
||||
space_after_anon_function: false,
|
||||
unescape_strings: false,
|
||||
wrap_line_length: 120,
|
||||
wrap_line_length: wrapLineLength,
|
||||
end_with_newline: false
|
||||
};
|
||||
}
|
||||
|
||||
2
dist/utils/beautifyHelper.js.map
vendored
2
dist/utils/beautifyHelper.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
||||
"name": "squirrel-nut-explorer",
|
||||
"displayName": "Squirrel NUT Explorer",
|
||||
"description": "通过 pvfUtility API 浏览和编辑 NUT 文件",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.4",
|
||||
"publisher": "local",
|
||||
"engines": {
|
||||
"vscode": "^1.99.0"
|
||||
@@ -132,6 +132,13 @@
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "是否在编辑时自动格式化代码"
|
||||
},
|
||||
"squirrel.formatting.wrapLineLength": {
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
"description": "代码格式化时的最大行长度,超过此长度会自动换行。设置为 0 表示禁用自动换行",
|
||||
"minimum": 0,
|
||||
"maximum": 500
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -78,7 +78,7 @@ function createBasicJsBeautify(): any {
|
||||
brace_style: 'collapse',
|
||||
space_before_conditional: true,
|
||||
space_after_anon_function: false,
|
||||
wrap_line_length: 120,
|
||||
wrap_line_length: 0, // 默认禁用自动换行
|
||||
end_with_newline: false
|
||||
};
|
||||
|
||||
@@ -158,6 +158,10 @@ const jsBeautify = {
|
||||
* Squirrel 语言的 js-beautify 选项配置
|
||||
*/
|
||||
export function getSquirrelBeautifyOptions(options: vscode.FormattingOptions): any {
|
||||
// 从用户配置中读取换行长度设置
|
||||
const config = vscode.workspace.getConfiguration('squirrel.formatting');
|
||||
const wrapLineLength = config.get<number>('wrapLineLength', 0);
|
||||
|
||||
return {
|
||||
indent_size: options.tabSize,
|
||||
indent_char: options.insertSpaces ? ' ' : '\t',
|
||||
@@ -168,7 +172,7 @@ export function getSquirrelBeautifyOptions(options: vscode.FormattingOptions): a
|
||||
space_before_conditional: true,
|
||||
space_after_anon_function: false,
|
||||
unescape_strings: false,
|
||||
wrap_line_length: 120,
|
||||
wrap_line_length: wrapLineLength,
|
||||
end_with_newline: false
|
||||
};
|
||||
}
|
||||
|
||||
41
客户端.cpp
41
客户端.cpp
@@ -1,41 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
277
新库函数示范.json
277
新库函数示范.json
@@ -1,277 +0,0 @@
|
||||
{
|
||||
"functions": [
|
||||
{
|
||||
"name": "file",
|
||||
"description": "",
|
||||
"params": [],
|
||||
"returns": {
|
||||
"type": "void",
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "close",
|
||||
"description": "关闭文件流",
|
||||
"params": [],
|
||||
"returns": {
|
||||
"type": "void",
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "len",
|
||||
"description": "获取数据长度",
|
||||
"params": [
|
||||
{
|
||||
"name": "data",
|
||||
"type": "object",
|
||||
"description": "基本数据类型"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "int",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"functionEx": [
|
||||
{
|
||||
"name": "sq_RGB",
|
||||
"description": "颜色空间",
|
||||
"params": [
|
||||
{
|
||||
"name": "R",
|
||||
"type": "int",
|
||||
"description": "红色(0-255)"
|
||||
},
|
||||
{
|
||||
"name": "G",
|
||||
"type": "int",
|
||||
"description": "绿色(0-255)"
|
||||
},
|
||||
{
|
||||
"name": "B",
|
||||
"type": "int",
|
||||
"description": "蓝色(0-255)"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "object",
|
||||
"description": "颜色对象"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sq_RGBA",
|
||||
"description": "颜色空间",
|
||||
"params": [
|
||||
{
|
||||
"name": "R",
|
||||
"type": "int",
|
||||
"description": "红色(0-255)"
|
||||
},
|
||||
{
|
||||
"name": "G",
|
||||
"type": "int",
|
||||
"description": "绿色(0-255)"
|
||||
},
|
||||
{
|
||||
"name": "B",
|
||||
"type": "int",
|
||||
"description": "蓝色(0-255)"
|
||||
},
|
||||
{
|
||||
"name": "A",
|
||||
"type": "int",
|
||||
"description": "透明度(0-255)"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "object",
|
||||
"description": "颜色对象"
|
||||
}
|
||||
}
|
||||
],
|
||||
"classes": [
|
||||
{
|
||||
"name": "String",
|
||||
"description": "字符串类,提供字符串操作方法",
|
||||
"methods": [
|
||||
{
|
||||
"name": "len",
|
||||
"description": "返回字符串长度",
|
||||
"params": [],
|
||||
"returns": {
|
||||
"type": "integer",
|
||||
"description": "字符串的长度"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "slice",
|
||||
"description": "返回字符串的子串",
|
||||
"params": [
|
||||
{
|
||||
"name": "start",
|
||||
"type": "integer",
|
||||
"description": "起始位置"
|
||||
},
|
||||
{
|
||||
"name": "end",
|
||||
"type": "integer",
|
||||
"description": "结束位置(可选)",
|
||||
"optional": true
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "string",
|
||||
"description": "子串"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "find",
|
||||
"description": "查找子串在字符串中的位置",
|
||||
"params": [
|
||||
{
|
||||
"name": "substr",
|
||||
"type": "string",
|
||||
"description": "要查找的子串"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "integer",
|
||||
"description": "子串的位置,未找到返回-1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "length",
|
||||
"type": "integer",
|
||||
"description": "字符串的长度"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Array",
|
||||
"description": "数组类,提供数组操作方法",
|
||||
"methods": [
|
||||
{
|
||||
"name": "len",
|
||||
"description": "返回数组长度",
|
||||
"params": [],
|
||||
"returns": {
|
||||
"type": "integer",
|
||||
"description": "数组的长度"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "append",
|
||||
"description": "向数组末尾添加元素",
|
||||
"params": [
|
||||
{
|
||||
"name": "value",
|
||||
"type": "any",
|
||||
"description": "要添加的元素"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "void",
|
||||
"description": "无返回值"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "pop",
|
||||
"description": "移除并返回数组最后一个元素",
|
||||
"params": [],
|
||||
"returns": {
|
||||
"type": "any",
|
||||
"description": "被移除的元素"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "length",
|
||||
"type": "integer",
|
||||
"description": "数组的长度"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Table",
|
||||
"description": "表类,提供表操作方法",
|
||||
"methods": [
|
||||
{
|
||||
"name": "len",
|
||||
"description": "返回表中键值对的数量",
|
||||
"params": [],
|
||||
"returns": {
|
||||
"type": "integer",
|
||||
"description": "键值对的数量"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "rawget",
|
||||
"description": "获取指定键的值",
|
||||
"params": [
|
||||
{
|
||||
"name": "key",
|
||||
"type": "any",
|
||||
"description": "键"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "any",
|
||||
"description": "键对应的值"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "rawset",
|
||||
"description": "设置指定键的值",
|
||||
"params": [
|
||||
{
|
||||
"name": "key",
|
||||
"type": "any",
|
||||
"description": "键"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "any",
|
||||
"description": "值"
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "void",
|
||||
"description": "无返回值"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": []
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"name": "PI",
|
||||
"value": "3.14159",
|
||||
"description": "圆周率",
|
||||
"category": "math"
|
||||
},
|
||||
{
|
||||
"name": "true",
|
||||
"value": "true",
|
||||
"description": "布尔真值",
|
||||
"category": "boolean"
|
||||
},
|
||||
{
|
||||
"name": "false",
|
||||
"value": "false",
|
||||
"description": "布尔假值",
|
||||
"category": "boolean"
|
||||
},
|
||||
{
|
||||
"name": "null",
|
||||
"value": "null",
|
||||
"description": "空值",
|
||||
"category": "general"
|
||||
}
|
||||
]
|
||||
}
|
||||
71
第三方API.md
71
第三方API.md
@@ -1,71 +0,0 @@
|
||||
pvfUtility WebApi
|
||||
介绍
|
||||
pvfUtility 2020开始 一项重大的更新就是提供了HTTP接口进行自动化操作
|
||||
|
||||
这使得第三方工具可以利用http rest api进行文件读写
|
||||
|
||||
只需在软件内打开pvf,就能通过第三方工具进行下一步的操作
|
||||
|
||||
|
||||
获取pvfUtility版本号
|
||||
插件作者可以以版本来来确定用户当前使用的pvfUtility是否适用某些API接口
|
||||
请求类型:GET
|
||||
http://localhost:/Api/PvfUtiltiy/getVersion
|
||||
返回结果
|
||||
//注:使用此接口pvfUtility版本号需大于2022.9.30.2
|
||||
{"Data":"2022.9.30.3","IsError":false,"Msg":null}
|
||||
|
||||
|
||||
获取nut文件列表
|
||||
请求类型:GET
|
||||
http://localhost:/Api/PvfUtiltiy/GetFileList?dirName=sqr&returnType=0&fileType=nut
|
||||
解释:dirName=equipment(目录名称)
|
||||
fileType=.equ(文件后缀名) 注:使用fileType pvfUtility版本号必须大于:2022.08.08.2
|
||||
|
||||
返回结果示例(returnType=1)
|
||||
{
|
||||
"Data": [
|
||||
"sqr/arad_cashshop.nut",
|
||||
"sqr/hair_avagacha.nut",
|
||||
"sqr/neck_avagacha.nut",
|
||||
"sqr/belt_avagacha.nut"
|
||||
],
|
||||
"IsError": false,
|
||||
"Msg": null
|
||||
}
|
||||
|
||||
|
||||
批量获取nut文件内容
|
||||
请求类型:POST
|
||||
http://localhost:/Api/PvfUtiltiy/GetFileContents
|
||||
请求参数
|
||||
{"FileList":["sqr/arad_cashshop.nut","sqr/neck_avagacha.nut"],"UseCompatibleDecompiler":false,"EncodingType":Null}
|
||||
|
||||
解释
|
||||
UseCompatibleDecompiler=是否使用兼容性反编译器
|
||||
注:使用encodingType参数 pvfUtility版本号需大于2022.12.3.1,
|
||||
//encodingType:仅适用于文本文件,默认使用UTF8
|
||||
//TW=中国台湾
|
||||
//CN=中国大陆
|
||||
//KR=韩国
|
||||
//JP=日本
|
||||
//UTF8
|
||||
//Unicode
|
||||
|
||||
|
||||
返回结果示例(注:文件内容为utf-8编码)
|
||||
{
|
||||
{"Data":{"FileContentData":{"sqr/arad_cashshop.nut":"\r\nlocal a = 0;\r\n","sqr/neck_avagacha.nut":"\r\nlocal b = 1;\r\n"}},"IsError":false,"Msg":null}
|
||||
|
||||
|
||||
上传新的文件内容
|
||||
新增或覆盖文件内容
|
||||
|
||||
请求类型:POST
|
||||
http://localhost:/Api/PvfUtiltiy/ImportFile?filePath=[文件路径]
|
||||
请求参数(文本内容):
|
||||
文件内容
|
||||
|
||||
返回结果
|
||||
{"IsError":false,"Msg":null}
|
||||
|
||||
Reference in New Issue
Block a user