From 8ecae2c86e28138ac21d12ea29aba34860c3bb95 Mon Sep 17 00:00:00 2001 From: Axetroy Date: Fri, 14 Feb 2020 17:39:24 +0800 Subject: [PATCH] feat: remove `deno.enable` & `deno.disable` command (#48) * feat: remove `deno.enable` and `deno.disable` command * update * docs: update readme --- README.md | 2 - client/src/extension.ts | 146 +++------------------------------------- client/src/util.ts | 17 +++++ package.de-de.json | 2 - package.json | 10 --- package.nl-nl.json | 2 - package.nls.json | 2 - package.nls.zh-cn.json | 2 - package.nls.zh-tw.json | 2 - 9 files changed, 28 insertions(+), 157 deletions(-) create mode 100644 client/src/util.ts diff --git a/README.md b/README.md index eaaab61..210bd46 100644 --- a/README.md +++ b/README.md @@ -168,8 +168,6 @@ This extension also provides Deno's formatting tools, settings are in `.vscode/s This extension contributes the following commands to the Command palette: -- `deno.enable` - Enable this extension. -- `deno.disable` - Disable this extension. - `deno.restart_server` - Restart Deno Language Server. ## Contribute diff --git a/client/src/extension.ts b/client/src/extension.ts index 47719aa..11484d9 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -9,8 +9,6 @@ import { ExtensionContext, StatusBarAlignment, TextEditor, - WorkspaceFolder, - QuickPickItem, WorkspaceConfiguration, Uri, StatusBarItem, @@ -29,27 +27,25 @@ import getport from "get-port"; import execa from "execa"; import { init, localize } from "vscode-nls-i18n"; +import { pathExists } from "./util"; + const TYPESCRIPT_EXTENSION_NAME = "vscode.typescript-language-features"; const TYPESCRIPT_DENO_PLUGIN_ID = "typescript-deno-plugin"; -interface WorkspaceFolderItem extends QuickPickItem { - folder: WorkspaceFolder; -} - -interface SynchronizedConfiguration { +type SynchronizedConfiguration = { enable?: boolean; dtsFilepaths?: string[]; import_map?: string; -} +}; -interface TypescriptAPI { +type TypescriptAPI = { configurePlugin( pluginId: string, configuration: SynchronizedConfiguration ): void; -} +}; -interface DenoInfo { +type DenoInfo = { DENO_DIR: string; version: { deno: string; @@ -59,18 +55,11 @@ interface DenoInfo { }; executablePath: string; dtsFilepath: string; -} +}; -interface ImportMap { +type ImportMap = { imports: { [key: string]: string }; -} - -function exists(filepath: string): Promise { - return fs - .stat(filepath) - .then(() => Promise.resolve(true)) - .catch(() => Promise.resolve(false)); -} +}; async function getImportMaps(importMapFilepath: string, workspaceDir: string) { let importMaps: ImportMap = { @@ -83,7 +72,7 @@ async function getImportMaps(importMapFilepath: string, workspaceDir: string) { ? importMapFilepath : path.resolve(workspaceDir || process.cwd(), importMapFilepath); - if (await exists(importMapsFilepath)) { + if (await pathExists(importMapsFilepath)) { const importMapContent = await fs.readFile(importMapsFilepath); try { @@ -113,30 +102,6 @@ function resolveModuleFromImportMap( return moduleName; } -async function pickFolder( - folders: WorkspaceFolder[], - placeHolder: string, - multipleWorkspaces: boolean -): Promise { - if (!multipleWorkspaces && folders.length === 1) { - return folders[0]; - } - const selected = await window.showQuickPick( - folders.map(folder => { - return { - label: folder.name, - description: folder.uri.fsPath, - folder: folder - }; - }), - { placeHolder: placeHolder } - ); - if (!selected) { - return undefined; - } - return selected.folder; -} - // get typescript api from build-in extension // https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/api.ts async function getTypescriptAPI(): Promise { @@ -417,93 +382,6 @@ Executable ${this.denoInfo.executablePath}`; this.statusBar.show(); } - // enable Deno Extension - private enable() { - const folders = workspace.workspaceFolders; - - if (!folders) { - window.showWarningMessage( - "Deno can only be enabled if VS Code is opened on a workspace folder." - ); - return; - } - - const disabledFolders = folders.filter( - folder => - !workspace - .getConfiguration(this.configurationSection, folder.uri) - .get("enable", true) - ); - - if (disabledFolders.length === 0) { - if (folders.length === 1) { - window.showInformationMessage( - "Deno is already enabled in the workspace." - ); - } else { - window.showInformationMessage( - "Deno is already enabled on all workspace folders." - ); - } - return; - } - - pickFolder( - disabledFolders, - "Select a workspace folder to enable Deno for", - folders.length > 1 - ).then(folder => { - if (!folder) { - return; - } - workspace - .getConfiguration(this.configurationSection, folder.uri) - .update("enable", true); - }); - } - // disable Deno Extension - private disable() { - const folders = workspace.workspaceFolders; - - if (!folders) { - window.showErrorMessage( - "Deno can only be disabled if VS Code is opened on a workspace folder." - ); - return; - } - - const enabledFolders = folders.filter(folder => - workspace - .getConfiguration(this.configurationSection, folder.uri) - .get("enable", true) - ); - - if (enabledFolders.length === 0) { - if (folders.length === 1) { - window.showInformationMessage( - "Deno is already disabled in the workspace." - ); - } else { - window.showInformationMessage( - "Deno is already disabled on all workspace folders." - ); - } - return; - } - - pickFolder( - enabledFolders, - "Select a workspace folder to disable Deno for", - folders.length > 1 - ).then(folder => { - if (!folder) { - return; - } - workspace - .getConfiguration(this.configurationSection, folder.uri) - .update("enable", false); - }); - } // register quickly fix code action private registerQuickFix(map: { [command: string]: ( @@ -564,8 +442,6 @@ Executable ${this.denoInfo.executablePath}`; }) ); - this.registerCommand("enable", this.enable.bind(this)); - this.registerCommand("disable", this.disable.bind(this)); this.registerCommand( "restart_server", this.StartDenoLanguageServer.bind(this) diff --git a/client/src/util.ts b/client/src/util.ts new file mode 100644 index 0000000..ade5d9f --- /dev/null +++ b/client/src/util.ts @@ -0,0 +1,17 @@ +import { promises as fs, statSync } from "fs"; + +export function pathExistsSync(filepath: string) { + try { + return statSync(filepath); + } catch (err) { + return false; + } +} + +export function pathExists(filepath: string) { + try { + return fs.stat(filepath); + } catch (err) { + return false; + } +} diff --git a/package.de-de.json b/package.de-de.json index f49cb2c..068661b 100644 --- a/package.de-de.json +++ b/package.de-de.json @@ -1,8 +1,6 @@ { "deno.displayName": "Deno", "deno.description": "Deno unterstützung für VSCode", - "deno.command.enable": "Aktiviere Deno", - "deno.command.disable": "Deaktiviere Deno", "deno.command.restart_server": "Starte den Deno Language Server neu", "deno.config.enabled": "Steuert, ob Deno aktiviert ist oder nicht.\n\n**In der globalen Konfiguration nicht empfohlen**", "deno.config.dtsFilepaths": "Der Dateipfad der Deno TypeScript-Deklarationsdatei (.d.ts).\n\nDies kann ein Pfad sein, der relativ zum Projektpfad ist, oder ein absoluter Pfad.\n\n**Wird in der globalen Konfiguration nicht empfohlen, ausser wenn Sie einen absoluten Pfad verwenden.**", diff --git a/package.json b/package.json index 5b14cdb..6d04566 100644 --- a/package.json +++ b/package.json @@ -44,16 +44,6 @@ } ], "commands": [ - { - "command": "deno.enable", - "title": "%deno.command.enable%", - "category": "deno" - }, - { - "command": "deno.disable", - "title": "%deno.command.disable%", - "category": "deno" - }, { "command": "deno.restart_server", "title": "%deno.command.restart_server%", diff --git a/package.nl-nl.json b/package.nl-nl.json index 3d435db..a01cbb0 100644 --- a/package.nl-nl.json +++ b/package.nl-nl.json @@ -1,8 +1,6 @@ { "deno.displayName": "Deno", "deno.description": "Deno ondersteuning voor VSCode", - "deno.command.enable": "Schakel Deno aan", - "deno.command.disable": "Schakel Deno uit", "deno.command.restart_server": "Start Deno Language Server opnieuw", "deno.config.enabled": "Bepaalt of Deno is ingeschakeld of niet.\n\n**Niet aanbevolen in globale configuratie**", "deno.config.dtsFilepaths": "Het bestandspad van het Deno TypeScript-declaratiebestand (.d.ts).\n\nHet kan een pad zijn dat relatief is aan het projectpad, of een absoluut pad.\n\n**Niet aanbevolen in globale configuratie tenzij u een absoluut pad gebruikt.**", diff --git a/package.nls.json b/package.nls.json index a073591..bd15392 100644 --- a/package.nls.json +++ b/package.nls.json @@ -1,8 +1,6 @@ { "deno.displayName": "Deno", "deno.description": "Deno support for VSCode", - "deno.command.enable": "Enable Deno", - "deno.command.disable": "Disable Deno", "deno.command.restart_server": "Restart Deno Language Server", "deno.config.enabled": "Controls whether Deno is enabled or not.\n\n**Not recommended in global configuration**", "deno.config.dtsFilepaths": "The file path of the Deno TypeScript declaration file (.d.ts).\n\nIt can be a path that is relative to the project root, or an absolute path.\n\n**Not recommended in global configuration unless you are using an absolute path.**", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index 180b0c5..f6b29d9 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -1,8 +1,6 @@ { "deno.displayName": "Deno", "deno.description": "Deno support for VSCode", - "deno.command.enable": "启用 Deno", - "deno.command.disable": "禁用 Deno", "deno.command.restart_server": "重启 Deno 语言服务器", "deno.config.enabled": "是否启用 Deno。\n\n**不推荐在全局配置中设置**", "deno.config.dtsFilepaths": "Typescript 的声明文件(.d.ts)路径。\n\n它可以是相对于项目目录的相对路径或者是绝对路径。\n\n**不推荐在全局配置中设置**", diff --git a/package.nls.zh-tw.json b/package.nls.zh-tw.json index b75ac47..f20c48d 100644 --- a/package.nls.zh-tw.json +++ b/package.nls.zh-tw.json @@ -1,8 +1,6 @@ { "deno.displayName": "Deno", "deno.description": "Deno support for VSCode", - "deno.command.enable": "啟用 Deno", - "deno.command.disable": "禁用 Deno", "deno.command.restart_server": "重啟 Deno 語言服務器", "deno.config.enabled": "是否啟用 Deno。\n\n**不推薦在全局配置中設置**", "deno.config.dtsFilepaths": "Typescript 的聲明文件(.d.ts)路徑。\n\n它可以是相對於項目目錄的相對路徑或者是絕對路徑。\n\n**不推薦在全局配置中設置**",