优化格式化功能中的自动换行
This commit is contained in:
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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user