工作区配置

wescode 会自动识别项目类型并进行智能配置。本文档介绍如何配置工作区以获得最佳的 AI 编程体验。

项目类型识别

自动检测

打开一个项目文件夹后,wescode 会自动检测项目类型:

检测结果

检测完成后,wescode 会:

  1. 自动安装推荐的扩展
  2. 配置语言服务器
  3. 设置构建和测试命令
  4. 初始化 CKG 索引
  5. 加载项目特定的 AI 技能

状态栏会显示检测到的项目类型和 CKG 索引进度。

手动配置

如果自动检测不准确,可以手动指定:

// .vscode/settings.json
{
  "wescode.project.type": "go",
  "wescode.project.framework": "gin"
}

语言支持

语言服务器配置

wescode 为主要语言内置了语言服务器支持:

语言语言服务器自动安装
Gogopls✅
TypeScripttsserver✅ 内置
PythonPylance / Pyright✅
Rustrust-analyzer✅
JavaEclipse 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 框架并提供针对性支持:

框架检测方式增强功能
Reactreact 在 package.jsonJSX 补全、组件跳转
Vuevue 在 package.jsonSFC 支持、模板补全
Next.jsnext 在 package.json路由识别、API 路由
Gingithub.com/gin-gonic/gin 在 go.mod路由分析、中间件
FastAPIfastapi 在 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 可以识别项目中的数据库配置:

扩展安装

推荐扩展

首次打开项目时,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 的设置按以下优先级生效(从低到高):

  1. 默认设置:wescode 内置的默认值
  2. 用户设置:~/.config/wescode/settings.json
  3. 工作区设置:.vscode/settings.json
  4. 文件夹设置:多根工作区中的文件夹级设置

常用工作区设置

// .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
}

注意事项

相关文档