工作区配置
wescode 会自动识别项目类型并进行智能配置。本文档介绍如何配置工作区以获得最佳的 AI 编程体验。
项目类型识别
自动检测
打开一个项目文件夹后,wescode 会自动检测项目类型:
- Go 项目:检测
go.mod、go.sum - Node.js 项目:检测
package.json、tsconfig.json - Python 项目:检测
pyproject.toml、setup.py、requirements.txt - Rust 项目:检测
Cargo.toml - Java 项目:检测
pom.xml、build.gradle - 多语言项目:同时识别多种语言
检测结果
检测完成后,wescode 会:
- 自动安装推荐的扩展
- 配置语言服务器
- 设置构建和测试命令
- 初始化 CKG 索引
- 加载项目特定的 AI 技能
状态栏会显示检测到的项目类型和 CKG 索引进度。
手动配置
如果自动检测不准确,可以手动指定:
// .vscode/settings.json
{
"wescode.project.type": "go",
"wescode.project.framework": "gin"
}
语言支持
语言服务器配置
wescode 为主要语言内置了语言服务器支持:
| 语言 | 语言服务器 | 自动安装 |
|---|---|---|
| Go | gopls | ✅ |
| TypeScript | tsserver | ✅ 内置 |
| Python | Pylance / Pyright | ✅ |
| Rust | rust-analyzer | ✅ |
| Java | Eclipse JDT | 需手动 |
| C/C++ | clangd | 需手动 |
Go 项目配置
{
"go.gopath": "${env:GOPATH}",
"go.goroot": "${env:GOROOT}",
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast"],
"go.testFlags": ["-v", "-count=1"],
"go.formatTool": "goimports"
}
TypeScript 项目配置
{
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.suggest.autoImports": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.formatOnSave": true
}
}
Python 项目配置
{
"python.defaultInterpreterPath": ".venv/bin/python",
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"]
}
框架集成
Web 框架
wescode 识别常见 Web 框架并提供针对性支持:
| 框架 | 检测方式 | 增强功能 |
|---|---|---|
| React | react 在 package.json | JSX 补全、组件跳转 |
| Vue | vue 在 package.json | SFC 支持、模板补全 |
| Next.js | next 在 package.json | 路由识别、API 路由 |
| Gin | github.com/gin-gonic/gin 在 go.mod | 路由分析、中间件 |
| FastAPI | fastapi 在 requirements.txt | 端点识别、Schema |
构建工具
支持的构建工具配置:
// tasks.json — 自定义任务
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "go build ./...",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Test",
"type": "shell",
"command": "go test ./...",
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
数据库工具
wescode 可以识别项目中的数据库配置:
- 自动检测 ORM(GORM、TypeORM、SQLAlchemy 等)
- 提供 SQL 补全和验证
- 数据库 Schema 感知的代码建议
扩展安装
推荐扩展
首次打开项目时,wescode 会根据项目类型推荐扩展:
检测到 Go 项目,推荐安装以下扩展:
✅ Go (golang.go)
✅ Go Test Explorer
☐ REST Client
☐ Docker
工作区扩展推荐
通过 .vscode/extensions.json 为团队成员推荐统一的扩展:
{
"recommendations": [
"golang.go",
"ms-vscode.vscode-typescript-next",
"bradlc.vscode-tailwindcss",
"dbaeumer.vscode-eslint"
],
"unwantedRecommendations": [
"ms-vscode.vscode-typescript"
]
}
扩展管理
# 查看已安装扩展
Ctrl+Shift+X
# 通过命令面板安装
Ctrl+Shift+P → "Extensions: Install Extensions"
# 禁用特定工作区的扩展
扩展面板 → 右键 → "Disable (Workspace)"
环境变量
.env 文件支持
wescode 自动识别 .env 文件并加载环境变量:
# .env
DATABASE_URL=postgres://localhost:5432/mydb
REDIS_URL=redis://localhost:6379
API_KEY=your-api-key
PORT=8080
多环境配置
支持按环境加载不同的配置文件:
.env # 默认环境变量
.env.local # 本地覆盖(不提交到 Git)
.env.development # 开发环境
.env.production # 生产环境
.env.test # 测试环境
在终端中使用
wescode 的集成终端会自动加载 .env 文件中的环境变量。你也可以手动配置:
// .vscode/settings.json
{
"terminal.integrated.env.osx": {
"GOPATH": "${env:HOME}/go",
"PATH": "${env:HOME}/go/bin:${env:PATH}"
}
}
Launch 配置中的环境变量
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Server",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/server",
"envFile": "${workspaceFolder}/.env",
"env": {
"LOG_LEVEL": "debug"
}
}
]
}
工作区设置层级
wescode 的设置按以下优先级生效(从低到高):
- 默认设置:wescode 内置的默认值
- 用户设置:
~/.config/wescode/settings.json - 工作区设置:
.vscode/settings.json - 文件夹设置:多根工作区中的文件夹级设置
常用工作区设置
// .vscode/settings.json
{
// 编辑器
"editor.fontSize": 14,
"editor.tabSize": 4,
"editor.formatOnSave": true,
"editor.rulers": [80, 120],
// 文件
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/dist": true
},
"files.watcherExclude": {
"**/node_modules/**": true,
"**/vendor/**": true
},
// 搜索
"search.exclude": {
"**/node_modules": true,
"**/vendor": true,
"**/*.min.js": true
},
// wescode 特定
"wescode.ckg.enabled": true,
"wescode.qualityGate.autoRun": true
}
注意事项
- 首次打开大型项目时,CKG 索引可能需要几分钟,期间部分功能受限
.env文件中的敏感信息不要提交到 Git(添加到.gitignore)- 工作区设置会影响所有在此文件夹中工作的团队成员
- 多根工作区(Multi-root Workspace)的每个文件夹可以有独立配置
- 语言服务器需要对应的运行时环境(如 Go 需要安装 Go SDK)