From 49e4b10c68bb60ae710e52a6f5e3761de9ed5281 Mon Sep 17 00:00:00 2001 From: Toyoharu Han Date: Sun, 2 Jan 2022 21:18:48 +0900 Subject: [PATCH] add variable substitution for workspaceFolder --- src/utils/settingUtils.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/utils/settingUtils.ts b/src/utils/settingUtils.ts index 7b6eb6c..a874342 100644 --- a/src/utils/settingUtils.ts +++ b/src/utils/settingUtils.ts @@ -3,6 +3,8 @@ import { workspace, WorkspaceConfiguration } from "vscode"; import { DescriptionConfiguration } from "../shared"; +import { sep } from "path"; + export function getWorkspaceConfiguration(): WorkspaceConfiguration { return workspace.getConfiguration("leetcode"); @@ -13,7 +15,7 @@ export function shouldHideSolvedProblem(): boolean { } export function getWorkspaceFolder(): string { - return getWorkspaceConfiguration().get("workspaceFolder", ""); + return substitute(getWorkspaceConfiguration().get("workspaceFolder", "")); } export function getEditorShortcuts(): string[] { @@ -66,3 +68,29 @@ export interface IDescriptionConfiguration { showInComment: boolean; showInWebview: boolean; } + +function substitute(val: T): T { + if (typeof val == 'string') { + val = val.replace(/\$\{(.*?)\}/g, (match, name) => { + const rep = replace(name); + return (rep === null) ? match : rep; + }) as unknown as T; + } + return val; +} + +function replace(name: string): string | null { + if (name == 'pathSeparator') { + return sep as string; + } + const envPrefix = 'env:'; + if (name.startsWith(envPrefix)) + return process.env[name.substring(envPrefix.length)] || ''; + const configPrefix = 'config:'; + if (name.startsWith(configPrefix)) { + const config = workspace.getConfiguration().get( + name.substring(configPrefix.length)); + return (typeof config == 'string') ? config : null; + } + return null; +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy