From 728f4d0e1fe28b534f6260864b0f7fd99bb375be Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:24:59 +0800 Subject: [PATCH 1/9] feat: Implement build tools management system in VS Code extension - Add EnvironmentManager for managing VS Code environment variables. - Introduce BuildToolsManager to handle detection, configuration, and environment setup for build tools. - Create ConfigurationResolver for parsing and managing build tool configurations. - Implement integration example to demonstrate build tools management in the extension. - Define types for build tools configuration and environment. - Update meta information and configuration keys for new build tools features. - Ensure legacy configuration migration and validation for user paths. --- packages/vscode/README.md | 22 +- packages/vscode/package.json | 40 ++ packages/vscode/package.nls.zh-cn.json | 5 + packages/vscode/src/build-tools/detector.ts | 470 ++++++++++++++++++ .../vscode/src/build-tools/environment.ts | 196 ++++++++ packages/vscode/src/build-tools/index.ts | 11 + .../src/build-tools/integration-example.ts | 85 ++++ packages/vscode/src/build-tools/manager.ts | 376 ++++++++++++++ packages/vscode/src/build-tools/resolver.ts | 225 +++++++++ packages/vscode/src/build-tools/types.ts | 70 +++ packages/vscode/src/generated/meta.ts | 107 +++- 11 files changed, 1598 insertions(+), 9 deletions(-) create mode 100644 packages/vscode/src/build-tools/detector.ts create mode 100644 packages/vscode/src/build-tools/environment.ts create mode 100644 packages/vscode/src/build-tools/index.ts create mode 100644 packages/vscode/src/build-tools/integration-example.ts create mode 100644 packages/vscode/src/build-tools/manager.ts create mode 100644 packages/vscode/src/build-tools/resolver.ts create mode 100644 packages/vscode/src/build-tools/types.ts diff --git a/packages/vscode/README.md b/packages/vscode/README.md index 2c6e3918..6c3bcb84 100644 --- a/packages/vscode/README.md +++ b/packages/vscode/README.md @@ -102,14 +102,20 @@ PR地址: [https://github.com/material-extensions/vscode-material-icon-theme/pul -| Key | Description | Type | Default | -| ------------------ | ---------------------------------------------------------------------------------------------------------- | --------- | ----------------------------- | -| `ets.sdkPath` | %configuration.ets.sdkPath.description% | `string` | `""` | -| `ets.baseSdkPath` | %configuration.ets.baseSdkPath.description% | `string` | `"${os.homedir}/OpenHarmony"` | -| `ets.hmsPath` | %configuration.ets.hmsPath.description% | `string` | `""` | -| `ets.lspDebugMode` | %configuration.ets.lspDebugMode.description% | `boolean` | `false` | -| `ets.hdcPath` | %configuration.ets.hdcPath.description% | `string` | `""` | -| `ets.sdkList` | A list of installed OpenHarmony SDK paths. Keys should follow the pattern API[number] (e.g., API9, API10). | `object` | `{}` | +| Key | Description | Type | Default | +| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------- | --------- | ----------------------------- | +| `ets.sdkPath` | %configuration.ets.sdkPath.description% | `string` | `""` | +| `ets.baseSdkPath` | %configuration.ets.baseSdkPath.description% | `string` | `"${os.homedir}/OpenHarmony"` | +| `ets.hmsPath` | %configuration.ets.hmsPath.description% | `string` | `""` | +| `ets.lspDebugMode` | %configuration.ets.lspDebugMode.description% | `boolean` | `false` | +| `ets.hdcPath` | %configuration.ets.hdcPath.description% | `string` | `""` | +| `ets.buildTools.autoDetect` | %configuration.ets.buildTools.autoDetect.description% | `boolean` | `true` | +| `ets.buildTools.installationType` | %configuration.ets.buildTools.installationType.description% | `string` | `"auto"` | +| `ets.buildTools.path` | %configuration.ets.buildTools.path.description% | `string` | `""` | +| `ets.buildTools.manageEnvironment` | %configuration.ets.buildTools.manageEnvironment.description% | `boolean` | `true` | +| `ets.buildTools.environmentVariables` | %configuration.ets.buildTools.environmentVariables.description% | `object` | `{}` | +| `ets.ignoreWorkspaceLocalPropertiesFile` | %configuration.ets.ignoreWorkspaceLocalPropertiesFile.description% | `boolean` | `false` | +| `ets.sdkList` | A list of installed OpenHarmony SDK paths. Keys should follow the pattern API[number] (e.g., API9, API10). | `object` | `{}` | diff --git a/packages/vscode/package.json b/packages/vscode/package.json index a47d3265..d836e4f9 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -155,6 +155,46 @@ "deprecationMessage": "Currently this setting is not used.", "default": "" }, + "ets.buildTools.autoDetect": { + "type": "boolean", + "description": "%configuration.ets.buildTools.autoDetect.description%", + "default": true + }, + "ets.buildTools.installationType": { + "type": "string", + "enum": ["auto", "command-line-tools", "deveco-studio"], + "description": "%configuration.ets.buildTools.installationType.description%", + "default": "auto" + }, + "ets.buildTools.path": { + "type": "string", + "description": "%configuration.ets.buildTools.path.description%", + "default": "" + }, + "ets.buildTools.manageEnvironment": { + "type": "boolean", + "description": "%configuration.ets.buildTools.manageEnvironment.description%", + "default": true + }, + "ets.buildTools.environmentVariables": { + "type": "object", + "description": "%configuration.ets.buildTools.environmentVariables.description%", + "default": {}, + "properties": { + "DEVECO_SDK_HOME": { + "type": "string", + "description": "DevEco Studio SDK 路径" + }, + "DevEco Studio": { + "type": "string", + "description": "DevEco Studio bin 目录路径" + } + }, + "additionalProperties": { + "type": "string", + "description": "额外的环境变量" + } + }, "ets.ignoreWorkspaceLocalPropertiesFile": { "type": "boolean", "markdownDescription": "%configuration.ets.ignoreWorkspaceLocalPropertiesFile.description%", diff --git a/packages/vscode/package.nls.zh-cn.json b/packages/vscode/package.nls.zh-cn.json index 0a7a1184..24553e8d 100644 --- a/packages/vscode/package.nls.zh-cn.json +++ b/packages/vscode/package.nls.zh-cn.json @@ -54,6 +54,11 @@ "configuration.ets.lspDebugMode.description": "启用 ETS 语言服务器调试日志。", "configuration.ets.hmsPath.description": "HMS SDK 路径。因为 HMS SDK 是独立于 OpenHarmony SDK 的,所以需要另外单独设置。一般您可以在 DevEco Studio 安装目录下找到该SDK。(此路径对应deveco studio 安装目录下的`sdk/default/harmony`路径)", "configuration.ets.hdcPath.description": "HDC 工具的路径,用于`hilog`等。", + "configuration.ets.buildTools.autoDetect.description": "自动检测 HarmonyOS 构建工具安装", + "configuration.ets.buildTools.installationType.description": "构建工具安装类型:auto (自动检测), command-line-tools (独立命令行工具), deveco-studio (DevEco Studio集成)", + "configuration.ets.buildTools.path.description": "构建工具安装路径 (command-line-tools 根目录或 DevEco Studio 安装目录)", + "configuration.ets.buildTools.manageEnvironment.description": "自动管理构建工具相关的环境变量", + "configuration.ets.buildTools.environmentVariables.description": "额外的环境变量配置", "configuration.ets.ignoreWorkspaceLocalPropertiesFile.description": "忽略从本地工作区 `local.properties` 文件中自动推断基础 SDK 路径。", "ets.language-server.restart.reloadWindow": "ETS 语言服务器已重启!如果内部库存在错误或不正确,您可以单击此按钮重新加载窗口。", "ets.language-server.restart.reloadWindow.button": "重新加载窗口", diff --git a/packages/vscode/src/build-tools/detector.ts b/packages/vscode/src/build-tools/detector.ts new file mode 100644 index 00000000..cf9270cc --- /dev/null +++ b/packages/vscode/src/build-tools/detector.ts @@ -0,0 +1,470 @@ +import type { DetectionResult, InstallationType, ToolsEnvironment } from './types' + +import * as fs from 'node:fs' +import * as path from 'node:path' +import process from 'node:process' +import { promisify } from 'node:util' + +const access = promisify(fs.access) + +/** + * 构建工具检测器 + * 负责自动检测各种HarmonyOS构建工具安装 + */ +export class ToolsDetector { + private static readonly REQUIRED_COMMAND_LINE_TOOLS = [ + 'hvigorw', + 'ohpm', + 'hdc', + 'codelinter', + 'hstack', + ] + + private static readonly REQUIRED_DEVECO_TOOLS = [ + 'hvigor', + 'ohpm', + 'hdc', + ] + + /** + * 检测所有可用的构建工具环境 + */ + async detectAllEnvironments(): Promise { + const environments: ToolsEnvironment[] = [] + const errors: string[] = [] + + try { + // 1. DevEco Studio 环境变量检测 (最高优先级) + const devecoEnvs = await this.detectFromDevEcoEnvironment() + environments.push(...devecoEnvs) + + // 2. Command-line-tools 检测 + const commandLineEnvs = await this.detectCommandLineTools() + environments.push(...commandLineEnvs) + + // 3. PATH 扫描检测 + const pathEnvs = await this.detectFromPath() + environments.push(...pathEnvs) + + // 4. 常见安装路径扫描 + const commonLocationEnvs = await this.detectFromCommonLocations() + environments.push(...commonLocationEnvs) + + // 去重并验证 + const uniqueEnvironments = this.deduplicateEnvironments(environments) + const validatedEnvironments = await this.validateEnvironments(uniqueEnvironments) + + // 选择推荐环境 + const recommended = this.selectRecommendedEnvironment(validatedEnvironments) + + return { + environments: validatedEnvironments, + recommended, + errors, + } + } + catch (error) { + errors.push(`检测失败: ${error instanceof Error ? error.message : String(error)}`) + return { environments, errors } + } + } + + /** + * 通过 DevEco Studio 环境变量检测 + */ + private async detectFromDevEcoEnvironment(): Promise { + const environments: ToolsEnvironment[] = [] + + // DevEco Studio 环境变量检测 + const devecoStudioBin = process.env['DevEco Studio'] + if (devecoStudioBin && await this.pathExists(devecoStudioBin)) { + // DevEco Studio/bin -> DevEco Studio (安装根目录) + const devecoStudioRoot = path.dirname(devecoStudioBin) + const toolsPath = path.join(devecoStudioRoot, 'tool') + + if (await this.validateDevEcoStudioStructure(toolsPath)) { + environments.push({ + type: 'deveco-studio', + path: devecoStudioRoot, + toolsPath, + source: 'environment-variable', + }) + } + } + + // DEVECO_SDK_HOME 推断 + const sdkHome = process.env.DEVECO_SDK_HOME + if (sdkHome && await this.pathExists(sdkHome)) { + // 尝试从 SDK 路径推断 DevEco Studio 安装路径 + const potentialDevecoRoot = path.dirname(sdkHome) + const toolsPath = path.join(potentialDevecoRoot, 'tool') + + if (await this.validateDevEcoStudioStructure(toolsPath)) { + // 避免重复添加相同路径 + if (!environments.some(env => env.path === potentialDevecoRoot)) { + environments.push({ + type: 'deveco-studio', + path: potentialDevecoRoot, + toolsPath, + source: 'sdk-path-inference', + }) + } + } + } + + return environments + } + + /** + * 检测独立的 command-line-tools 安装 + */ + private async detectCommandLineTools(): Promise { + const environments: ToolsEnvironment[] = [] + + // 从环境变量中查找可能的 command-line-tools 路径 + const pathEnv = process.env.PATH || '' + const pathDirs = pathEnv.split(path.delimiter) + + for (const dir of pathDirs) { + if (!dir || !await this.pathExists(dir)) + continue + + // 检查是否是 command-line-tools/bin 目录 + if (path.basename(dir) === 'bin') { + const parentDir = path.dirname(dir) + if (await this.validateCommandLineToolsStructure(parentDir)) { + environments.push({ + type: 'command-line-tools', + path: parentDir, + toolsPath: parentDir, + source: 'path-scan', + }) + } + } + } + + return environments + } + + /** + * 从 PATH 环境变量检测工具 + */ + private async detectFromPath(): Promise { + const environments: ToolsEnvironment[] = [] + + // 检查 PATH 中的 hvigorw 和其他工具 + const pathEnv = process.env.PATH || '' + const pathDirs = pathEnv.split(path.delimiter) + + for (const dir of pathDirs) { + if (!dir || !await this.pathExists(dir)) + continue + + const hvigorwPath = path.join(dir, process.platform === 'win32' ? 'hvigorw.bat' : 'hvigorw') + if (await this.pathExists(hvigorwPath)) { + // 尝试推断安装类型和根路径 + const rootPath = await this.inferRootPathFromBin(dir) + if (rootPath) { + const installationType = await this.determineInstallationType(rootPath) + environments.push({ + type: installationType, + path: rootPath, + toolsPath: installationType === 'deveco-studio' ? path.join(rootPath, 'tool') : rootPath, + source: 'path-scan', + }) + } + } + } + + return environments + } + + /** + * 扫描常见安装位置 + */ + private async detectFromCommonLocations(): Promise { + const environments: ToolsEnvironment[] = [] + const commonPaths = this.getCommonInstallationPaths() + + for (const commonPath of commonPaths) { + if (!await this.pathExists(commonPath)) + continue + + // 检查是否是 DevEco Studio 安装 + const devecoToolsPath = path.join(commonPath, 'tool') + if (await this.validateDevEcoStudioStructure(devecoToolsPath)) { + environments.push({ + type: 'deveco-studio', + path: commonPath, + toolsPath: devecoToolsPath, + source: 'common-location', + }) + continue + } + + // 检查是否是 command-line-tools 安装 + if (await this.validateCommandLineToolsStructure(commonPath)) { + environments.push({ + type: 'command-line-tools', + path: commonPath, + toolsPath: commonPath, + source: 'common-location', + }) + } + } + + return environments + } + + /** + * 验证 DevEco Studio 安装结构 + */ + private async validateDevEcoStudioStructure(toolsPath: string): Promise { + try { + if (!await this.pathExists(toolsPath)) + return false + + // 检查必要的工具目录 + const requiredDirs = ['hvigor', 'ohpm', 'hdc', 'node'] + for (const dir of requiredDirs) { + const dirPath = path.join(toolsPath, dir) + if (!await this.pathExists(dirPath)) + return false + } + + return true + } + catch { + return false + } + } + + /** + * 验证 command-line-tools 安装结构 + */ + private async validateCommandLineToolsStructure(rootPath: string): Promise { + try { + const binPath = path.join(rootPath, 'bin') + if (!await this.pathExists(binPath)) + return false + + // 检查必要的工具 + const requiredTools = ToolsDetector.REQUIRED_COMMAND_LINE_TOOLS + for (const tool of requiredTools) { + const toolPath = path.join(binPath, process.platform === 'win32' ? `${tool}.bat` : tool) + if (!await this.pathExists(toolPath)) + return false + } + + return true + } + catch { + return false + } + } + + /** + * 验证环境可用性 + */ + private async validateEnvironments(environments: ToolsEnvironment[]): Promise { + const validatedEnvironments: ToolsEnvironment[] = [] + + for (const env of environments) { + const availableTools = await this.getAvailableTools(env) + const version = await this.getToolsVersion(env) + + validatedEnvironments.push({ + ...env, + availableTools, + version, + }) + } + + return validatedEnvironments + } + + /** + * 获取可用工具列表 + */ + private async getAvailableTools(env: ToolsEnvironment): Promise { + const tools: string[] = [] + + if (env.type === 'deveco-studio') { + for (const tool of ToolsDetector.REQUIRED_DEVECO_TOOLS) { + const toolDir = path.join(env.toolsPath, tool) + if (await this.pathExists(toolDir)) { + tools.push(tool) + } + } + } + else if (env.type === 'command-line-tools') { + const binPath = path.join(env.toolsPath, 'bin') + for (const tool of ToolsDetector.REQUIRED_COMMAND_LINE_TOOLS) { + const toolPath = path.join(binPath, process.platform === 'win32' ? `${tool}.bat` : tool) + if (await this.pathExists(toolPath)) { + tools.push(tool) + } + } + } + + return tools + } + + /** + * 获取工具版本信息 + */ + private async getToolsVersion(env: ToolsEnvironment): Promise { + // 尝试从 hvigor 获取版本信息 + try { + let hvigorPath: string + + if (env.type === 'deveco-studio') { + hvigorPath = path.join(env.toolsPath, 'hvigor', 'bin', 'hvigor') + } + else { + hvigorPath = path.join(env.toolsPath, 'bin', 'hvigorw') + } + + if (await this.pathExists(hvigorPath)) { + // 这里可以执行 hvigor --version 来获取版本,但为了简化暂时跳过 + return 'unknown' + } + } + catch { + // 忽略版本检测错误 + } + + return undefined + } + + /** + * 选择推荐的环境 + */ + private selectRecommendedEnvironment(environments: ToolsEnvironment[]): ToolsEnvironment | undefined { + if (environments.length === 0) + return undefined + + // 优先级:环境变量检测 > DevEco Studio > command-line-tools + const priorityOrder: Array = [ + 'environment-variable', + 'sdk-path-inference', + 'path-scan', + 'common-location', + ] + + const typeOrder: InstallationType[] = ['deveco-studio', 'command-line-tools', 'unknown'] + + for (const source of priorityOrder) { + for (const type of typeOrder) { + const env = environments.find(e => e.source === source && e.type === type) + if (env) + return env + } + } + + return environments[0] + } + + /** + * 去重环境列表 + */ + private deduplicateEnvironments(environments: ToolsEnvironment[]): ToolsEnvironment[] { + const seen = new Set() + return environments.filter((env) => { + const key = `${env.type}:${env.path}` + if (seen.has(key)) + return false + seen.add(key) + return true + }) + } + + /** + * 从 bin 目录推断根路径 + */ + private async inferRootPathFromBin(binPath: string): Promise { + // 对于 command-line-tools: /path/to/command-line-tools/bin -> /path/to/command-line-tools + if (path.basename(binPath) === 'bin') { + return path.dirname(binPath) + } + + // 对于 DevEco Studio: /path/to/deveco/tool/hvigor/bin -> /path/to/deveco + const segments = binPath.split(path.sep) + const toolIndex = segments.lastIndexOf('tool') + if (toolIndex > 0) { + return segments.slice(0, toolIndex).join(path.sep) + } + + return undefined + } + + /** + * 确定安装类型 + */ + private async determineInstallationType(rootPath: string): Promise { + // 检查是否有 tool 目录 (DevEco Studio) + const toolDir = path.join(rootPath, 'tool') + if (await this.pathExists(toolDir)) { + return 'deveco-studio' + } + + // 检查是否有 bin 目录 (command-line-tools) + const binDir = path.join(rootPath, 'bin') + if (await this.pathExists(binDir)) { + return 'command-line-tools' + } + + return 'unknown' + } + + /** + * 获取常见安装路径 + */ + private getCommonInstallationPaths(): string[] { + const paths: string[] = [] + const homeDir = process.env.HOME || process.env.USERPROFILE || '' + + if (process.platform === 'win32') { + paths.push( + 'C:\\Program Files\\DevEco Studio', + 'C:\\DevEco Studio', + path.join(homeDir, 'AppData', 'Local', 'DevEco Studio'), + 'C:\\command-line-tools', + path.join(homeDir, 'command-line-tools'), + ) + } + else if (process.platform === 'darwin') { + paths.push( + '/Applications/DevEco Studio.app', + path.join(homeDir, 'DevEco Studio'), + path.join(homeDir, 'command-line-tools'), + '/opt/command-line-tools', + ) + } + else { + paths.push( + path.join(homeDir, 'DevEco Studio'), + path.join(homeDir, 'command-line-tools'), + '/opt/DevEco Studio', + '/opt/command-line-tools', + '/usr/local/DevEco Studio', + '/usr/local/command-line-tools', + ) + } + + return paths + } + + /** + * 检查路径是否存在 + */ + private async pathExists(filePath: string): Promise { + try { + await access(filePath) + return true + } + catch { + return false + } + } +} diff --git a/packages/vscode/src/build-tools/environment.ts b/packages/vscode/src/build-tools/environment.ts new file mode 100644 index 00000000..a7b2953d --- /dev/null +++ b/packages/vscode/src/build-tools/environment.ts @@ -0,0 +1,196 @@ +import type { EnvironmentConfig, ToolsEnvironment } from './types' +import * as path from 'node:path' +import * as vscode from 'vscode' + +/** + * 环境变量管理器 + * 负责配置和管理VS Code环境变量集合 + */ +export class EnvironmentManager { + private envCollection: vscode.EnvironmentVariableCollection + private currentConfig?: EnvironmentConfig + + constructor(context: vscode.ExtensionContext) { + this.envCollection = context.environmentVariableCollection + } + + /** + * 应用构建工具环境配置 + */ + async applyEnvironment(environment: ToolsEnvironment): Promise { + // 清除之前的配置 + this.clearEnvironment() + + const config = this.generateEnvironmentConfig(environment) + await this.applyEnvironmentConfig(config) + + this.currentConfig = config + + // 显示配置成功通知 + vscode.window.showInformationMessage( + `已配置 ${environment.type === 'deveco-studio' ? 'DevEco Studio' : 'Command-line-tools'} 构建环境`, + ) + } + + /** + * 清除环境变量配置 + */ + clearEnvironment(): void { + this.envCollection.clear() + this.currentConfig = undefined + } + + /** + * 获取当前环境配置 + */ + getCurrentConfig(): EnvironmentConfig | undefined { + return this.currentConfig + } + + /** + * 检查环境是否已配置 + */ + isConfigured(): boolean { + return this.currentConfig !== undefined + } + + /** + * 生成环境配置 + */ + private generateEnvironmentConfig(environment: ToolsEnvironment): EnvironmentConfig { + const pathAdditions: string[] = [] + const variables: Record = {} + + if (environment.type === 'deveco-studio') { + // DevEco Studio 配置 + const devecoPath = environment.path + const toolPath = environment.toolsPath + + // 1. DevEco Studio bin 路径 + const binPath = path.join(devecoPath, 'bin') + pathAdditions.push(binPath) + + // 2. 各个工具路径 + const hvigorPath = path.join(toolPath, 'hvigor', 'bin') + const ohpmPath = path.join(toolPath, 'ohpm', 'bin') + const hdcPath = path.join(toolPath, 'hdc', 'bin') + const nodePath = path.join(toolPath, 'node', 'bin') + + pathAdditions.push(hvigorPath, ohpmPath, hdcPath, nodePath) + + // 3. 环境变量 + const sdkPath = path.join(devecoPath, 'sdk') + variables.DEVECO_SDK_HOME = sdkPath + variables['DevEco Studio'] = binPath + + // 4. SDK 相关路径 + const openHarmonySdkPath = path.join(sdkPath, 'default', 'openharmony') + const harmonySdkPath = path.join(sdkPath, 'default', 'harmony') + variables.OHOS_SDK_HOME = openHarmonySdkPath + variables.HARMONY_SDK_HOME = harmonySdkPath + } + else if (environment.type === 'command-line-tools') { + // Command-line-tools 配置 + const binPath = path.join(environment.toolsPath, 'bin') + pathAdditions.push(binPath) + + // Node.js 路径 (如果存在) + const nodePath = path.join(environment.toolsPath, 'tool', 'node', 'bin') + pathAdditions.push(nodePath) + + // 工具特定的环境变量 + variables.COMMAND_LINE_TOOLS_HOME = environment.toolsPath + } + + return { + pathAdditions, + variables, + appliedEnvironment: environment, + } + } + + /** + * 应用环境配置到VS Code + */ + private async applyEnvironmentConfig(config: EnvironmentConfig): Promise { + // 配置 PATH + if (config.pathAdditions.length > 0) { + const pathAddition = config.pathAdditions.join(path.delimiter) + this.envCollection.prepend('PATH', pathAddition + path.delimiter) + } + + // 配置其他环境变量 + for (const [key, value] of Object.entries(config.variables)) { + this.envCollection.replace(key, value) + } + + // 设置集合描述 + const envType = config.appliedEnvironment?.type === 'deveco-studio' + ? 'DevEco Studio' + : 'HarmonyOS Command-line-tools' + + this.envCollection.description = `${envType} 构建工具环境变量` + } + + /** + * 获取环境变量详情(用于调试) + */ + getEnvironmentDetails(): Record { + const details: Record = {} + + this.envCollection.forEach((key, value) => { + details[key] = `${value.type}: ${value.value}` + }) + + return details + } + + /** + * 验证环境配置 + */ + async validateEnvironment(): Promise { + if (!this.currentConfig?.appliedEnvironment) { + return false + } + + try { + // 检查关键工具是否可访问 + const environment = this.currentConfig.appliedEnvironment + + if (environment.type === 'deveco-studio') { + // 检查 hvigor 是否可用 + // const hvigorPath = path.join(environment.toolsPath, 'hvigor', 'bin', 'hvigor') + // 这里可以添加更详细的验证逻辑 + return true + } + else if (environment.type === 'command-line-tools') { + // 检查 hvigorw 是否可用 + // const hvigorwPath = path.join(environment.toolsPath, 'bin', 'hvigorw') + // 这里可以添加更详细的验证逻辑 + return true + } + + return false + } + catch (error) { + console.error('环境验证失败:', error) + return false + } + } + + /** + * 刷新环境配置 + */ + async refreshEnvironment(): Promise { + if (this.currentConfig?.appliedEnvironment) { + await this.applyEnvironment(this.currentConfig.appliedEnvironment) + } + } + + /** + * 销毁环境管理器 + */ + dispose(): void { + this.clearEnvironment() + } +} diff --git a/packages/vscode/src/build-tools/index.ts b/packages/vscode/src/build-tools/index.ts new file mode 100644 index 00000000..d0e642bf --- /dev/null +++ b/packages/vscode/src/build-tools/index.ts @@ -0,0 +1,11 @@ +export { ToolsDetector } from './detector' +export { EnvironmentManager } from './environment' +// Build Tools Configuration System +export { BuildToolsManager } from './manager' +export { ConfigurationResolver } from './resolver' +export type { + BuildToolsConfig, + DetectionResult, + InstallationType, + ToolsEnvironment, +} from './types' diff --git a/packages/vscode/src/build-tools/integration-example.ts b/packages/vscode/src/build-tools/integration-example.ts new file mode 100644 index 00000000..18e22ab3 --- /dev/null +++ b/packages/vscode/src/build-tools/integration-example.ts @@ -0,0 +1,85 @@ +import * as vscode from 'vscode' +import { BuildToolsManager } from './index' + +/** + * 构建工具集成示例 + * 展示如何在VS Code扩展中集成构建工具管理系统 + */ + +let buildToolsManager: BuildToolsManager | undefined + +export async function activate(context: vscode.ExtensionContext): Promise { + try { + // 初始化构建工具管理器 + buildToolsManager = new BuildToolsManager(context) + context.subscriptions.push(buildToolsManager) + + // 启动初始化过程 + await buildToolsManager.initialize() + + // 注册其他扩展功能... + registerAdditionalCommands(context) + + console.warn('ArkTS扩展已激活,构建工具管理器已初始化') + } + catch (error) { + console.error('扩展激活失败:', error) + vscode.window.showErrorMessage(`ArkTS扩展激活失败: ${error}`) + } +} + +export function deactivate(): void { + if (buildToolsManager) { + buildToolsManager.dispose() + buildToolsManager = undefined + } +} + +function registerAdditionalCommands(context: vscode.ExtensionContext): void { + // 注册其他扩展命令 + const commands = [ + // 构建工具相关命令已经在 BuildToolsManager 中注册 + // 这里可以注册其他扩展功能的命令 + + vscode.commands.registerCommand('ets.example.checkBuildTools', async () => { + if (buildToolsManager) { + // 获取构建工具状态 + const envConfig = buildToolsManager.environmentManager.getCurrentConfig() + if (envConfig?.appliedEnvironment) { + const env = envConfig.appliedEnvironment + vscode.window.showInformationMessage( + `当前构建工具: ${env.type} (${env.path})`, + ) + } + else { + vscode.window.showWarningMessage('构建工具未配置') + } + } + }), + ] + + context.subscriptions.push(...commands) +} + +/** + * 获取当前的构建工具管理器实例 + * 其他模块可以通过此函数获取管理器实例 + */ +export function getBuildToolsManager(): BuildToolsManager | undefined { + return buildToolsManager +} + +/** + * 检查构建工具是否已配置 + */ +export function isBuildToolsConfigured(): boolean { + return buildToolsManager?.environmentManager.isConfigured() ?? false +} + +/** + * 获取当前构建工具类型 + */ +export function getCurrentBuildToolsType(): 'deveco-studio' | 'command-line-tools' | undefined { + const config = buildToolsManager?.environmentManager.getCurrentConfig() + return config?.appliedEnvironment?.type +} diff --git a/packages/vscode/src/build-tools/manager.ts b/packages/vscode/src/build-tools/manager.ts new file mode 100644 index 00000000..14fd312e --- /dev/null +++ b/packages/vscode/src/build-tools/manager.ts @@ -0,0 +1,376 @@ +import type { ToolsEnvironment } from './types' +import * as vscode from 'vscode' +import { ToolsDetector } from './detector' +import { EnvironmentManager } from './environment' +import { ConfigurationResolver } from './resolver' + +/** + * 构建工具管理器 + * 统一管理构建工具的检测、配置和环境设置 + */ +export class BuildToolsManager implements vscode.Disposable { + private detector: ToolsDetector + private environmentManager: EnvironmentManager + private configResolver: ConfigurationResolver + private statusBarItem?: vscode.StatusBarItem + private disposables: vscode.Disposable[] = [] + + constructor(context: vscode.ExtensionContext) { + this.detector = new ToolsDetector() + this.environmentManager = new EnvironmentManager(context) + this.configResolver = new ConfigurationResolver() + + this.setupStatusBar() + this.registerCommands() + this.watchConfiguration() + } + + /** + * 初始化构建工具系统 + */ + async initialize(): Promise { + try { + // 检查是否需要迁移遗留配置 + if (this.configResolver.needsLegacyMigration()) { + await this.configResolver.migrateLegacyConfig() + vscode.window.showInformationMessage('已迁移遗留的构建工具配置') + } + + const config = this.configResolver.getBuildToolsConfig() + + if (config.autoDetect) { + await this.autoDetectAndConfigure() + } + else if (config.path) { + if (config.installationType === 'auto' + || config.installationType === 'command-line-tools' + || config.installationType === 'deveco-studio') { + await this.configureFromUserPath(config.path, config.installationType) + } + } + + this.updateStatusBar() + } + catch (error) { + console.error('构建工具初始化失败:', error) + this.showErrorMessage('构建工具初始化失败', error) + } + } + + /** + * 自动检测并配置构建工具 + */ + async autoDetectAndConfigure(): Promise { + try { + const result = await this.detector.detectAllEnvironments() + + if (result.environments.length === 0) { + this.showNoToolsFoundMessage() + return + } + + if (result.recommended) { + await this.applyEnvironment(result.recommended) + await this.configResolver.applyDetectedEnvironment(result.recommended) + } + else if (result.environments.length > 1) { + await this.showEnvironmentSelector(result.environments) + } + else { + await this.applyEnvironment(result.environments[0]) + await this.configResolver.applyDetectedEnvironment(result.environments[0]) + } + } + catch (error) { + console.error('自动检测失败:', error) + this.showErrorMessage('自动检测构建工具失败', error) + } + } + + /** + * 从用户指定路径配置 + */ + async configureFromUserPath(userPath: string, installationType: 'auto' | 'command-line-tools' | 'deveco-studio'): Promise { + try { + // 验证路径 + const environment = await this.validateUserPath(userPath, installationType) + if (environment) { + await this.applyEnvironment(environment) + } + else { + vscode.window.showErrorMessage(`无效的构建工具路径: ${userPath}`) + } + } + catch (error) { + console.error('用户路径配置失败:', error) + this.showErrorMessage('配置用户指定的构建工具路径失败', error) + } + } + + /** + * 应用环境配置 + */ + private async applyEnvironment(environment: ToolsEnvironment): Promise { + const config = this.configResolver.getBuildToolsConfig() + + if (config.manageEnvironment) { + await this.environmentManager.applyEnvironment(environment) + } + + // 触发语言服务器重启等其他操作 + await this.onEnvironmentChanged(environment) + } + + /** + * 验证用户路径 + */ + private async validateUserPath(userPath: string, installationType: 'auto' | 'command-line-tools' | 'deveco-studio'): Promise { + // 根据安装类型验证路径 + if (installationType === 'deveco-studio' || installationType === 'auto') { + const toolsPath = `${userPath}/tool` + if (await this.detector.validateDevEcoStudioStructure(toolsPath)) { + return { + type: 'deveco-studio', + path: userPath, + toolsPath, + source: 'user-config', + } + } + } + + if (installationType === 'command-line-tools' || installationType === 'auto') { + if (await this.detector.validateCommandLineToolsStructure(userPath)) { + return { + type: 'command-line-tools', + path: userPath, + toolsPath: userPath, + source: 'user-config', + } + } + } + + return null + } + + /** + * 显示环境选择器 + */ + private async showEnvironmentSelector(environments: ToolsEnvironment[]): Promise { + const items = environments.map(env => ({ + label: `${env.type === 'deveco-studio' ? 'DevEco Studio' : 'Command-line-tools'}`, + description: env.path, + detail: `检测来源: ${env.source}, 可用工具: ${env.availableTools?.join(', ') || '未知'}`, + environment: env, + })) + + const selected = await vscode.window.showQuickPick(items, { + placeHolder: '检测到多个构建工具安装,请选择一个', + ignoreFocusOut: true, + }) + + if (selected) { + await this.applyEnvironment(selected.environment) + await this.configResolver.applyDetectedEnvironment(selected.environment) + } + } + + /** + * 设置状态栏 + */ + private setupStatusBar(): void { + this.statusBarItem = vscode.window.createStatusBarItem( + vscode.StatusBarAlignment.Right, + 100, + ) + this.statusBarItem.command = 'ets.buildTools.status' + this.statusBarItem.tooltip = '点击查看构建工具状态' + this.statusBarItem.show() + + this.disposables.push(this.statusBarItem) + } + + /** + * 更新状态栏 + */ + private updateStatusBar(): void { + if (!this.statusBarItem) + return + + const currentConfig = this.environmentManager.getCurrentConfig() + if (currentConfig?.appliedEnvironment) { + const env = currentConfig.appliedEnvironment + const displayName = env.type === 'deveco-studio' ? 'DevEco Studio' : 'CLI Tools' + this.statusBarItem.text = `$(tools) ${displayName}` + this.statusBarItem.backgroundColor = undefined + } + else { + this.statusBarItem.text = '$(warning) 未配置构建工具' + this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground') + } + } + + /** + * 注册命令 + */ + private registerCommands(): void { + const commands = [ + vscode.commands.registerCommand('ets.buildTools.detect', () => this.commandDetectTools()), + vscode.commands.registerCommand('ets.buildTools.configure', () => this.commandConfigureTools()), + vscode.commands.registerCommand('ets.buildTools.status', () => this.commandShowStatus()), + vscode.commands.registerCommand('ets.buildTools.reset', () => this.commandResetConfiguration()), + vscode.commands.registerCommand('ets.buildTools.refresh', () => this.commandRefreshEnvironment()), + ] + + this.disposables.push(...commands) + } + + /** + * 监听配置变化 + */ + private watchConfiguration(): void { + const configWatcher = vscode.workspace.onDidChangeConfiguration((event) => { + if (event.affectsConfiguration('ets.buildTools')) { + this.onConfigurationChanged() + } + }) + + this.disposables.push(configWatcher) + } + + /** + * 配置变化处理 + */ + private async onConfigurationChanged(): Promise { + // 重新初始化 + await this.initialize() + } + + /** + * 环境变化处理 + */ + private async onEnvironmentChanged(_environment: ToolsEnvironment): Promise { + this.updateStatusBar() + + // 可以在这里触发语言服务器重启等操作 + // await vscode.commands.executeCommand('ets.restartServer') + } + + // 命令处理方法 + private async commandDetectTools(): Promise { + await this.autoDetectAndConfigure() + } + + private async commandConfigureTools(): Promise { + const action = await vscode.window.showQuickPick([ + { label: '自动检测', description: '自动检测系统中的构建工具' }, + { label: '手动选择路径', description: '手动指定构建工具安装路径' }, + { label: '重置配置', description: '重置所有构建工具配置' }, + ], { + placeHolder: '选择配置方式', + }) + + if (!action) + return + + switch (action.label) { + case '自动检测': + await this.configResolver.saveBuildToolsConfig({ autoDetect: true }) + await this.autoDetectAndConfigure() + break + case '手动选择路径': + await this.promptForManualPath() + break + case '重置配置': + await this.configResolver.resetToDefaults() + await this.initialize() + break + } + } + + private async commandShowStatus(): Promise { + const status = this.configResolver.getConfigurationStatus() + const currentEnv = this.environmentManager.getCurrentConfig() + + const info = [ + `自动检测: ${status.autoDetectEnabled ? '启用' : '禁用'}`, + `安装类型: ${status.config.installationType}`, + `有效路径: ${status.effectivePath || '未设置'}`, + `环境管理: ${status.config.manageEnvironment ? '启用' : '禁用'}`, + `当前环境: ${currentEnv?.appliedEnvironment?.type || '未配置'}`, + ].join('\n') + + vscode.window.showInformationMessage(`构建工具状态:\n${info}`, { modal: true }) + } + + private async commandResetConfiguration(): Promise { + const confirm = await vscode.window.showWarningMessage( + '确定要重置所有构建工具配置吗?', + { modal: true }, + '重置', + ) + + if (confirm === '重置') { + await this.configResolver.resetToDefaults() + this.environmentManager.clearEnvironment() + await this.initialize() + vscode.window.showInformationMessage('构建工具配置已重置') + } + } + + private async commandRefreshEnvironment(): Promise { + await this.environmentManager.refreshEnvironment() + vscode.window.showInformationMessage('构建工具环境已刷新') + } + + private async promptForManualPath(): Promise { + const selectedPath = await vscode.window.showOpenDialog({ + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + openLabel: '选择构建工具目录', + }) + + if (selectedPath && selectedPath[0]) { + const path = selectedPath[0].fsPath + + // 检测安装类型 + const environment = await this.validateUserPath(path, 'auto') + if (environment) { + await this.configResolver.saveBuildToolsConfig({ + autoDetect: false, + installationType: environment.type, + path, + }) + await this.applyEnvironment(environment) + vscode.window.showInformationMessage(`已配置 ${environment.type} 构建工具`) + } + else { + vscode.window.showErrorMessage('选择的路径不是有效的构建工具安装目录') + } + } + } + + private showNoToolsFoundMessage(): void { + vscode.window.showWarningMessage( + '未检测到 HarmonyOS 构建工具。请安装 DevEco Studio 或 command-line-tools。', + '手动配置', + ).then((action) => { + if (action === '手动配置') { + this.commandConfigureTools() + } + }) + } + + private showErrorMessage(message: string, error: unknown): void { + const errorMsg = error instanceof Error ? error.message : String(error) + vscode.window.showErrorMessage(`${message}: ${errorMsg}`) + } + + /** + * 销毁管理器 + */ + dispose(): void { + this.disposables.forEach(d => d.dispose()) + this.environmentManager.dispose() + } +} diff --git a/packages/vscode/src/build-tools/resolver.ts b/packages/vscode/src/build-tools/resolver.ts new file mode 100644 index 00000000..74cdefcd --- /dev/null +++ b/packages/vscode/src/build-tools/resolver.ts @@ -0,0 +1,225 @@ +import type { BuildToolsConfig, ToolsEnvironment } from './types' +import { ConfigUtil } from '../config' + +/** + * 配置解析器 + * 负责解析和管理构建工具配置,处理用户设置、自动检测和遗留配置迁移 + */ +export class ConfigurationResolver { + /** + * 解析构建工具配置 + */ + getBuildToolsConfig(): BuildToolsConfig { + return { + autoDetect: ConfigUtil['ets.buildTools.autoDetect'] ?? true, + installationType: ConfigUtil['ets.buildTools.installationType'] ?? 'auto', + path: ConfigUtil['ets.buildTools.path'], + sdkPath: ConfigUtil['ets.sdkPath'], + hmsPath: ConfigUtil['ets.hmsPath'], + hdcPath: ConfigUtil['ets.hdcPath'], + environmentVariables: ConfigUtil['ets.buildTools.environmentVariables'], + manageEnvironment: ConfigUtil['ets.buildTools.manageEnvironment'] ?? true, + } + } + + /** + * 保存构建工具配置 + */ + async saveBuildToolsConfig(config: Partial): Promise { + const updates: Array> = [] + + if (config.autoDetect !== undefined) { + updates.push(ConfigUtil.$update('ets.buildTools.autoDetect', config.autoDetect)) + } + + if (config.installationType !== undefined) { + updates.push(ConfigUtil.$update('ets.buildTools.installationType', config.installationType)) + } + + if (config.path !== undefined) { + updates.push(ConfigUtil.$update('ets.buildTools.path', config.path)) + } + + if (config.environmentVariables !== undefined) { + updates.push(ConfigUtil.$update('ets.buildTools.environmentVariables', config.environmentVariables)) + } + + if (config.manageEnvironment !== undefined) { + updates.push(ConfigUtil.$update('ets.buildTools.manageEnvironment', config.manageEnvironment)) + } + + await Promise.all(updates) + } + + /** + * 应用检测到的环境到配置 + */ + async applyDetectedEnvironment(environment: ToolsEnvironment): Promise { + const config: Partial = { + installationType: environment.type, + path: environment.path, + } + + // 如果是 DevEco Studio 安装,同时更新 SDK 路径 + if (environment.type === 'deveco-studio') { + const sdkPath = `${environment.path}/sdk/default/openharmony` + const hmsPath = `${environment.path}/sdk/default/harmony` + + config.sdkPath = sdkPath + config.hmsPath = hmsPath + + // 更新遗留配置项 + await Promise.all([ + ConfigUtil.$update('ets.sdkPath', sdkPath), + ConfigUtil.$update('ets.hmsPath', hmsPath), + ]) + } + + await this.saveBuildToolsConfig(config) + } + + /** + * 检查是否需要迁移遗留配置 + */ + needsLegacyMigration(): boolean { + const hasNewConfig = !!ConfigUtil['ets.buildTools.path'] + || ConfigUtil['ets.buildTools.installationType'] !== 'auto' + + const hasLegacyConfig = !!ConfigUtil['ets.sdkPath'] + || !!ConfigUtil['ets.hmsPath'] + || !!ConfigUtil['ets.hdcPath'] + + return !hasNewConfig && hasLegacyConfig + } + + /** + * 迁移遗留配置 + */ + async migrateLegacyConfig(): Promise { + const legacyConfig = this.getLegacyConfig() + + if (legacyConfig.sdkPath) { + // 尝试从 SDK 路径推断安装类型和根路径 + const installationInfo = this.inferInstallationFromSdkPath(legacyConfig.sdkPath) + + if (installationInfo) { + await this.saveBuildToolsConfig({ + installationType: installationInfo.type, + path: installationInfo.rootPath, + sdkPath: legacyConfig.sdkPath, + hmsPath: legacyConfig.hmsPath, + hdcPath: legacyConfig.hdcPath, + }) + + // 标记迁移完成,不再使用遗留配置 + // TODO: 添加 legacyMigrated 配置项 + // await ConfigUtil.$update('ets.buildTools.legacyMigrated', true) + } + } + } + + private getLegacyConfig(): { + sdkPath: string + hmsPath: string + hdcPath: string + } { + return { + sdkPath: ConfigUtil['ets.sdkPath'], + hmsPath: ConfigUtil['ets.hmsPath'], + hdcPath: ConfigUtil['ets.hdcPath'], + } + } + + /** + * 从 SDK 路径推断安装信息 + */ + private inferInstallationFromSdkPath(sdkPath: string): { type: 'deveco-studio' | 'command-line-tools', rootPath: string } | null { + // DevEco Studio: /path/to/deveco/sdk/default/openharmony -> /path/to/deveco + if (sdkPath.includes('/sdk/default/openharmony')) { + const rootPath = sdkPath.replace('/sdk/default/openharmony', '') + return { type: 'deveco-studio', rootPath } + } + + // 其他情况暂时无法准确推断 + return null + } + + /** + * 重置配置到默认值 + */ + async resetToDefaults(): Promise { + await Promise.all([ + ConfigUtil.$update('ets.buildTools.autoDetect', true), + ConfigUtil.$update('ets.buildTools.installationType', 'auto'), + ConfigUtil.$update('ets.buildTools.path', ''), + ConfigUtil.$update('ets.buildTools.environmentVariables', {}), + ConfigUtil.$update('ets.buildTools.manageEnvironment', true), + ]) + } + + /** + * 获取有效的构建工具路径 + * 优先级:用户配置 > 自动检测 > 遗留配置 + */ + getEffectiveBuildToolsPath(): string | undefined { + const config = this.getBuildToolsConfig() + + // 用户明确配置的路径 + if (config.path) { + return config.path + } + + // 如果启用自动检测,返回 undefined 让检测器处理 + if (config.autoDetect) { + return undefined + } + + // 尝试从遗留配置推断 + if (config.sdkPath) { + const inferredInfo = this.inferInstallationFromSdkPath(config.sdkPath) + return inferredInfo?.rootPath + } + + return undefined + } + + /** + * 检查配置是否完整 + */ + isConfigurationComplete(): boolean { + const config = this.getBuildToolsConfig() + + if (config.autoDetect) { + // 自动检测模式下,只要启用了自动检测就认为配置完整 + return true + } + + // 手动配置模式下,需要明确的路径 + return !!config.path + } + + /** + * 获取配置状态诊断信息 + */ + getConfigurationStatus(): { + config: BuildToolsConfig + needsMigration: boolean + isComplete: boolean + effectivePath: string | undefined + hasLegacyConfig: boolean + autoDetectEnabled: boolean + } { + const config = this.getBuildToolsConfig() + const needsMigration = this.needsLegacyMigration() + const isComplete = this.isConfigurationComplete() + + return { + config, + needsMigration, + isComplete, + effectivePath: this.getEffectiveBuildToolsPath(), + hasLegacyConfig: !!ConfigUtil['ets.sdkPath'] || !!ConfigUtil['ets.hmsPath'], + autoDetectEnabled: config.autoDetect, + } + } +} diff --git a/packages/vscode/src/build-tools/types.ts b/packages/vscode/src/build-tools/types.ts new file mode 100644 index 00000000..0bd65f0c --- /dev/null +++ b/packages/vscode/src/build-tools/types.ts @@ -0,0 +1,70 @@ +/** + * 构建工具配置类型定义 + */ + +export type InstallationType = 'command-line-tools' | 'deveco-studio' | 'unknown' + +export interface ToolsEnvironment { + /** 安装类型 */ + type: InstallationType + /** 安装根路径 */ + path: string + /** 工具目录路径 */ + toolsPath: string + /** 检测来源 */ + source: 'environment-variable' | 'path-scan' | 'common-location' | 'user-config' | 'sdk-path-inference' + /** 版本信息 */ + version?: string + /** 可用工具列表 */ + availableTools?: string[] +} + +export interface DetectionResult { + /** 检测到的环境列表 */ + environments: ToolsEnvironment[] + /** 推荐使用的环境 */ + recommended?: ToolsEnvironment + /** 检测错误 */ + errors?: string[] +} + +export interface BuildToolsConfig { + /** 是否启用自动检测 */ + autoDetect: boolean + /** 强制指定的安装类型 */ + installationType: 'auto' | InstallationType + /** 用户指定的构建工具路径 */ + path?: string + /** SDK路径配置 */ + sdkPath?: string + /** HMS SDK路径配置 */ + hmsPath?: string + /** HDC工具路径 */ + hdcPath?: string + /** 额外的环境变量 */ + environmentVariables?: Record + /** 是否启用环境变量管理 */ + manageEnvironment: boolean +} + +export interface ToolValidation { + /** 工具名称 */ + name: string + /** 工具路径 */ + path: string + /** 是否可用 */ + available: boolean + /** 版本信息 */ + version?: string + /** 错误信息 */ + error?: string +} + +export interface EnvironmentConfig { + /** PATH环境变量添加项 */ + pathAdditions: string[] + /** 环境变量设置 */ + variables: Record + /** 应用的环境 */ + appliedEnvironment?: ToolsEnvironment +} diff --git a/packages/vscode/src/generated/meta.ts b/packages/vscode/src/generated/meta.ts index 411a0baa..e8d78209 100644 --- a/packages/vscode/src/generated/meta.ts +++ b/packages/vscode/src/generated/meta.ts @@ -4,7 +4,7 @@ // Meta info export const publisher = "NailyZero" export const name = "vscode-naily-ets" -export const version = "1.0.22" +export const version = "1.0.28" export const displayName = "Naily's ArkTS Support" export const description = "自用ArkTS扩展,支持代码跳转,欢迎PR! Naily's ArkTS Support." export const extensionId = `${publisher}.${name}` @@ -32,6 +32,19 @@ export const commands = { etsInstallSDK: "ets.installSDK", } satisfies Record +/** + * Type union of all languages + */ +export type LanguageKey = + | "ets" + +/** + * Languages map registed by `NailyZero.vscode-naily-ets` + */ +export const languages = { + ets: "ets", +} satisfies Record + /** * Type union of all configs */ @@ -41,6 +54,12 @@ export type ConfigKey = | "ets.hmsPath" | "ets.lspDebugMode" | "ets.hdcPath" + | "ets.buildTools.autoDetect" + | "ets.buildTools.installationType" + | "ets.buildTools.path" + | "ets.buildTools.manageEnvironment" + | "ets.buildTools.environmentVariables" + | "ets.ignoreWorkspaceLocalPropertiesFile" | "ets.sdkList" export interface ConfigKeyTypeMap { @@ -49,6 +68,12 @@ export interface ConfigKeyTypeMap { "ets.hmsPath": string, "ets.lspDebugMode": boolean, "ets.hdcPath": string, + "ets.buildTools.autoDetect": boolean, + "ets.buildTools.installationType": ("auto" | "command-line-tools" | "deveco-studio"), + "ets.buildTools.path": string, + "ets.buildTools.manageEnvironment": boolean, + "ets.buildTools.environmentVariables": { 'DEVECO_SDK_HOME'?: string; 'DevEco Studio'?: string }, + "ets.ignoreWorkspaceLocalPropertiesFile": boolean, "ets.sdkList": { 'API10'?: string; 'API11'?: string; 'API12'?: string; 'API13'?: string; 'API14'?: string; 'API15'?: string; 'API18'?: string; 'API20'?: string }, } @@ -58,6 +83,12 @@ export interface ConfigShorthandMap { etsHmsPath: "ets.hmsPath", etsLspDebugMode: "ets.lspDebugMode", etsHdcPath: "ets.hdcPath", + etsBuildToolsAutoDetect: "ets.buildTools.autoDetect", + etsBuildToolsInstallationType: "ets.buildTools.installationType", + etsBuildToolsPath: "ets.buildTools.path", + etsBuildToolsManageEnvironment: "ets.buildTools.manageEnvironment", + etsBuildToolsEnvironmentVariables: "ets.buildTools.environmentVariables", + etsIgnoreWorkspaceLocalPropertiesFile: "ets.ignoreWorkspaceLocalPropertiesFile", etsSdkList: "ets.sdkList", } @@ -67,6 +98,12 @@ export interface ConfigShorthandTypeMap { etsHmsPath: string, etsLspDebugMode: boolean, etsHdcPath: string, + etsBuildToolsAutoDetect: boolean, + etsBuildToolsInstallationType: ("auto" | "command-line-tools" | "deveco-studio"), + etsBuildToolsPath: string, + etsBuildToolsManageEnvironment: boolean, + etsBuildToolsEnvironmentVariables: { 'DEVECO_SDK_HOME'?: string; 'DevEco Studio'?: string }, + etsIgnoreWorkspaceLocalPropertiesFile: boolean, etsSdkList: { 'API10'?: string; 'API11'?: string; 'API12'?: string; 'API13'?: string; 'API14'?: string; 'API15'?: string; 'API18'?: string; 'API20'?: string }, } @@ -130,6 +167,66 @@ export const configs = { key: "ets.hdcPath", default: "", } as ConfigItem<"ets.hdcPath">, + /** + * %configuration.ets.buildTools.autoDetect.description% + * @key `ets.buildTools.autoDetect` + * @default `true` + * @type `boolean` + */ + etsBuildToolsAutoDetect: { + key: "ets.buildTools.autoDetect", + default: true, + } as ConfigItem<"ets.buildTools.autoDetect">, + /** + * %configuration.ets.buildTools.installationType.description% + * @key `ets.buildTools.installationType` + * @default `"auto"` + * @type `string` + */ + etsBuildToolsInstallationType: { + key: "ets.buildTools.installationType", + default: "auto", + } as ConfigItem<"ets.buildTools.installationType">, + /** + * %configuration.ets.buildTools.path.description% + * @key `ets.buildTools.path` + * @default `""` + * @type `string` + */ + etsBuildToolsPath: { + key: "ets.buildTools.path", + default: "", + } as ConfigItem<"ets.buildTools.path">, + /** + * %configuration.ets.buildTools.manageEnvironment.description% + * @key `ets.buildTools.manageEnvironment` + * @default `true` + * @type `boolean` + */ + etsBuildToolsManageEnvironment: { + key: "ets.buildTools.manageEnvironment", + default: true, + } as ConfigItem<"ets.buildTools.manageEnvironment">, + /** + * %configuration.ets.buildTools.environmentVariables.description% + * @key `ets.buildTools.environmentVariables` + * @default `{}` + * @type `object` + */ + etsBuildToolsEnvironmentVariables: { + key: "ets.buildTools.environmentVariables", + default: {}, + } as ConfigItem<"ets.buildTools.environmentVariables">, + /** + * + * @key `ets.ignoreWorkspaceLocalPropertiesFile` + * @default `false` + * @type `boolean` + */ + etsIgnoreWorkspaceLocalPropertiesFile: { + key: "ets.ignoreWorkspaceLocalPropertiesFile", + default: false, + } as ConfigItem<"ets.ignoreWorkspaceLocalPropertiesFile">, /** * A list of installed OpenHarmony SDK paths. Keys should follow the pattern API[number] (e.g., API9, API10). * @key `ets.sdkList` @@ -158,6 +255,14 @@ export interface NestedConfigs { "hmsPath": string, "lspDebugMode": boolean, "hdcPath": string, + "buildTools": { + "autoDetect": boolean, + "installationType": ("auto" | "command-line-tools" | "deveco-studio"), + "path": string, + "manageEnvironment": boolean, + "environmentVariables": { 'DEVECO_SDK_HOME'?: string; 'DevEco Studio'?: string }, + }, + "ignoreWorkspaceLocalPropertiesFile": boolean, "sdkList": { 'API10'?: string; 'API11'?: string; 'API12'?: string; 'API13'?: string; 'API14'?: string; 'API15'?: string; 'API18'?: string; 'API20'?: string }, }, } From b846b7d058db967203bbfc5bb62e650e781fd959 Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:32:31 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E5=85=B7=E7=AE=A1=E7=90=86=E5=99=A8=EF=BC=8C?= =?UTF-8?q?=E5=85=AC=E5=BC=80=E7=8E=AF=E5=A2=83=E7=AE=A1=E7=90=86=E5=99=A8?= =?UTF-8?q?=E3=80=81=E6=A3=80=E6=B5=8B=E5=99=A8=E5=92=8C=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=99=A8=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/build-tools/detector.ts | 4 ++-- .../src/build-tools/integration-example.ts | 8 +++---- packages/vscode/src/build-tools/manager.ts | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/vscode/src/build-tools/detector.ts b/packages/vscode/src/build-tools/detector.ts index cf9270cc..ed1f320d 100644 --- a/packages/vscode/src/build-tools/detector.ts +++ b/packages/vscode/src/build-tools/detector.ts @@ -219,7 +219,7 @@ export class ToolsDetector { /** * 验证 DevEco Studio 安装结构 */ - private async validateDevEcoStudioStructure(toolsPath: string): Promise { + async validateDevEcoStudioStructure(toolsPath: string): Promise { try { if (!await this.pathExists(toolsPath)) return false @@ -242,7 +242,7 @@ export class ToolsDetector { /** * 验证 command-line-tools 安装结构 */ - private async validateCommandLineToolsStructure(rootPath: string): Promise { + async validateCommandLineToolsStructure(rootPath: string): Promise { try { const binPath = path.join(rootPath, 'bin') if (!await this.pathExists(binPath)) diff --git a/packages/vscode/src/build-tools/integration-example.ts b/packages/vscode/src/build-tools/integration-example.ts index 18e22ab3..14bb9657 100644 --- a/packages/vscode/src/build-tools/integration-example.ts +++ b/packages/vscode/src/build-tools/integration-example.ts @@ -44,7 +44,7 @@ function registerAdditionalCommands(context: vscode.ExtensionContext): void { vscode.commands.registerCommand('ets.example.checkBuildTools', async () => { if (buildToolsManager) { // 获取构建工具状态 - const envConfig = buildToolsManager.environmentManager.getCurrentConfig() + const envConfig = buildToolsManager.getEnvironmentManager().getCurrentConfig() if (envConfig?.appliedEnvironment) { const env = envConfig.appliedEnvironment vscode.window.showInformationMessage( @@ -73,13 +73,13 @@ export function getBuildToolsManager(): BuildToolsManager | undefined { * 检查构建工具是否已配置 */ export function isBuildToolsConfigured(): boolean { - return buildToolsManager?.environmentManager.isConfigured() ?? false + return buildToolsManager?.getEnvironmentManager().isConfigured() ?? false } /** * 获取当前构建工具类型 */ export function getCurrentBuildToolsType(): 'deveco-studio' | 'command-line-tools' | undefined { - const config = buildToolsManager?.environmentManager.getCurrentConfig() - return config?.appliedEnvironment?.type + const config = buildToolsManager?.getEnvironmentManager().getCurrentConfig() + return config?.appliedEnvironment?.type === 'unknown' ? undefined : config?.appliedEnvironment?.type } diff --git a/packages/vscode/src/build-tools/manager.ts b/packages/vscode/src/build-tools/manager.ts index 14fd312e..78b1f90d 100644 --- a/packages/vscode/src/build-tools/manager.ts +++ b/packages/vscode/src/build-tools/manager.ts @@ -25,6 +25,27 @@ export class BuildToolsManager implements vscode.Disposable { this.watchConfiguration() } + /** + * 获取环境管理器实例 + */ + getEnvironmentManager(): EnvironmentManager { + return this.environmentManager + } + + /** + * 获取检测器实例 + */ + getDetector(): ToolsDetector { + return this.detector + } + + /** + * 获取配置解析器实例 + */ + getConfigResolver(): ConfigurationResolver { + return this.configResolver + } + /** * 初始化构建工具系统 */ From e3731a231f28bdc7c4b7bad4681af1646c9794b2 Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:43:13 +0800 Subject: [PATCH 3/9] Update packages/vscode/src/build-tools/integration-example.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/vscode/src/build-tools/integration-example.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode/src/build-tools/integration-example.ts b/packages/vscode/src/build-tools/integration-example.ts index 14bb9657..6e20ee8f 100644 --- a/packages/vscode/src/build-tools/integration-example.ts +++ b/packages/vscode/src/build-tools/integration-example.ts @@ -20,7 +20,7 @@ export async function activate(context: vscode.ExtensionContext): Promise // 注册其他扩展功能... registerAdditionalCommands(context) - console.warn('ArkTS扩展已激活,构建工具管理器已初始化') + console.log('ArkTS扩展已激活,构建工具管理器已初始化') } catch (error) { console.error('扩展激活失败:', error) From 07b0fa9799ae5c6f3acbc739ac1fa3378d814aeb Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:43:49 +0800 Subject: [PATCH 4/9] Update packages/vscode/src/build-tools/manager.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/vscode/src/build-tools/manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode/src/build-tools/manager.ts b/packages/vscode/src/build-tools/manager.ts index 78b1f90d..a5b3b7cf 100644 --- a/packages/vscode/src/build-tools/manager.ts +++ b/packages/vscode/src/build-tools/manager.ts @@ -65,7 +65,7 @@ export class BuildToolsManager implements vscode.Disposable { else if (config.path) { if (config.installationType === 'auto' || config.installationType === 'command-line-tools' - || config.installationType === 'deveco-studio') { + if (['auto', 'command-line-tools', 'deveco-studio'].includes(config.installationType)) { await this.configureFromUserPath(config.path, config.installationType) } } From 5afb0a98e06e464c35c1031c9a163e15e996b014 Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:52:40 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=81=97?= =?UTF-8?q?=E7=95=99=E9=85=8D=E7=BD=AE=E8=BF=81=E7=A7=BB=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E5=92=8C=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/package.json | 5 +++++ packages/vscode/package.nls.zh-cn.json | 1 + packages/vscode/src/build-tools/resolver.ts | 9 +++++++-- packages/vscode/src/build-tools/types.ts | 2 ++ packages/vscode/src/generated/meta.ts | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/vscode/package.json b/packages/vscode/package.json index d836e4f9..21e78715 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -195,6 +195,11 @@ "description": "额外的环境变量" } }, + "ets.buildTools.legacyMigrated": { + "type": "boolean", + "description": "%configuration.ets.buildTools.legacyMigrated.description%", + "default": false + }, "ets.ignoreWorkspaceLocalPropertiesFile": { "type": "boolean", "markdownDescription": "%configuration.ets.ignoreWorkspaceLocalPropertiesFile.description%", diff --git a/packages/vscode/package.nls.zh-cn.json b/packages/vscode/package.nls.zh-cn.json index 24553e8d..f66880c7 100644 --- a/packages/vscode/package.nls.zh-cn.json +++ b/packages/vscode/package.nls.zh-cn.json @@ -59,6 +59,7 @@ "configuration.ets.buildTools.path.description": "构建工具安装路径 (command-line-tools 根目录或 DevEco Studio 安装目录)", "configuration.ets.buildTools.manageEnvironment.description": "自动管理构建工具相关的环境变量", "configuration.ets.buildTools.environmentVariables.description": "额外的环境变量配置", + "configuration.ets.buildTools.legacyMigrated.description": "标记是否已完成遗留配置迁移(内部使用)", "configuration.ets.ignoreWorkspaceLocalPropertiesFile.description": "忽略从本地工作区 `local.properties` 文件中自动推断基础 SDK 路径。", "ets.language-server.restart.reloadWindow": "ETS 语言服务器已重启!如果内部库存在错误或不正确,您可以单击此按钮重新加载窗口。", "ets.language-server.restart.reloadWindow.button": "重新加载窗口", diff --git a/packages/vscode/src/build-tools/resolver.ts b/packages/vscode/src/build-tools/resolver.ts index 74cdefcd..43bbd977 100644 --- a/packages/vscode/src/build-tools/resolver.ts +++ b/packages/vscode/src/build-tools/resolver.ts @@ -19,6 +19,7 @@ export class ConfigurationResolver { hdcPath: ConfigUtil['ets.hdcPath'], environmentVariables: ConfigUtil['ets.buildTools.environmentVariables'], manageEnvironment: ConfigUtil['ets.buildTools.manageEnvironment'] ?? true, + legacyMigrated: ConfigUtil['ets.buildTools.legacyMigrated'] ?? false, } } @@ -82,6 +83,11 @@ export class ConfigurationResolver { * 检查是否需要迁移遗留配置 */ needsLegacyMigration(): boolean { + // 如果已经标记为迁移完成,则不需要再迁移 + if (ConfigUtil['ets.buildTools.legacyMigrated']) { + return false + } + const hasNewConfig = !!ConfigUtil['ets.buildTools.path'] || ConfigUtil['ets.buildTools.installationType'] !== 'auto' @@ -112,8 +118,7 @@ export class ConfigurationResolver { }) // 标记迁移完成,不再使用遗留配置 - // TODO: 添加 legacyMigrated 配置项 - // await ConfigUtil.$update('ets.buildTools.legacyMigrated', true) + await ConfigUtil.$update('ets.buildTools.legacyMigrated', true) } } } diff --git a/packages/vscode/src/build-tools/types.ts b/packages/vscode/src/build-tools/types.ts index 0bd65f0c..a9948eb5 100644 --- a/packages/vscode/src/build-tools/types.ts +++ b/packages/vscode/src/build-tools/types.ts @@ -45,6 +45,8 @@ export interface BuildToolsConfig { environmentVariables?: Record /** 是否启用环境变量管理 */ manageEnvironment: boolean + /** 是否已完成遗留配置迁移 */ + legacyMigrated?: boolean } export interface ToolValidation { diff --git a/packages/vscode/src/generated/meta.ts b/packages/vscode/src/generated/meta.ts index e8d78209..bb541637 100644 --- a/packages/vscode/src/generated/meta.ts +++ b/packages/vscode/src/generated/meta.ts @@ -59,6 +59,7 @@ export type ConfigKey = | "ets.buildTools.path" | "ets.buildTools.manageEnvironment" | "ets.buildTools.environmentVariables" + | "ets.buildTools.legacyMigrated" | "ets.ignoreWorkspaceLocalPropertiesFile" | "ets.sdkList" @@ -73,6 +74,7 @@ export interface ConfigKeyTypeMap { "ets.buildTools.path": string, "ets.buildTools.manageEnvironment": boolean, "ets.buildTools.environmentVariables": { 'DEVECO_SDK_HOME'?: string; 'DevEco Studio'?: string }, + "ets.buildTools.legacyMigrated": boolean, "ets.ignoreWorkspaceLocalPropertiesFile": boolean, "ets.sdkList": { 'API10'?: string; 'API11'?: string; 'API12'?: string; 'API13'?: string; 'API14'?: string; 'API15'?: string; 'API18'?: string; 'API20'?: string }, } @@ -88,6 +90,7 @@ export interface ConfigShorthandMap { etsBuildToolsPath: "ets.buildTools.path", etsBuildToolsManageEnvironment: "ets.buildTools.manageEnvironment", etsBuildToolsEnvironmentVariables: "ets.buildTools.environmentVariables", + etsBuildToolsLegacyMigrated: "ets.buildTools.legacyMigrated", etsIgnoreWorkspaceLocalPropertiesFile: "ets.ignoreWorkspaceLocalPropertiesFile", etsSdkList: "ets.sdkList", } @@ -103,6 +106,7 @@ export interface ConfigShorthandTypeMap { etsBuildToolsPath: string, etsBuildToolsManageEnvironment: boolean, etsBuildToolsEnvironmentVariables: { 'DEVECO_SDK_HOME'?: string; 'DevEco Studio'?: string }, + etsBuildToolsLegacyMigrated: boolean, etsIgnoreWorkspaceLocalPropertiesFile: boolean, etsSdkList: { 'API10'?: string; 'API11'?: string; 'API12'?: string; 'API13'?: string; 'API14'?: string; 'API15'?: string; 'API18'?: string; 'API20'?: string }, } @@ -217,6 +221,16 @@ export const configs = { key: "ets.buildTools.environmentVariables", default: {}, } as ConfigItem<"ets.buildTools.environmentVariables">, + /** + * %configuration.ets.buildTools.legacyMigrated.description% + * @key `ets.buildTools.legacyMigrated` + * @default `false` + * @type `boolean` + */ + etsBuildToolsLegacyMigrated: { + key: "ets.buildTools.legacyMigrated", + default: false, + } as ConfigItem<"ets.buildTools.legacyMigrated">, /** * * @key `ets.ignoreWorkspaceLocalPropertiesFile` @@ -261,6 +275,7 @@ export interface NestedConfigs { "path": string, "manageEnvironment": boolean, "environmentVariables": { 'DEVECO_SDK_HOME'?: string; 'DevEco Studio'?: string }, + "legacyMigrated": boolean, }, "ignoreWorkspaceLocalPropertiesFile": boolean, "sdkList": { 'API10'?: string; 'API11'?: string; 'API12'?: string; 'API13'?: string; 'API14'?: string; 'API15'?: string; 'API18'?: string; 'API20'?: string }, From f782f75bfdb0e2740c6cc625fe9771dac1a8ad38 Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:55:39 +0800 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E4=B8=BA=E8=AD=A6=E5=91=8A=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=9E=84=E5=BB=BA=E5=B7=A5=E5=85=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E8=B7=AF=E5=BE=84=E9=85=8D=E7=BD=AE=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/build-tools/integration-example.ts | 2 +- packages/vscode/src/build-tools/manager.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/vscode/src/build-tools/integration-example.ts b/packages/vscode/src/build-tools/integration-example.ts index 6e20ee8f..14bb9657 100644 --- a/packages/vscode/src/build-tools/integration-example.ts +++ b/packages/vscode/src/build-tools/integration-example.ts @@ -20,7 +20,7 @@ export async function activate(context: vscode.ExtensionContext): Promise // 注册其他扩展功能... registerAdditionalCommands(context) - console.log('ArkTS扩展已激活,构建工具管理器已初始化') + console.warn('ArkTS扩展已激活,构建工具管理器已初始化') } catch (error) { console.error('扩展激活失败:', error) diff --git a/packages/vscode/src/build-tools/manager.ts b/packages/vscode/src/build-tools/manager.ts index a5b3b7cf..2f926c3e 100644 --- a/packages/vscode/src/build-tools/manager.ts +++ b/packages/vscode/src/build-tools/manager.ts @@ -63,8 +63,6 @@ export class BuildToolsManager implements vscode.Disposable { await this.autoDetectAndConfigure() } else if (config.path) { - if (config.installationType === 'auto' - || config.installationType === 'command-line-tools' if (['auto', 'command-line-tools', 'deveco-studio'].includes(config.installationType)) { await this.configureFromUserPath(config.path, config.installationType) } From 7eb8c77db6f3b3c43c0ccf9b3b807afec4b40124 Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 14:57:38 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=E5=BC=BA=E5=88=B6=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=AE=89=E8=A3=85=E7=B1=BB=E5=9E=8B=E4=BB=A5?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E8=B7=AF=E5=BE=84=E9=85=8D=E7=BD=AE=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/build-tools/manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode/src/build-tools/manager.ts b/packages/vscode/src/build-tools/manager.ts index 2f926c3e..80063353 100644 --- a/packages/vscode/src/build-tools/manager.ts +++ b/packages/vscode/src/build-tools/manager.ts @@ -64,7 +64,7 @@ export class BuildToolsManager implements vscode.Disposable { } else if (config.path) { if (['auto', 'command-line-tools', 'deveco-studio'].includes(config.installationType)) { - await this.configureFromUserPath(config.path, config.installationType) + await this.configureFromUserPath(config.path, config.installationType as 'auto' | 'command-line-tools' | 'deveco-studio') } } From 4274c687de5ded5538ead92bcfd9cb47c48dd2b9 Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 15:58:23 +0800 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E5=B7=A5=E5=85=B7=20'hdc'=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=B7=A5=E5=85=B7=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/build-tools/detector.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/vscode/src/build-tools/detector.ts b/packages/vscode/src/build-tools/detector.ts index ed1f320d..039c3bdf 100644 --- a/packages/vscode/src/build-tools/detector.ts +++ b/packages/vscode/src/build-tools/detector.ts @@ -15,7 +15,6 @@ export class ToolsDetector { private static readonly REQUIRED_COMMAND_LINE_TOOLS = [ 'hvigorw', 'ohpm', - 'hdc', 'codelinter', 'hstack', ] @@ -23,7 +22,7 @@ export class ToolsDetector { private static readonly REQUIRED_DEVECO_TOOLS = [ 'hvigor', 'ohpm', - 'hdc', + 'hstack', ] /** @@ -225,7 +224,7 @@ export class ToolsDetector { return false // 检查必要的工具目录 - const requiredDirs = ['hvigor', 'ohpm', 'hdc', 'node'] + const requiredDirs = ['hvigor', 'ohpm', 'node'] for (const dir of requiredDirs) { const dirPath = path.join(toolsPath, dir) if (!await this.pathExists(dirPath)) From 9e1312495aecb2e74ad9102b8cf3f3cd0cdf958c Mon Sep 17 00:00:00 2001 From: sanchuanhehe Date: Sun, 17 Aug 2025 16:00:08 +0800 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E5=B7=A5=E5=85=B7=20'hdc'=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/build-tools/environment.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vscode/src/build-tools/environment.ts b/packages/vscode/src/build-tools/environment.ts index a7b2953d..2d325773 100644 --- a/packages/vscode/src/build-tools/environment.ts +++ b/packages/vscode/src/build-tools/environment.ts @@ -73,10 +73,9 @@ export class EnvironmentManager { // 2. 各个工具路径 const hvigorPath = path.join(toolPath, 'hvigor', 'bin') const ohpmPath = path.join(toolPath, 'ohpm', 'bin') - const hdcPath = path.join(toolPath, 'hdc', 'bin') const nodePath = path.join(toolPath, 'node', 'bin') - pathAdditions.push(hvigorPath, ohpmPath, hdcPath, nodePath) + pathAdditions.push(hvigorPath, ohpmPath, nodePath) // 3. 环境变量 const sdkPath = path.join(devecoPath, 'sdk')