From 4198e237fb9a150e65c05a263a8632fecef43fbc Mon Sep 17 00:00:00 2001 From: Flaque Date: Thu, 18 Jun 2020 17:33:17 -0700 Subject: [PATCH] add paths config option --- .vscode/settings.json | 2 +- README.md | 2 ++ client/src/extension.ts | 21 ++++++++++++++++++--- package.nls.fr.json | 1 + package.nls.it.json | 1 + package.nls.json | 1 + package.nls.pt-pt.json | 1 + package.nls.zh-cn.json | 1 + 8 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 54b7d363..d1207850 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,5 @@ "out": true // set this to false to include "out" folder in search results }, "typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version - "typescript.tsc.autoDetect": "off" // Turn off tsc task auto detection since we have the necessary task as npm scripts + "typescript.tsc.autoDetect": "off" } diff --git a/README.md b/README.md index 47c6521e..7a325027 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ Note the VS Code based configuration overrides the `tsconfig` configuration. - `deno.enable` - Enable/disable this extension. Default is `true`. +- `deno.paths` - An array of regexes that matches files Deno should be enabled on. Default is `["*"]` (matches all files). + - `deno.alwaysShowStatus` - Always show the Deno status bar item. Default is `true`. - `deno.importmap` - The Path of import maps. Default is `null`. diff --git a/client/src/extension.ts b/client/src/extension.ts index f0eb6603..a91a3150 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -158,6 +158,7 @@ interface SynchronizedConfiguration { importmap?: string; tsconfig?: string; unstable?: boolean; + paths?: string[]; } export async function activate(context: vscode.ExtensionContext) { @@ -374,8 +375,20 @@ export async function activate(context: vscode.ExtensionContext) { token: vscode.CancellationToken, next: lsp.ProvideCodeActionsSignature, ) { - if (!config.get("deno.enable") || !context.diagnostics) { - return []; + if (!context.diagnostics) return []; + if (!config.get("deno.enable")) return []; + + // If deno.paths is specified and this file doesn't + // match a path, then disable Deno. + const paths = (config.get("deno.paths") || ["*"]) as string[]; + if (paths && paths.length) { + const localFileName = document.fileName + .replace(vscode.workspace.rootPath, ""); + const matchesPath = paths + .findIndex((p) => RegExp(p).test(localFileName)); + if (!matchesPath) { + return []; + } } // diagnostics from Deno Language Server @@ -460,6 +473,7 @@ function getConfiguration(): SynchronizedConfiguration { withConfigValue(config, outConfig, "tsconfig"); withConfigValue(config, outConfig, "importmap"); withConfigValue(config, outConfig, "unstable"); + withConfigValue(config, outConfig, "paths"); return outConfig; } @@ -494,8 +508,9 @@ function withConfigValue>( /** when package.json is detected in the root directory, display a prompt */ async function promptForNodeJsProject(): Promise { let enabled = vscode.workspace.getConfiguration("deno").get("enable", true); + let filtered = vscode.workspace.getConfiguration("deno").get("paths"); - if (enabled && packageJsonExists()) { + if (enabled && !filtered && packageJsonExists()) { const disable = localize("button.disable", "Disable"); const cancel = localize("button.cancel", "Cancel"); const choice = await vscode.window.showInformationMessage( diff --git a/package.nls.fr.json b/package.nls.fr.json index 67b51888..90deb2aa 100644 --- a/package.nls.fr.json +++ b/package.nls.fr.json @@ -7,6 +7,7 @@ "deno.config.enabled": "Détermine si Deno doit être activé ou non.", "deno.config.packageManager": "Le gestionnaire de paquets utilisé pour les modules node.", "deno.config.alwaysShowStatus": "Toujours afficher Deno dans la barre de status.", + "deno.command.paths": "Les dossiers ou fichiers dans lesquels Deno doit être activé", "deno.config.autoFmtOnSave": "Active ou désactive le formatage automatique à la sauvegarde.", "deno.config.dtsPath": "Le chemin du fichier de déclarations de types TypeScript (.d.ts).", "deno.config.importmap": "Le chemin de votre fichier import map." diff --git a/package.nls.it.json b/package.nls.it.json index d7c58830..6d5ae3fa 100644 --- a/package.nls.it.json +++ b/package.nls.it.json @@ -8,6 +8,7 @@ "deno.config.packageManager": "Il gestore di pacchetti con cui installi i moduli node.", "deno.config.alwaysShowStatus": "Mostra sempre Deno sulla barra di stato.", "deno.config.autoFmtOnSave": "Attiva o disattiva la formattazione automatica dopo il salvataggio.", + "deno.command.paths": "Le cartelle o i file in cui Deno dovrebbe essere abilitato", "deno.config.dtsPath": "Il percorso per il file TypeScript declaration (.d.ts).", "deno.config.importmap": "Il percorso delle import map." } diff --git a/package.nls.json b/package.nls.json index 457de78a..3f3ccd71 100644 --- a/package.nls.json +++ b/package.nls.json @@ -6,6 +6,7 @@ "deno.command.disable": "Disable Deno", "deno.config.enabled": "Controls whether deno is enabled or not.", "deno.config.packageManager": "The package manager you use to install node modules.", + "deno.command.paths": "The folders or files that deno should be enabled in", "deno.config.alwaysShowStatus": "Always show the Deno status bar item.", "deno.config.autoFmtOnSave": "Turns auto format on save on or off.", "deno.config.dtsPath": "The Path of TypeScript declaration file(.d.ts).", diff --git a/package.nls.pt-pt.json b/package.nls.pt-pt.json index 0f7e816a..c1fc1fe1 100644 --- a/package.nls.pt-pt.json +++ b/package.nls.pt-pt.json @@ -8,6 +8,7 @@ "deno.config.packageManager": "O gestor de pacotes que você utiliza para instalar node modules.", "deno.config.alwaysShowStatus": "Mostrar sempre o Deno na barra de estados.", "deno.config.autoFmtOnSave": "Ativa ou desativa a formatação automática ao salvar.", + "deno.config.paths": "As pastas ou arquivos nos quais o Deno deve estar ativado", "deno.config.dtsPath": "O caminho para os ficheiros de declaração do TypeScript(.d.ts).", "deno.config.importmap": "O caminho para o ficheiro de importação de mapas." } diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index b7e60083..eccd9606 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -8,6 +8,7 @@ "deno.config.packageManager": "用于运行脚本的程序包管理器。", "deno.config.alwaysShowStatus": "总是在状态栏显示 Deno 图标。", "deno.config.autoFmtOnSave": "是否在保存时进行格式化。", + "deno.config.paths":"应该在其中启用Deno的文件夹或文件", "deno.config.dtsPath": "Deno 的类型声明文件(.d.ts)路径。", "deno.config.importmap": "import maps 文件的路径。" }