From 8354ebb1ca90eedf85218314d2b2a7a84bd7e23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=8D=9A=E5=87=AF?= Date: Sat, 7 Dec 2024 18:10:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../variable-convert/conversion.ts | 5 ++-- .../variable-convert/cyclic-conversion.ts | 6 ++--- .../types}/SupportCaseType.ts | 4 +-- src/extension.ts | 26 +++++++++++++------ .../editor-submenu-handler.ts | 6 ++--- .../quick-pick-handler.ts | 10 +++---- .../status-bar-handler.ts | 0 src/test/extension.test.ts | 8 +++--- src/test/test-case.ts | 2 +- .../types}/TestCaseType.ts | 2 +- .../variable-convert => utils}/transform.ts | 2 +- .../user-configuration.ts | 2 +- src/{main-code => utils}/utils.ts | 0 13 files changed, 42 insertions(+), 31 deletions(-) rename src/{main-code => core}/variable-convert/conversion.ts (97%) rename src/{main-code => core}/variable-convert/cyclic-conversion.ts (96%) rename src/{type-definition => core/variable-convert/types}/SupportCaseType.ts (99%) rename src/{extension-handler => handler}/editor-submenu-handler.ts (90%) rename src/{extension-handler => handler}/quick-pick-handler.ts (95%) rename src/{extension-handler => handler}/status-bar-handler.ts (100%) rename src/{type-definition => test/types}/TestCaseType.ts (94%) rename src/{main-code/variable-convert => utils}/transform.ts (97%) rename src/{main-code => utils}/user-configuration.ts (89%) rename src/{main-code => utils}/utils.ts (100%) diff --git a/src/main-code/variable-convert/conversion.ts b/src/core/variable-convert/conversion.ts similarity index 97% rename from src/main-code/variable-convert/conversion.ts rename to src/core/variable-convert/conversion.ts index 7fd7c01..a1ba205 100644 --- a/src/main-code/variable-convert/conversion.ts +++ b/src/core/variable-convert/conversion.ts @@ -1,7 +1,7 @@ import { EOL } from '../../type-definition/EOLType'; -import { SupportCase } from '../../type-definition/SupportCaseType'; +import { SupportCase } from './types/SupportCaseType'; import { TransformTextResult } from '../../type-definition/TransformTextResultType'; -import { transformMutliLineText, transformText } from './transform'; +import { transformMutliLineText, transformText } from '../../utils/transform'; /** * 统一文本转换函数 @@ -9,6 +9,7 @@ import { transformMutliLineText, transformText } from './transform'; * @param {SupportCase} targetCase 目标文本情况 * @param {string} str 用户选择的文本 user selection * @param {EOL} eol 行结束符 + * @param {Array?} cutText 行结束符 * @returns 转换后的文本 * @since 2024-04-04 */ diff --git a/src/main-code/variable-convert/cyclic-conversion.ts b/src/core/variable-convert/cyclic-conversion.ts similarity index 96% rename from src/main-code/variable-convert/cyclic-conversion.ts rename to src/core/variable-convert/cyclic-conversion.ts index 40027ce..242f354 100644 --- a/src/main-code/variable-convert/cyclic-conversion.ts +++ b/src/core/variable-convert/cyclic-conversion.ts @@ -1,9 +1,9 @@ import * as vscode from 'vscode'; import { EOL } from "../../type-definition/EOLType"; -import { cyclicConvertCaseOrder } from "../../type-definition/SupportCaseType"; +import { cyclicConvertCaseOrder } from "./types/SupportCaseType"; import { caseConversion } from "./conversion"; -import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../utils'; -import { getUserConfigurations } from '../user-configuration'; +import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils'; +import { getUserConfigurations } from '../../utils/user-configuration'; interface UserSelection { currentEol: EOL diff --git a/src/type-definition/SupportCaseType.ts b/src/core/variable-convert/types/SupportCaseType.ts similarity index 99% rename from src/type-definition/SupportCaseType.ts rename to src/core/variable-convert/types/SupportCaseType.ts index 453e6e0..d1124dc 100644 --- a/src/type-definition/SupportCaseType.ts +++ b/src/core/variable-convert/types/SupportCaseType.ts @@ -4,10 +4,10 @@ * Code: * - Add type definition in below `SupportCase` enum and following array * - Add `commands`, `menus`, `configuration` parts in [package.json] and [package-comment.jsonc] - * - Add main conversion logic in [src/main-code/conversion.ts] + * - Add main conversion logic in [src/core/variable-convert/conversion.ts] * * Test: - * - Add test case type definition in [src/type-definition/TestCaseType.ts] + * - Add test case type definition in [src/test/types/TestCaseType.ts] * - Add test case in [src/test/test-case.ts] * - Add test code in [src/test/extension.test.ts] * diff --git a/src/extension.ts b/src/extension.ts index 95d26e1..485e88c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,13 +1,23 @@ -// The module 'vscode' contains the VS Code extensibility API -// Import the module and reference it with the alias vscode in your code below +/** + * @file extension.ts + * @description 该文件包含了 VS Code 插件的主要扩展逻辑,包括命令注册、菜单配置和编辑器事件监听等。 + * @author coder-xiaomo + * @version 1.0.0 + * @license MIT + * + * 本文件是插件的核心文件,负责扩展命令的注册以及编辑器中各种事件的处理。通过监听编辑器的选择状态, + * 动态更新命令行为。插件在启动时会初始化必要的命令,并根据编辑器状态决定是否启用相关功能。 + * + * @see https://code.visualstudio.com/api + */ import * as vscode from 'vscode'; -import handleEditorReplace from './extension-handler/editor-submenu-handler'; -import { handleQuickPick } from './extension-handler/quick-pick-handler'; -import { commands } from './type-definition/SupportCaseType'; -import { createStatusBarItem, updateStatusBarItemVisable } from './extension-handler/status-bar-handler'; -import * as CyclicConversion from './main-code/variable-convert/cyclic-conversion'; +import handleEditorReplace from './handler/editor-submenu-handler'; +import { handleQuickPick } from './handler/quick-pick-handler'; +import { commands } from './core/variable-convert/types/SupportCaseType'; +import { createStatusBarItem, updateStatusBarItemVisable } from './handler/status-bar-handler'; +import * as CyclicConversion from './core/variable-convert/cyclic-conversion'; import { EOL } from './type-definition/EOLType'; -import { getUserConfigurations } from './main-code/user-configuration'; +import { getUserConfigurations } from './utils/user-configuration'; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed diff --git a/src/extension-handler/editor-submenu-handler.ts b/src/handler/editor-submenu-handler.ts similarity index 90% rename from src/extension-handler/editor-submenu-handler.ts rename to src/handler/editor-submenu-handler.ts index d9d2ecd..ac7be8e 100644 --- a/src/extension-handler/editor-submenu-handler.ts +++ b/src/handler/editor-submenu-handler.ts @@ -1,8 +1,8 @@ import * as vscode from 'vscode'; import { EOL } from '../type-definition/EOLType'; -import { caseConversion } from '../main-code/variable-convert/conversion'; -import { SupportCase } from '../type-definition/SupportCaseType'; -import { isStringArrayEqual } from '../main-code/utils'; +import { caseConversion } from '../core/variable-convert/conversion'; +import { SupportCase } from '../core/variable-convert/types/SupportCaseType'; +import { isStringArrayEqual } from '../utils/utils'; /** * 编辑器右键菜单 diff --git a/src/extension-handler/quick-pick-handler.ts b/src/handler/quick-pick-handler.ts similarity index 95% rename from src/extension-handler/quick-pick-handler.ts rename to src/handler/quick-pick-handler.ts index edc283f..42c34b0 100644 --- a/src/extension-handler/quick-pick-handler.ts +++ b/src/handler/quick-pick-handler.ts @@ -1,12 +1,12 @@ import * as vscode from 'vscode'; import QuickPickItemEx from "../type-definition/QuickPickItemExType"; -import { QuickPickSupportCaseItem, quickPickSupportCases } from '../type-definition/SupportCaseType'; +import { QuickPickSupportCaseItem, quickPickSupportCases } from '../core/variable-convert/types/SupportCaseType'; import { TransformTextResult } from '../type-definition/TransformTextResultType'; -import { transformMutliSelectionText } from '../main-code/variable-convert/transform'; +import { transformMutliSelectionText } from '../utils/transform'; import { EOL } from '../type-definition/EOLType'; -import { caseConversion } from '../main-code/variable-convert/conversion'; -import { isStringArrayEqual } from '../main-code/utils'; -import { getUserConfigurations } from '../main-code/user-configuration'; +import { caseConversion } from '../core/variable-convert/conversion'; +import { isStringArrayEqual } from '../utils/utils'; +import { getUserConfigurations } from '../utils/user-configuration'; const QuickPickLabelMaxLength = 60; diff --git a/src/extension-handler/status-bar-handler.ts b/src/handler/status-bar-handler.ts similarity index 100% rename from src/extension-handler/status-bar-handler.ts rename to src/handler/status-bar-handler.ts diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 83ac182..9f45cfd 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -4,10 +4,10 @@ import * as assert from 'assert'; // as well as import your extension to test it import * as vscode from 'vscode'; import testGroups from './test-case'; -import { TestCase, TestCaseGroup } from '../type-definition/TestCaseType'; -import { transformMutliLineText, transformText } from '../main-code/variable-convert/transform'; -import { caseConversion } from '../main-code/variable-convert/conversion'; -import { SupportCase } from '../type-definition/SupportCaseType'; +import { TestCase, TestCaseGroup } from './types/TestCaseType'; +import { transformMutliLineText, transformText } from '../utils/transform'; +import { caseConversion } from '../core/variable-convert/conversion'; +import { SupportCase } from '../core/variable-convert/types/SupportCaseType'; import { TransformTextResult } from '../type-definition/TransformTextResultType'; // import * as myExtension from '../../extension'; diff --git a/src/test/test-case.ts b/src/test/test-case.ts index 2d4232c..f67bc5e 100644 --- a/src/test/test-case.ts +++ b/src/test/test-case.ts @@ -1,4 +1,4 @@ -import { TestCaseGroup } from "../type-definition/TestCaseType"; +import { TestCaseGroup } from "./types/TestCaseType"; const LF = '\n'; const CRLF = '\r\n'; diff --git a/src/type-definition/TestCaseType.ts b/src/test/types/TestCaseType.ts similarity index 94% rename from src/type-definition/TestCaseType.ts rename to src/test/types/TestCaseType.ts index 4c99d87..0261161 100644 --- a/src/type-definition/TestCaseType.ts +++ b/src/test/types/TestCaseType.ts @@ -1,4 +1,4 @@ -import { EOL } from "./EOLType"; +import { EOL } from "../../type-definition/EOLType"; export type TestCaseGroup = { group: string diff --git a/src/main-code/variable-convert/transform.ts b/src/utils/transform.ts similarity index 97% rename from src/main-code/variable-convert/transform.ts rename to src/utils/transform.ts index 6de6aa1..814f3e9 100644 --- a/src/main-code/variable-convert/transform.ts +++ b/src/utils/transform.ts @@ -1,4 +1,4 @@ -import { TransformTextResult } from "../../type-definition/TransformTextResultType"; +import { TransformTextResult } from "../type-definition/TransformTextResultType"; const logDebugInfo = false; diff --git a/src/main-code/user-configuration.ts b/src/utils/user-configuration.ts similarity index 89% rename from src/main-code/user-configuration.ts rename to src/utils/user-configuration.ts index 536968f..256ca4a 100644 --- a/src/main-code/user-configuration.ts +++ b/src/utils/user-configuration.ts @@ -11,7 +11,7 @@ function getUserConfigurations(configKey: string): T | undefined { const config = vscode.workspace.getConfiguration('variable-conversion'); const configValue = config.get(configKey); - console.log('configValue:', configValue); + // console.log('configValue:', configValue); return configValue; } diff --git a/src/main-code/utils.ts b/src/utils/utils.ts similarity index 100% rename from src/main-code/utils.ts rename to src/utils/utils.ts