Skip to content

Commit

Permalink
add paths config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaque committed Jul 4, 2020
1 parent 158112b commit 7a61da0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -53,6 +53,8 @@ Note the VS Code based configuration overrides the `tsconfig` configuration.

- `deno.enable` - Enable/disable this extension. Default is `true`.

- `deno.enablePatterns` - An array of regexes that matches files Deno should be enabled on. Default is `["*"]` (matches all files). Paths are relative to the workspaces directory, so for example `["packages/"']` will look for the `packages` folder in your project.

- `deno.alwaysShowStatus` - Always show the Deno status bar item. Default is `true`.

- `deno.importmap` - The Path of import maps. Default is `null`.
Expand Down
23 changes: 20 additions & 3 deletions client/src/extension.ts
Expand Up @@ -158,6 +158,7 @@ interface SynchronizedConfiguration {
importmap?: string;
tsconfig?: string;
unstable?: boolean;
enablePatterns?: string[];
}

export async function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -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.enablePatterns is specified and this file doesn't
// match a path, then disable Deno.
const paths = (config.get("deno.enablePatterns") || ["*"]) 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
Expand Down Expand Up @@ -460,6 +473,7 @@ function getConfiguration(): SynchronizedConfiguration {
withConfigValue(config, outConfig, "tsconfig");
withConfigValue(config, outConfig, "importmap");
withConfigValue(config, outConfig, "unstable");
withConfigValue(config, outConfig, "enablePatterns");

return outConfig;
}
Expand Down Expand Up @@ -494,8 +508,11 @@ function withConfigValue<C, K extends Extract<keyof C, string>>(
/** when package.json is detected in the root directory, display a prompt */
async function promptForNodeJsProject(): Promise<void> {
let enabled = vscode.workspace.getConfiguration("deno").get("enable", true);
let filtered = vscode.workspace.getConfiguration("deno").get(
"enablePatterns",
);

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(
Expand Down
1 change: 1 addition & 0 deletions package.nls.fr.json
Expand Up @@ -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.enablePatterns": "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."
Expand Down
1 change: 1 addition & 0 deletions package.nls.it.json
Expand Up @@ -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.enablePatterns": "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."
}
1 change: 1 addition & 0 deletions package.nls.json
Expand Up @@ -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.enablePatterns": "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).",
Expand Down
1 change: 1 addition & 0 deletions package.nls.pt-pt.json
Expand Up @@ -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."
}
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Expand Up @@ -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 文件的路径。"
}

0 comments on commit 7a61da0

Please sign in to comment.