From d315c6ce3b5d7c0d83ddafa5370ab00455a6d1ac Mon Sep 17 00:00:00 2001 From: Jufeng Zhang Date: Sat, 26 Oct 2024 14:52:43 +0800 Subject: [PATCH] refactor: change commands name --- package.json | 22 +++++++++---------- package.nls.json | 6 ++--- package.nls.zh-cn.json | 6 ++--- src/CodeSnippetsEditor.ts | 6 ++--- src/commands/{showEditor.ts => openEditor.ts} | 0 src/commands/{showSource.ts => openSource.ts} | 0 src/commands/searchSnippet.ts | 2 +- .../{showSnippet.ts => viewSnippet.ts} | 0 src/extension.ts | 18 +++++++-------- src/test/suite/extension.test.ts | 16 +++++++------- src/views/BasicSnippetsExplorerView.ts | 8 +++---- 11 files changed, 42 insertions(+), 42 deletions(-) rename src/commands/{showEditor.ts => openEditor.ts} (100%) rename src/commands/{showSource.ts => openSource.ts} (100%) rename src/commands/{showSnippet.ts => viewSnippet.ts} (100%) diff --git a/package.json b/package.json index afa1375..f27352a 100644 --- a/package.json +++ b/package.json @@ -99,8 +99,8 @@ "icon": "$(edit)" }, { - "command": "_snippetsmanager.showSnippet", - "title": "%extension.showSnippet.title%", + "command": "_snippetsmanager.viewSnippet", + "title": "%extension.viewSnippet.title%", "icon": "$(book)" }, { @@ -139,14 +139,14 @@ "category": "Snippets Manager" }, { - "command": "snippetsmanager.showSource", - "title": "%extension.showSource.title%", + "command": "snippetsmanager.openSource", + "title": "%extension.openSource.title%", "category": "Snippets Manager", "icon": "$(go-to-file)" }, { - "command": "snippetsmanager.showEditor", - "title": "%extension.showEditor.title%", + "command": "snippetsmanager.openEditor", + "title": "%extension.openEditor.title%", "category": "Snippets Manager", "icon": "$(book)" } @@ -183,7 +183,7 @@ "menus": { "editor/title": [ { - "command": "snippetsmanager.showEditor", + "command": "snippetsmanager.openEditor", "when": "resourceExtname == '.code-snippets'", "group": "navigation" } @@ -252,7 +252,7 @@ "group": "snippets@2" }, { - "command": "_snippetsmanager.showSnippet", + "command": "_snippetsmanager.viewSnippet", "when": "viewItem == snippetsmanager-snippetsView-Explorer-FileItem && !listMultiSelection", "group": "inline@1" }, @@ -269,11 +269,11 @@ ], "commandPalette": [ { - "command": "snippetsmanager.showSource", + "command": "snippetsmanager.openSource", "when": "resourceExtname == '.code-snippets'" }, { - "command": "snippetsmanager.showEditor", + "command": "snippetsmanager.openEditor", "when": "resourceExtname == '.code-snippets'" }, { @@ -289,7 +289,7 @@ "when": "false" }, { - "command": "_snippetsmanager.showSnippet", + "command": "_snippetsmanager.viewSnippet", "when": "false" }, { diff --git a/package.nls.json b/package.nls.json index c9e8dc1..55a0b0e 100644 --- a/package.nls.json +++ b/package.nls.json @@ -16,15 +16,15 @@ "extension.deleteSnippet.title": "Delete Snippet(s)", "extension.editSnippet.title": "Edit Snippet", "extension.duplicateSnippet.title": "Duplicate Snippet", - "extension.showSnippet.title": "Show Snippet", + "extension.viewSnippet.title": "View Snippet", "extension.deleteSnippetFile.title": "Delete Snippet File", "extension.refresh.title": "Refresh", "extension.search.title": "Search Workspace, User and Extension Snippets", "extension.searchWorkspaceSnippets.title": "Search Workspace Snippets", "extension.searchUserSnippets.title": "Search User Snippets", "extension.searchExtensionSnippets.title": "Search Extension Snippets", - "extension.showSource.title": "Show Source", - "extension.showEditor.title": "Show Editor", + "extension.openSource.title": "Open Source", + "extension.openEditor.title": "Open Editor", "extension.codeSnippetsEditorView.displayName": "Code Snippets Editor", "extension.configuration.title": "Snippets Manager", "extension.configuration.autoCloseSnippetBodyEditor.desc": "Controls whether to automatically close the code snippet body editor after saving." diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index 1643b41..1ecde76 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -16,15 +16,15 @@ "extension.deleteSnippet.title": "删除代码片段", "extension.editSnippet.title": "编辑代码片段", "extension.duplicateSnippet.title": "制作代码片段副本", - "extension.showSnippet.title": "查看代码片段", + "extension.viewSnippet.title": "查看代码片段", "extension.deleteSnippetFile.title": "删除代码片段文件", "extension.refresh.title": "刷新", "extension.search.title": "搜索工作区、用户和拓展程序的代码片段", "extension.searchWorkspaceSnippets.title": "搜索工作区的代码片段", "extension.searchUserSnippets.title": "搜索用户的代码片段", "extension.searchExtensionSnippets.title": "搜索拓展程序的代码片段", - "extension.showSource.title": "打开源文件", - "extension.showEditor.title": "打开代码片段编辑器", + "extension.openSource.title": "打开源文件", + "extension.openEditor.title": "打开代码片段编辑器", "extension.codeSnippetsEditorView.displayName": "代码片段编辑器", "extension.configuration.title": "代码片段管理", "extension.configuration.autoCloseSnippetBodyEditor.desc": "控制是否保存后自动关闭代码片段主体编辑器。" diff --git a/src/CodeSnippetsEditor.ts b/src/CodeSnippetsEditor.ts index fd916bf..30e80a1 100644 --- a/src/CodeSnippetsEditor.ts +++ b/src/CodeSnippetsEditor.ts @@ -2,7 +2,7 @@ import { Buffer } from "buffer"; import * as vscode from "vscode"; import { CodeSnippetsService } from "./CodeSnippetsService"; import editSnippetBody from "./commands/editSnippetBody"; -import showSource from "./commands/showSource"; +import openSource from "./commands/openSource"; import { no, yes } from "./common/l10n"; import { getNonce } from "./util"; import logger from "./utils/logger"; @@ -219,7 +219,7 @@ export class CodeSnippetsEditor implements vscode.CustomTextEditorProvider { } case "openInDefaultEditor": - showSource(); + openSource(); return; case "help": @@ -250,7 +250,7 @@ export class CodeSnippetsEditor implements vscode.CustomTextEditorProvider { ); if (answer === yes) { - showSource(); + openSource(); return; } } diff --git a/src/commands/showEditor.ts b/src/commands/openEditor.ts similarity index 100% rename from src/commands/showEditor.ts rename to src/commands/openEditor.ts diff --git a/src/commands/showSource.ts b/src/commands/openSource.ts similarity index 100% rename from src/commands/showSource.ts rename to src/commands/openSource.ts diff --git a/src/commands/searchSnippet.ts b/src/commands/searchSnippet.ts index 0a2a7a9..7713ba7 100644 --- a/src/commands/searchSnippet.ts +++ b/src/commands/searchSnippet.ts @@ -86,7 +86,7 @@ export default async (type?: SnippetType) => { if (result) { vscode.commands.executeCommand( - "_snippetsmanager.showSnippet", + "_snippetsmanager.viewSnippet", result.snippet, ); } diff --git a/src/commands/showSnippet.ts b/src/commands/viewSnippet.ts similarity index 100% rename from src/commands/showSnippet.ts rename to src/commands/viewSnippet.ts diff --git a/src/extension.ts b/src/extension.ts index 6c92d96..1649231 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,12 +8,12 @@ import deleteSnippetFile from "./commands/deleteSnippetFile"; import duplicateSnippet from "./commands/duplicateSnippet"; import editSnippet from "./commands/editSnippet"; import { initEditSnippetBody } from "./commands/editSnippetBody"; +import openEditor from "./commands/openEditor"; import openSnippetsManger from "./commands/openSnippetsManger"; +import openSource from "./commands/openSource"; import pasteSnippet from "./commands/pasteSnippet"; import searchSnippet from "./commands/searchSnippet"; -import showEditor from "./commands/showEditor"; -import showSnippet from "./commands/showSnippet"; -import showSource from "./commands/showSource"; +import viewSnippet from "./commands/viewSnippet"; import workbenchActionOpenSnippets, { workbenchActionOpenSnippetsId, } from "./commands/workbenchActionOpenSnippets"; @@ -188,9 +188,9 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand( - "_snippetsmanager.showSnippet", + "_snippetsmanager.viewSnippet", (snippet) => { - showSnippet(snippet); + viewSnippet(snippet); }, ), ); @@ -202,14 +202,14 @@ export function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push( - vscode.commands.registerCommand("snippetsmanager.showSource", async () => { - return showSource(); + vscode.commands.registerCommand("snippetsmanager.openSource", async () => { + return openSource(); }), ); context.subscriptions.push( - vscode.commands.registerCommand("snippetsmanager.showEditor", async () => { - return showEditor(); + vscode.commands.registerCommand("snippetsmanager.openEditor", async () => { + return openEditor(); }), ); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index ea3e2f9..ea8519a 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -72,7 +72,7 @@ suite("Extension", () => { const uri = await createTestFile(""); await vscode.commands.executeCommand("vscode.open", uri); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); await vscode.commands.executeCommand("workbench.action.splitEditorRight"); @@ -82,7 +82,7 @@ suite("Extension", () => { assert.strictEqual(currentWebviewPanel, null); await vscode.commands.executeCommand("vscode.open", uri); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); }); @@ -96,24 +96,24 @@ suite("Extension", () => { const uri3 = await createTestFile(""); await vscode.commands.executeCommand("vscode.open", uri); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); await vscode.commands.executeCommand("vscode.open", uri2); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); await vscode.commands.executeCommand("vscode.open", uri3); assert.ok(!currentWebviewPanel); await vscode.commands.executeCommand("vscode.open", uri2); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); - await vscode.commands.executeCommand("snippetsmanager.showSource"); + await vscode.commands.executeCommand("snippetsmanager.openSource"); assert.ok(!currentWebviewPanel); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); }); @@ -125,7 +125,7 @@ suite("Extension", () => { const uri = await createTestFile(`[{"test": {}}]`); await vscode.commands.executeCommand("vscode.open", uri); - await vscode.commands.executeCommand("snippetsmanager.showEditor"); + await vscode.commands.executeCommand("snippetsmanager.openEditor"); assert.ok(currentWebviewPanel); }); }); diff --git a/src/views/BasicSnippetsExplorerView.ts b/src/views/BasicSnippetsExplorerView.ts index 7fd5830..823c8ed 100644 --- a/src/views/BasicSnippetsExplorerView.ts +++ b/src/views/BasicSnippetsExplorerView.ts @@ -90,9 +90,9 @@ export default abstract class BasicSnippetsExplorerView } public getTreeItem(element: SnippetTreeItem): SnippetTreeItem { - const showSnippetCommand = { - command: "_snippetsmanager.showSnippet", - title: "Show this snippet in editor.", + const viewSnippetCommand = { + command: "_snippetsmanager.viewSnippet", + title: "View this snippet in editor.", arguments: [element], }; @@ -107,7 +107,7 @@ export default abstract class BasicSnippetsExplorerView element.name || "", element.children ? vscode.TreeItemCollapsibleState.Collapsed : undefined, ); - item.command = !element.children ? showSnippetCommand : undefined; + item.command = !element.children ? viewSnippetCommand : undefined; item.contextValue = contextValue; return item;