feat: 添加代码语法高亮功能和 HTML 格式化依赖
- 集成 react-syntax-highlighter 实现代码高亮显示 - 新增 code-highlighter UI 组件和 syntax-helpers 工具 - 添加 HTML/XML 格式化相关 Rust 依赖(minify-html、markup_fmt 等) - 在开发指南中整合 Rust-TS 跨语言命名规范 - 移除冗余的 Tauri_Naming_Conventions.md 文档 - 更新 Claude Code 配置添加工具命令权限
This commit is contained in:
92
docs/开发指南.md
92
docs/开发指南.md
@@ -741,6 +741,8 @@ pub fn capture_region(
|
||||
|
||||
### 1. 命名规范
|
||||
|
||||
#### 1.1 Rust 内部命名规范
|
||||
|
||||
| 类型 | 命名风格 | 示例 |
|
||||
|------|----------|------|
|
||||
| 模块 | snake_case | `color_service.rs` |
|
||||
@@ -750,6 +752,96 @@ pub fn capture_region(
|
||||
| Trait | PascalCase + 能力 | `ScreenAccessor`, `CursorController` |
|
||||
| 类型别名 | PascalCase + Type | `AppResult`, `JsonResult` |
|
||||
|
||||
#### 1.2 跨语言命名规范(Rust ↔ TypeScript)
|
||||
|
||||
**核心原则**:
|
||||
- ✅ **各自遵循语言规范**:Rust 用 snake_case,前端用 camelCase
|
||||
- ✅ **通过 serde 自动转换**:使用 `#[serde(rename_all = "camelCase")]`
|
||||
- ✅ **类型名称保持一致**:两端都用 PascalCase
|
||||
|
||||
**Rust 端实现**:
|
||||
```rust
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")] // 自动转换
|
||||
pub struct SessionConfig {
|
||||
pub host: String, // Rust: snake_case → JSON: "host"
|
||||
pub port: u16,
|
||||
pub user_name: String, // Rust: snake_case → JSON: "userName"
|
||||
pub private_key_path: String, // Rust: snake_case → JSON: "privateKeyPath"
|
||||
pub auth_method: AuthMethod,
|
||||
}
|
||||
```
|
||||
|
||||
**前端类型定义**:
|
||||
```typescript
|
||||
export interface SessionConfig {
|
||||
host: string; // camelCase
|
||||
port: number;
|
||||
userName: string; // camelCase
|
||||
privateKeyPath: string; // camelCase
|
||||
authMethod: AuthMethod;
|
||||
}
|
||||
```
|
||||
|
||||
**字段命名对照表**:
|
||||
|
||||
| Rust 端 (snake_case) | 前端 (camelCase) | 说明 |
|
||||
|---------------------|------------------|------|
|
||||
| `user_name` | `userName` | 用户名 |
|
||||
| `private_key_path` | `privateKeyPath` | 私钥路径 |
|
||||
| `auth_method` | `authMethod` | 认证方法 |
|
||||
| `connection_id` | `connectionId` | 连接 ID |
|
||||
| `terminal_type` | `terminalType` | 终端类型 |
|
||||
| `keep_alive_interval` | `keepAliveInterval` | 保活间隔 |
|
||||
| `strict_host_key_checking` | `strictHostKeyChecking` | 主机密钥检查 |
|
||||
|
||||
**注意事项**:
|
||||
- ✅ 所有与前端交互的 struct 都必须添加 `#[serde(rename_all = "camelCase")]`
|
||||
- ✅ Enum 变体命名也使用 `#[serde(rename_all = "camelCase")]`
|
||||
- ✅ 类型名称(如 `SessionConfig`)在两端保持一致
|
||||
- ❌ 不要在 Rust 端直接使用 camelCase 命名字段
|
||||
- ❌ 不要在前端使用 snake_case 命名属性
|
||||
|
||||
**完整示例**:
|
||||
|
||||
```rust
|
||||
// Rust 端
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionConfig {
|
||||
pub id: Option<String>,
|
||||
pub name: String,
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub username: String,
|
||||
#[serde(default = "default_keep_alive_interval")]
|
||||
pub keepAliveInterval: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum AuthMethod {
|
||||
Password { password: String },
|
||||
PublicKey { privateKeyPath: String, passphrase: Option<String> },
|
||||
}
|
||||
```
|
||||
|
||||
```typescript
|
||||
// 前端
|
||||
export interface SessionConfig {
|
||||
id?: string;
|
||||
name: string;
|
||||
host: string;
|
||||
port: number;
|
||||
username: string;
|
||||
keepAliveInterval?: number;
|
||||
}
|
||||
|
||||
export type AuthMethod =
|
||||
| { Password: { password: string } }
|
||||
| { PublicKey: { privateKeyPath: string; passphrase?: string } };
|
||||
```
|
||||
|
||||
### 2. 文档注释规范
|
||||
|
||||
```rust
|
||||
|
||||
Reference in New Issue
Block a user