Skip to content

Commit

Permalink
Remove unnecessary logging about string expansion (#3761)
Browse files Browse the repository at this point in the history
* Remove unnecessary logging about string expansion

* Fix typo in var name

---------

Co-authored-by: snehara99 <[email protected]>
  • Loading branch information
andreeis and snehara99 authored May 20, 2024
1 parent 02a91b0 commit 3fd67f6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,20 @@ export async function expandString<T>(input: string | T, opts: ExpansionOptions)
const varValueRegexp = ".+?";

async function expandStringHelper(input: string, opts: ExpansionOptions) {
log.debug(localize('expand.expandstringhelper', 'expanding {0}', input));
const envPreNormalize = opts.envOverride ? opts.envOverride : process.env;
const env = EnvironmentUtils.create(envPreNormalize);
const replacements = opts.vars;
replacements.sourceDirectory = replacements.sourceDir;
let circularReference: string | undefined;
let expansionOccurred: boolean = false;

// We accumulate a list of substitutions that we need to make, preventing
// recursively expanding or looping forever on bad replacements
const subs = new Map<string, string>();

const varRegex = /\$\{(\w+)\}/g;
for (const mat of matchAll(input, varRegex)) {
expansionOccurred = true;
const full = mat[0];
const key = mat[1];
if (key !== 'dollar') {
Expand All @@ -169,6 +170,7 @@ async function expandStringHelper(input: string, opts: ExpansionOptions) {

const envRegex1 = RegExp(`\\$\\{env:(${varValueRegexp})\\}`, "g");
for (const mat of matchAll(input, envRegex1)) {
expansionOccurred = true;
const full = mat[0];
const varName = mat[1];
const replacement = fixPaths(env[varName]) || '';
Expand All @@ -177,6 +179,7 @@ async function expandStringHelper(input: string, opts: ExpansionOptions) {

const envRegex2 = RegExp(`\\$\\{env\\.(${varValueRegexp})\\}`, "g");
for (const mat of matchAll(input, envRegex2)) {
expansionOccurred = true;
const full = mat[0];
const varName = mat[1];
const replacement = fixPaths(env[varName]) || '';
Expand All @@ -185,6 +188,7 @@ async function expandStringHelper(input: string, opts: ExpansionOptions) {

const envRegex3 = RegExp(`\\$env\\{(${varValueRegexp})\\}`, "g");
for (const mat of matchAll(input, envRegex3)) {
expansionOccurred = true;
const full = mat[0];
const varName = mat[1];
const replacement: string = fixPaths(env[varName]) || '';
Expand All @@ -208,6 +212,7 @@ async function expandStringHelper(input: string, opts: ExpansionOptions) {
const folderName = mat[1];
const f = vscode.workspace.workspaceFolders.find(folder => folder.name.toLocaleLowerCase() === folderName.toLocaleLowerCase());
if (f) {
expansionOccurred = true;
subs.set(full, f.uri.fsPath);
}
}
Expand All @@ -217,6 +222,7 @@ async function expandStringHelper(input: string, opts: ExpansionOptions) {
const variants = opts.variantVars;
const variantRegex = RegExp(`\\$\\{variant:(${varValueRegexp})\\}`, "g");
for (const mat of matchAll(input, variantRegex)) {
expansionOccurred = true;
const full = mat[0];
const varName = mat[1];
const replacement = variants[varName] || '';
Expand All @@ -236,13 +242,18 @@ async function expandStringHelper(input: string, opts: ExpansionOptions) {
continue; // Don't execute commands more than once per string
}
try {
expansionOccurred = true;
const result = await vscode.commands.executeCommand(command, opts.vars.workspaceFolder);
subs.set(full, `${result}`);
} catch (e) {
log.warning(localize('exception.executing.command', 'Exception while executing command {0} for string: {1} {2}', command, input, errorToString(e)));
}
}

if (expansionOccurred) {
log.debug(localize('expand.expandstringhelper', 'expanded {0}', input));
}

return { ...substituteAll(input, subs), circularReference };
}

Expand Down

0 comments on commit 3fd67f6

Please sign in to comment.