🚚 Refactor directory structure
This commit is contained in:
105
frontend/src/common/prettier/plugins/clang/src/CMakeLists.txt
Normal file
105
frontend/src/common/prettier/plugins/clang/src/CMakeLists.txt
Normal file
@@ -0,0 +1,105 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(clang-format-wasm)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Set Emscripten flags for WASM
|
||||
if(EMSCRIPTEN)
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".js")
|
||||
|
||||
# Common Emscripten flags
|
||||
set(EMSCRIPTEN_FLAGS
|
||||
-O3
|
||||
-sWASM=1
|
||||
-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap']
|
||||
-sALLOW_MEMORY_GROWTH=1
|
||||
-sMODULARIZE=1
|
||||
-sEXPORT_NAME='Module'
|
||||
-sENVIRONMENT=web,webview,worker
|
||||
-sUSE_ES6_IMPORT_META=0
|
||||
--no-entry
|
||||
)
|
||||
|
||||
# Library-specific flags
|
||||
set(LIB_EMSCRIPTEN_FLAGS
|
||||
${EMSCRIPTEN_FLAGS}
|
||||
-sEXPORTED_FUNCTIONS=['_malloc','_free']
|
||||
--bind
|
||||
)
|
||||
|
||||
# CLI-specific flags
|
||||
set(CLI_EMSCRIPTEN_FLAGS
|
||||
${EMSCRIPTEN_FLAGS}
|
||||
-sEXPORTED_FUNCTIONS=['_main']
|
||||
-sINVOKE_RUN=0
|
||||
-sNODERAWFS=1
|
||||
)
|
||||
endif()
|
||||
|
||||
# Find LLVM
|
||||
find_package(LLVM REQUIRED CONFIG)
|
||||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
|
||||
|
||||
# Include LLVM headers
|
||||
include_directories(${LLVM_INCLUDE_DIRS})
|
||||
add_definitions(${LLVM_DEFINITIONS})
|
||||
|
||||
# Find Clang
|
||||
find_package(Clang REQUIRED CONFIG)
|
||||
|
||||
# Get LLVM components
|
||||
llvm_map_components_to_libnames(llvm_libs support core)
|
||||
|
||||
# Define source files
|
||||
set(LIB_SOURCES
|
||||
lib.cc
|
||||
lib.h
|
||||
binding.cc
|
||||
)
|
||||
|
||||
set(CLI_SOURCES
|
||||
cli.cc
|
||||
)
|
||||
|
||||
# Create library target
|
||||
add_executable(clang-format-wasm ${LIB_SOURCES})
|
||||
|
||||
# Link against Clang and LLVM libraries
|
||||
target_link_libraries(clang-format-wasm
|
||||
clangFormat
|
||||
clangToolingCore
|
||||
clangBasic
|
||||
clangRewrite
|
||||
${llvm_libs}
|
||||
)
|
||||
|
||||
# Create CLI target
|
||||
add_executable(clang-format-cli ${CLI_SOURCES})
|
||||
|
||||
target_link_libraries(clang-format-cli
|
||||
clangFormat
|
||||
clangToolingCore
|
||||
clangBasic
|
||||
clangRewrite
|
||||
${llvm_libs}
|
||||
)
|
||||
|
||||
# Set Emscripten flags
|
||||
if(EMSCRIPTEN)
|
||||
# Configure library target
|
||||
set_target_properties(clang-format-wasm PROPERTIES
|
||||
COMPILE_FLAGS "${LIB_EMSCRIPTEN_FLAGS}"
|
||||
LINK_FLAGS "${LIB_EMSCRIPTEN_FLAGS}"
|
||||
OUTPUT_NAME "clang-format-esm"
|
||||
)
|
||||
|
||||
# Configure CLI target
|
||||
set_target_properties(clang-format-cli PROPERTIES
|
||||
COMPILE_FLAGS "${CLI_EMSCRIPTEN_FLAGS}"
|
||||
LINK_FLAGS "${CLI_EMSCRIPTEN_FLAGS}"
|
||||
OUTPUT_NAME "clang-format-cli"
|
||||
)
|
||||
endif()
|
||||
100
frontend/src/common/prettier/plugins/clang/src/README.md
Normal file
100
frontend/src/common/prettier/plugins/clang/src/README.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# Clang Format WASM Plugin
|
||||
|
||||
这是一个基于 clang-format WebAssembly 的 Prettier 插件,支持格式化 C/C++/C#/Java/Protobuf 代码。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
clang/
|
||||
├── src/ # 源码目录
|
||||
│ ├── scripts/ # 构建和工具脚本
|
||||
│ │ ├── build.sh # 主构建脚本
|
||||
│ │ ├── gen_patch.sh # 补丁生成脚本
|
||||
│ │ └── cli.patch # CLI 修改补丁
|
||||
│ ├── *.cc # C++ 源文件
|
||||
│ ├── *.h # C++ 头文件
|
||||
│ ├── CMakeLists.txt # CMake 构建配置
|
||||
│ ├── package.json # NPM 包配置
|
||||
│ ├── clang-format.d.ts # TypeScript 类型定义
|
||||
│ ├── template.js # JavaScript 模板
|
||||
│ └── clang-format-diff.py # Python 差异工具
|
||||
├── *.js # 编译后的 JavaScript 文件
|
||||
├── *.wasm # 编译后的 WebAssembly 文件
|
||||
├── *.cjs # CommonJS 格式的 CLI 工具
|
||||
├── git-clang-format # Git 集成工具
|
||||
└── index.ts # 插件入口文件
|
||||
```
|
||||
|
||||
## 构建说明
|
||||
|
||||
### 前提条件
|
||||
|
||||
- Install LLVM and Clang (version 18 or later)
|
||||
- Install CMake (version 3.27 or later)
|
||||
- Install Ninja (version 1.11 or later)
|
||||
|
||||
### 构建步骤
|
||||
|
||||
1. Clone this repository
|
||||
|
||||
2. 进入源码目录:
|
||||
```bash
|
||||
cd src
|
||||
```
|
||||
|
||||
3. 运行构建脚本:
|
||||
```bash
|
||||
./scripts/build.sh
|
||||
```
|
||||
|
||||
构建脚本会:
|
||||
- 创建 `build` 目录并编译源码
|
||||
- 将编译结果复制到上级目录(插件目录)
|
||||
- 生成 WebAssembly 文件和 JavaScript 绑定
|
||||
- 复制必要的工具和类型定义文件
|
||||
|
||||
### 输出文件
|
||||
|
||||
构建完成后,插件目录下会包含:
|
||||
- `clang-format.wasm` - WebAssembly 库文件
|
||||
- `clang-format.js` - JavaScript 绑定文件
|
||||
- `clang-format-cli.cjs` - CLI 工具
|
||||
- `clang-format-cli.wasm` - CLI WebAssembly 文件
|
||||
- `git-clang-format` - Git 集成工具
|
||||
- `clang-format-diff.py` - 差异工具
|
||||
|
||||
## 开发说明
|
||||
|
||||
### 修改源码
|
||||
|
||||
- C++ 源文件位于 `src/` 目录下
|
||||
- 修改后运行 `./scripts/build.sh` 重新构建
|
||||
- 类型定义文件 `src/clang-format.d.ts` 需要与实际 API 保持同步
|
||||
|
||||
### 生成补丁
|
||||
|
||||
如果修改了 CLI 相关代码,可以使用:
|
||||
```bash
|
||||
./scripts/gen_patch.sh
|
||||
```
|
||||
|
||||
生成补丁文件 `scripts/cli.patch`。
|
||||
|
||||
## 使用说明
|
||||
|
||||
插件会自动加载编译后的 WebAssembly 文件,支持以下语言:
|
||||
- C/C++
|
||||
- Objective-C/C++
|
||||
- C#
|
||||
- Java
|
||||
- Protocol Buffer
|
||||
|
||||
支持的 clang-format 样式:
|
||||
- LLVM
|
||||
- Google
|
||||
- Chromium
|
||||
- Mozilla
|
||||
- WebKit
|
||||
- Microsoft
|
||||
- GNU
|
||||
- 自定义样式
|
||||
@@ -38,7 +38,5 @@ cp ./build/_deps/llvm_project-src/clang/tools/clang-format/clang-format-diff.py
|
||||
|
||||
ls -lh ./pkg
|
||||
|
||||
./scripts/package.mjs ./package.json
|
||||
|
||||
# make sure repo is clean
|
||||
# git diff --exit-code
|
||||
# git diff --exit-code
|
||||
@@ -24,4 +24,3 @@ git diff \
|
||||
|
||||
rm -rf $tmp_dir
|
||||
|
||||
|
||||
Binary file not shown.
@@ -27,7 +27,7 @@ function initialize() {
|
||||
const go = new TinyGo();
|
||||
|
||||
// Load WASM file from browser
|
||||
const response = await fetch('/go-format.wasm');
|
||||
const response = await fetch('./go-format.wasm');
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load WASM file: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
@@ -28,15 +28,4 @@ if errorlevel 1 (
|
||||
|
||||
echo Build successful!
|
||||
|
||||
rem Show file size (Windows version)
|
||||
for %%A in (go.wasm) do echo WASM file size: %%~zA bytes
|
||||
|
||||
rem Copy to public directory for browser access
|
||||
if exist "..\..\..\..\..\public" (
|
||||
copy go.wasm ..\..\..\..\..\public\go.wasm > nul
|
||||
echo Copied to public directory
|
||||
del go.wasm
|
||||
echo Cleaned up local WASM file
|
||||
)
|
||||
|
||||
echo Go Prettier Plugin WASM (TinyGo) is ready!
|
||||
@@ -25,14 +25,5 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
echo "Build successful!"
|
||||
echo "WASM file size: $(du -h go-format.wasm | cut -f1)"
|
||||
|
||||
# Copy to public directory for browser access
|
||||
if [ -d "../../../../../public" ]; then
|
||||
cp go-format.wasm ../../../../../public/go-format.wasm
|
||||
echo "Copied to public directory"
|
||||
rm go-format.wasm
|
||||
echo "Cleaned up local WASM file"
|
||||
fi
|
||||
|
||||
echo "Go Prettier Plugin WASM (TinyGo) is ready!"
|
||||
@@ -23,18 +23,7 @@ go build -o go-format.wasm main.go
|
||||
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo Build successful!
|
||||
|
||||
rem Show file size (Windows version)
|
||||
for %%A in (go.wasm) do echo WASM file size: %%~zA bytes
|
||||
|
||||
rem Copy to public directory for browser access
|
||||
if exist "..\..\..\..\..\public" (
|
||||
copy go.wasm ..\..\..\..\..\public\go.wasm > nul
|
||||
echo Copied to public directory
|
||||
del go.wasm
|
||||
echo Cleaned up local WASM file
|
||||
)
|
||||
|
||||
|
||||
echo Go Prettier Plugin WASM is ready!
|
||||
) else (
|
||||
echo Build failed!
|
||||
@@ -25,16 +25,7 @@ go build -o go-format.wasm main.go
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Build successful!"
|
||||
echo "WASM file size: $(du -h go-format.wasm | cut -f1)"
|
||||
|
||||
# Copy to public directory for browser access
|
||||
if [ -d "../../../../../public" ]; then
|
||||
cp go-format.wasm ../../../../../public/go-format.wasm
|
||||
echo "Copied to public directory"
|
||||
rm go-format.wasm
|
||||
echo "Cleaned up local WASM file"
|
||||
fi
|
||||
|
||||
|
||||
echo "Go Prettier Plugin WASM is ready!"
|
||||
else
|
||||
echo "Build failed!"
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "lua_fmt"
|
||||
name = "lua"
|
||||
|
||||
authors.workspace = true
|
||||
description.workspace = true
|
||||
@@ -1,6 +1,5 @@
|
||||
cd $(dirname $0)/..
|
||||
crates_dir=$(pwd)
|
||||
cd $(dirname $0)
|
||||
project_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt crates/lua_fmt
|
||||
wasm-pack build --target=web --scope=wasm-fmt .
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
*.tgz
|
||||
jsr.jsonc
|
||||
@@ -1,12 +0,0 @@
|
||||
cd $(dirname $0)/..
|
||||
crates_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt crates/ruff_fmt
|
||||
cp README.md crates/ruff_fmt/pkg/
|
||||
|
||||
cd $crates_dir
|
||||
|
||||
cp -R ./extra/. ./pkg/
|
||||
|
||||
./scripts/package.mjs ./pkg/package.json
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import process from "node:process";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
const pkg_path = path.resolve(process.cwd(), process.argv[2]);
|
||||
const pkg_text = fs.readFileSync(pkg_path, { encoding: "utf-8" });
|
||||
const pkg_json = JSON.parse(pkg_text);
|
||||
|
||||
delete pkg_json.files;
|
||||
|
||||
pkg_json.main = pkg_json.module;
|
||||
pkg_json.type = "module";
|
||||
pkg_json.publishConfig = {
|
||||
access: "public",
|
||||
};
|
||||
pkg_json.exports = {
|
||||
".": {
|
||||
types: "./ruff_fmt.d.ts",
|
||||
node: "./ruff_fmt_node.js",
|
||||
default: "./ruff_fmt.js",
|
||||
},
|
||||
"./vite": {
|
||||
types: "./ruff_fmt.d.ts",
|
||||
default: "./ruff_fmt_vite.js",
|
||||
},
|
||||
"./package.json": "./package.json",
|
||||
"./*": "./*",
|
||||
};
|
||||
|
||||
fs.writeFileSync(pkg_path, JSON.stringify(pkg_json, null, 4));
|
||||
|
||||
// JSR
|
||||
|
||||
const jsr_path = path.resolve(pkg_path, "..", "jsr.jsonc");
|
||||
pkg_json.name = "@fmt/ruff-fmt";
|
||||
pkg_json.exports = "./ruff_fmt.js";
|
||||
pkg_json.exclude = ["!**", "*.tgz"];
|
||||
fs.writeFileSync(jsr_path, JSON.stringify(pkg_json, null, 4));
|
||||
@@ -0,0 +1,9 @@
|
||||
cd $(dirname $0)/..
|
||||
project_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt ruff_fmt
|
||||
|
||||
cd $project_dir
|
||||
|
||||
cp -R ./extra/. ./pkg/
|
||||
@@ -253,7 +253,7 @@ export const plugin: Plugin<Node> = {
|
||||
{
|
||||
name: "Rust",
|
||||
aliases: ["rs"],
|
||||
parsers: ["jinx-rust"],
|
||||
parsers: ["rust"],
|
||||
extensions: [".rs", ".rs.in"],
|
||||
linguistLanguageId: 327,
|
||||
vscodeLanguageIds: ["rust"],
|
||||
@@ -264,8 +264,8 @@ export const plugin: Plugin<Node> = {
|
||||
},
|
||||
],
|
||||
parsers: {
|
||||
"jinx-rust": {
|
||||
astFormat: "jinx-rust",
|
||||
"rust": {
|
||||
astFormat: "rust",
|
||||
locStart: start,
|
||||
locEnd: end,
|
||||
parse(code: string, options: ParserOptions<Node> & Partial<CustomOptions>) {
|
||||
@@ -294,7 +294,7 @@ export const plugin: Plugin<Node> = {
|
||||
},
|
||||
},
|
||||
printers: {
|
||||
"jinx-rust": {
|
||||
"rust": {
|
||||
preprocess: (node: Node) => (node as Program).loc?.src || node,
|
||||
print(path, options, print, args) {
|
||||
if (path.stack.length === 1) {
|
||||
|
||||
119
frontend/src/common/prettier/plugins/rust_fmt/index.ts
Normal file
119
frontend/src/common/prettier/plugins/rust_fmt/index.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Prettier Plugin for Rust formatting using rust_fmt WebAssembly
|
||||
*
|
||||
* This plugin provides support for formatting Rust files using the rust_fmt WASM implementation.
|
||||
*/
|
||||
import type { Plugin, Parser, Printer } from 'prettier';
|
||||
|
||||
// Import the rust_fmt WASM module
|
||||
import rustFmtInit, { format, type Config } from './rust_fmt_vite.js';
|
||||
|
||||
const parserName = 'rust';
|
||||
|
||||
// Language configuration
|
||||
const languages = [
|
||||
{
|
||||
name: 'Rust',
|
||||
aliases: ['rust', 'rs'],
|
||||
parsers: [parserName],
|
||||
extensions: ['.rs', '.rs.in'],
|
||||
aceMode: 'rust',
|
||||
tmScope: 'source.rust',
|
||||
linguistLanguageId: 327,
|
||||
vscodeLanguageIds: ['rust']
|
||||
}
|
||||
];
|
||||
|
||||
// Parser configuration
|
||||
const rustParser: Parser<string> = {
|
||||
astFormat: parserName,
|
||||
parse: (text: string) => text,
|
||||
locStart: () => 0,
|
||||
locEnd: (node: string) => node.length,
|
||||
};
|
||||
|
||||
// Initialize rust_fmt WASM module
|
||||
let initPromise: Promise<void> | null = null;
|
||||
let isInitialized = false;
|
||||
|
||||
function initRustFmt(): Promise<void> {
|
||||
if (initPromise) {
|
||||
return initPromise;
|
||||
}
|
||||
|
||||
initPromise = (async () => {
|
||||
if (!isInitialized) {
|
||||
await rustFmtInit();
|
||||
isInitialized = true;
|
||||
}
|
||||
})();
|
||||
|
||||
return initPromise;
|
||||
}
|
||||
|
||||
// Printer configuration
|
||||
const rustPrinter: Printer<string> = {
|
||||
print: (path, options) => {
|
||||
try {
|
||||
if (!isInitialized) {
|
||||
console.warn('rust_fmt WASM module not initialized, returning original text');
|
||||
return (path as any).getValue ? (path as any).getValue() : path.node;
|
||||
}
|
||||
|
||||
const text = (path as any).getValue ? (path as any).getValue() : path.node;
|
||||
const config = getRustFmtConfig(options);
|
||||
|
||||
// Format using rust_fmt (synchronous call)
|
||||
const formatted = format(text, config);
|
||||
|
||||
return formatted.trim();
|
||||
} catch (error) {
|
||||
console.warn('Rust formatting failed:', error);
|
||||
// Return original text if formatting fails
|
||||
return (path as any).getValue ? (path as any).getValue() : path.node;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Helper function to create rust_fmt config from Prettier options
|
||||
function getRustFmtConfig(options: any): Config {
|
||||
const config: Config = {};
|
||||
|
||||
// Map Prettier options to rust_fmt config
|
||||
if (options.useTabs !== undefined) {
|
||||
config.use_tabs = options.useTabs;
|
||||
}
|
||||
|
||||
// Note: rust_fmt currently only supports use_tabs option
|
||||
// Future versions may support more options like tab_width
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
// Plugin options
|
||||
const options = {
|
||||
// Currently rust_fmt only supports use_tabs option
|
||||
// The tab width and other formatting options are handled by prettyplease internally
|
||||
};
|
||||
|
||||
// Plugin definition
|
||||
const rustPlugin: Plugin = {
|
||||
languages,
|
||||
parsers: {
|
||||
[parserName]: rustParser,
|
||||
},
|
||||
printers: {
|
||||
[parserName]: rustPrinter,
|
||||
},
|
||||
options,
|
||||
};
|
||||
|
||||
// Initialize the WASM module
|
||||
initRustFmt().catch(error => {
|
||||
console.error('Failed to initialize rust_fmt WASM module:', error);
|
||||
});
|
||||
|
||||
export default rustPlugin;
|
||||
export { languages };
|
||||
export const parsers = rustPlugin.parsers;
|
||||
export const printers = rustPlugin.printers;
|
||||
45
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt.d.ts
vendored
Normal file
45
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt.d.ts
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export function format(input: string, config?: Config | null): string;
|
||||
|
||||
export interface Config {
|
||||
/**
|
||||
* When set to true, uses tabs for indentation instead of spaces
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
use_tabs?: boolean;
|
||||
}
|
||||
|
||||
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
export interface InitOutput {
|
||||
readonly memory: WebAssembly.Memory;
|
||||
readonly format: (a: number, b: number, c: number, d: number) => void;
|
||||
readonly __wbindgen_export_0: (a: number, b: number) => number;
|
||||
readonly __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
|
||||
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
readonly __wbindgen_export_2: (a: number, b: number, c: number) => void;
|
||||
}
|
||||
|
||||
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
||||
/**
|
||||
* Instantiates the given `module`, which can either be bytes or
|
||||
* a precompiled `WebAssembly.Module`.
|
||||
*
|
||||
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {InitOutput}
|
||||
*/
|
||||
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
||||
|
||||
/**
|
||||
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
||||
*
|
||||
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {Promise<InitOutput>}
|
||||
*/
|
||||
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
||||
447
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt.js
Normal file
447
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt.js
Normal file
@@ -0,0 +1,447 @@
|
||||
let wasm;
|
||||
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
|
||||
let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
||||
|
||||
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
||||
|
||||
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
||||
let numBytesDecoded = 0;
|
||||
function decodeText(ptr, len) {
|
||||
numBytesDecoded += len;
|
||||
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
||||
cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
||||
cachedTextDecoder.decode();
|
||||
numBytesDecoded = len;
|
||||
}
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return decodeText(ptr, len);
|
||||
}
|
||||
|
||||
const heap = new Array(128).fill(undefined);
|
||||
|
||||
heap.push(undefined, null, true, false);
|
||||
|
||||
let heap_next = heap.length;
|
||||
|
||||
function addHeapObject(obj) {
|
||||
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||
const idx = heap_next;
|
||||
heap_next = heap[idx];
|
||||
|
||||
heap[idx] = obj;
|
||||
return idx;
|
||||
}
|
||||
|
||||
function getObject(idx) { return heap[idx]; }
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
||||
|
||||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
||||
? function (arg, view) {
|
||||
return cachedTextEncoder.encodeInto(arg, view);
|
||||
}
|
||||
: function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
});
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8ArrayMemory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = encodeString(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let cachedDataViewMemory0 = null;
|
||||
|
||||
function getDataViewMemory0() {
|
||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
||||
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
||||
}
|
||||
return cachedDataViewMemory0;
|
||||
}
|
||||
|
||||
function getArrayU8FromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
||||
}
|
||||
|
||||
function isLikeNone(x) {
|
||||
return x === undefined || x === null;
|
||||
}
|
||||
|
||||
function debugString(val) {
|
||||
// primitive types
|
||||
const type = typeof val;
|
||||
if (type == 'number' || type == 'boolean' || val == null) {
|
||||
return `${val}`;
|
||||
}
|
||||
if (type == 'string') {
|
||||
return `"${val}"`;
|
||||
}
|
||||
if (type == 'symbol') {
|
||||
const description = val.description;
|
||||
if (description == null) {
|
||||
return 'Symbol';
|
||||
} else {
|
||||
return `Symbol(${description})`;
|
||||
}
|
||||
}
|
||||
if (type == 'function') {
|
||||
const name = val.name;
|
||||
if (typeof name == 'string' && name.length > 0) {
|
||||
return `Function(${name})`;
|
||||
} else {
|
||||
return 'Function';
|
||||
}
|
||||
}
|
||||
// objects
|
||||
if (Array.isArray(val)) {
|
||||
const length = val.length;
|
||||
let debug = '[';
|
||||
if (length > 0) {
|
||||
debug += debugString(val[0]);
|
||||
}
|
||||
for(let i = 1; i < length; i++) {
|
||||
debug += ', ' + debugString(val[i]);
|
||||
}
|
||||
debug += ']';
|
||||
return debug;
|
||||
}
|
||||
// Test for built-in
|
||||
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
||||
let className;
|
||||
if (builtInMatches && builtInMatches.length > 1) {
|
||||
className = builtInMatches[1];
|
||||
} else {
|
||||
// Failed to match the standard '[object ClassName]'
|
||||
return toString.call(val);
|
||||
}
|
||||
if (className == 'Object') {
|
||||
// we're a user defined class or Object
|
||||
// JSON.stringify avoids problems with cycles, and is generally much
|
||||
// easier than looping through ownProperties of `val`.
|
||||
try {
|
||||
return 'Object(' + JSON.stringify(val) + ')';
|
||||
} catch (_) {
|
||||
return 'Object';
|
||||
}
|
||||
}
|
||||
// errors
|
||||
if (val instanceof Error) {
|
||||
return `${val.name}: ${val.message}\n${val.stack}`;
|
||||
}
|
||||
// TODO we could test for more things here, like `Set`s and `Map`s.
|
||||
return className;
|
||||
}
|
||||
|
||||
function dropObject(idx) {
|
||||
if (idx < 132) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Config | null} [config]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function format(input, config) {
|
||||
let deferred3_0;
|
||||
let deferred3_1;
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.format(retptr, ptr0, len0, isLikeNone(config) ? 0 : addHeapObject(config));
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
||||
var ptr2 = r0;
|
||||
var len2 = r1;
|
||||
if (r3) {
|
||||
ptr2 = 0; len2 = 0;
|
||||
throw takeObject(r2);
|
||||
}
|
||||
deferred3_0 = ptr2;
|
||||
deferred3_1 = len2;
|
||||
return getStringFromWasm0(ptr2, len2);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
if (typeof Response === 'function' && module instanceof Response) {
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
return await WebAssembly.instantiateStreaming(module, imports);
|
||||
|
||||
} catch (e) {
|
||||
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
||||
|
||||
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bytes = await module.arrayBuffer();
|
||||
return await WebAssembly.instantiate(bytes, imports);
|
||||
|
||||
} else {
|
||||
const instance = await WebAssembly.instantiate(module, imports);
|
||||
|
||||
if (instance instanceof WebAssembly.Instance) {
|
||||
return { instance, module };
|
||||
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function __wbg_get_imports() {
|
||||
const imports = {};
|
||||
imports.wbg = {};
|
||||
imports.wbg.__wbg_Error_1f3748b298f99708 = function(arg0, arg1) {
|
||||
const ret = Error(getStringFromWasm0(arg0, arg1));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
||||
const ret = String(getObject(arg1));
|
||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
||||
};
|
||||
imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
|
||||
const ret = getObject(arg0)[getObject(arg1)];
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbg_instanceof_ArrayBuffer_59339a3a6f0c10ea = function(arg0) {
|
||||
let result;
|
||||
try {
|
||||
result = getObject(arg0) instanceof ArrayBuffer;
|
||||
} catch (_) {
|
||||
result = false;
|
||||
}
|
||||
const ret = result;
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_instanceof_Uint8Array_91f3c5adee7e6672 = function(arg0) {
|
||||
let result;
|
||||
try {
|
||||
result = getObject(arg0) instanceof Uint8Array;
|
||||
} catch (_) {
|
||||
result = false;
|
||||
}
|
||||
const ret = result;
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_length_904c0910ed998bf3 = function(arg0) {
|
||||
const ret = getObject(arg0).length;
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_new_9190433fb67ed635 = function(arg0) {
|
||||
const ret = new Uint8Array(getObject(arg0));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbg_prototypesetcall_c5f74efd31aea86b = function(arg0, arg1, arg2) {
|
||||
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenbooleanget_59f830b1a70d2530 = function(arg0) {
|
||||
const v = getObject(arg0);
|
||||
const ret = typeof(v) === 'boolean' ? v : undefined;
|
||||
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
||||
};
|
||||
imports.wbg.__wbg_wbindgendebugstring_bb652b1bc2061b6d = function(arg0, arg1) {
|
||||
const ret = debugString(getObject(arg1));
|
||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenin_192b210aa1c401e9 = function(arg0, arg1) {
|
||||
const ret = getObject(arg0) in getObject(arg1);
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenisobject_dfe064a121d87553 = function(arg0) {
|
||||
const val = getObject(arg0);
|
||||
const ret = typeof(val) === 'object' && val !== null;
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenisundefined_71f08a6ade4354e7 = function(arg0) {
|
||||
const ret = getObject(arg0) === undefined;
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenjsvallooseeq_9dd7bb4b95ac195c = function(arg0, arg1) {
|
||||
const ret = getObject(arg0) == getObject(arg1);
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_wbindgennumberget_d855f947247a3fbc = function(arg0, arg1) {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof(obj) === 'number' ? obj : undefined;
|
||||
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenstringget_43fe05afe34b0cb1 = function(arg0, arg1) {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof(obj) === 'string' ? obj : undefined;
|
||||
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
||||
var len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
||||
};
|
||||
imports.wbg.__wbg_wbindgenthrow_4c11a24fca429ccf = function(arg0, arg1) {
|
||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
||||
};
|
||||
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
||||
// Cast intrinsic for `Ref(String) -> Externref`.
|
||||
const ret = getStringFromWasm0(arg0, arg1);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
||||
const ret = getObject(arg0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
||||
takeObject(arg0);
|
||||
};
|
||||
|
||||
return imports;
|
||||
}
|
||||
|
||||
function __wbg_init_memory(imports, memory) {
|
||||
|
||||
}
|
||||
|
||||
function __wbg_finalize_init(instance, module) {
|
||||
wasm = instance.exports;
|
||||
__wbg_init.__wbindgen_wasm_module = module;
|
||||
cachedDataViewMemory0 = null;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
|
||||
|
||||
|
||||
return wasm;
|
||||
}
|
||||
|
||||
function initSync(module) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
||||
({module} = module)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
__wbg_init_memory(imports);
|
||||
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
module = new WebAssembly.Module(module);
|
||||
}
|
||||
|
||||
const instance = new WebAssembly.Instance(module, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
async function __wbg_init(module_or_path) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (typeof module_or_path !== 'undefined') {
|
||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
||||
({module_or_path} = module_or_path)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof module_or_path === 'undefined') {
|
||||
module_or_path = new URL('rust_fmt_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
||||
module_or_path = fetch(module_or_path);
|
||||
}
|
||||
|
||||
__wbg_init_memory(imports);
|
||||
|
||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
export { initSync };
|
||||
export default __wbg_init;
|
||||
BIN
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt_bg.wasm
Normal file
BIN
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt_bg.wasm
Normal file
Binary file not shown.
8
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt_bg.wasm.d.ts
vendored
Normal file
8
frontend/src/common/prettier/plugins/rust_fmt/rust_fmt_bg.wasm.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const format: (a: number, b: number, c: number, d: number) => void;
|
||||
export const __wbindgen_export_0: (a: number, b: number) => number;
|
||||
export const __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
|
||||
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
export const __wbindgen_export_2: (a: number, b: number, c: number) => void;
|
||||
@@ -0,0 +1,10 @@
|
||||
import fs from "node:fs/promises";
|
||||
import initAsync from "./rust_fmt.js";
|
||||
|
||||
const wasm = new URL("./rust_fmt_bg.wasm", import.meta.url);
|
||||
|
||||
export default function __wbg_init(init = { module_or_path: fs.readFile(wasm) }) {
|
||||
return initAsync(init);
|
||||
}
|
||||
|
||||
export * from "./rust_fmt.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
import initAsync from "./rust_fmt.js";
|
||||
import wasm from "./rust_fmt_bg.wasm?url";
|
||||
|
||||
export default function __wbg_init(input = { module_or_path: wasm }) {
|
||||
return initAsync(input);
|
||||
}
|
||||
|
||||
export * from "./rust_fmt.js";
|
||||
@@ -1,3 +1,3 @@
|
||||
cd $(dirname $0)/..
|
||||
cd $(dirname $0)
|
||||
wasm-pack build --target=web --scope=wasm-fmt
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
cd $(dirname $0)/..
|
||||
crates_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt crates/json_fmt
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
cd $(dirname $0)/..
|
||||
crates_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt json_fmt
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
cd $(dirname $0)/..
|
||||
crates_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt web_fmt
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
cd $(dirname $0)/..
|
||||
crates_dir=$(pwd)
|
||||
|
||||
cd ../..
|
||||
wasm-pack build --target=web --scope=wasm-fmt crates/web_fmt
|
||||
|
||||
@@ -46,6 +46,7 @@ import xmlPrettierPlugin from "@prettier/plugin-xml"
|
||||
import * as rustPrettierPlugin from "@/common/prettier/plugins/rust";
|
||||
import * as shellPrettierPlugin from "@/common/prettier/plugins/shell";
|
||||
import * as dockerfilePrettierPlugin from "@/common/prettier/plugins/shell";
|
||||
// import rustPrettierPlugin from "@/common/prettier/plugins/rust_fmt";
|
||||
import tomlPrettierPlugin from "@/common/prettier/plugins/toml";
|
||||
import clojurePrettierPlugin from "@cospaia/prettier-plugin-clojure";
|
||||
import groovyPrettierPlugin from "@/common/prettier/plugins/groovy";
|
||||
@@ -122,7 +123,7 @@ export const LANGUAGES: LanguageInfo[] = [
|
||||
}
|
||||
}),
|
||||
new LanguageInfo("rs", "Rust", rustLanguage.parser, ["rs"], {
|
||||
parser: "jinx-rust",
|
||||
parser: "rust",
|
||||
plugins: [rustPrettierPlugin]
|
||||
}),
|
||||
new LanguageInfo("cs", "C#", StreamLanguage.define(csharp).parser, ["cs"],{
|
||||
|
||||
Reference in New Issue
Block a user