/** * 配置管理 * 从 VSCode 设置读取配置项 */ import * as vscode from "vscode"; /** 配置项接口 */ export interface IccoderConfig { /** 后端服务地址 */ backendUrl: string; /** 请求超时时间(毫秒) */ timeout: number; /** 用户ID(临时使用,后续对接认证) */ userId: string; } /** 默认配置 */ const DEFAULT_CONFIG: IccoderConfig = { backendUrl: "http://192.168.1.108:2233", timeout: 60000, userId: "default-user", }; /** * 获取配置项 */ export function getConfig(): IccoderConfig { const config = vscode.workspace.getConfiguration("icCoder"); return { backendUrl: config.get("backendUrl", DEFAULT_CONFIG.backendUrl), timeout: config.get("timeout", DEFAULT_CONFIG.timeout), userId: config.get("userId", DEFAULT_CONFIG.userId), }; } /** * 获取后端 API 地址 */ export function getApiUrl(path: string): string { const { backendUrl } = getConfig(); // 确保 URL 格式正确 const baseUrl = backendUrl.endsWith("/") ? backendUrl.slice(0, -1) : backendUrl; const apiPath = path.startsWith("/") ? path : `/${path}`; return `${baseUrl}${apiPath}`; }