in src/utils.ts [532:582]
export function applyPathMapping(
sourcePath: string,
pathMapping: IStringDictionary<string>): string {
const forwardSlashSourcePath = sourcePath.replace(/\\/g, '/');
// Sort the overrides by length, large to small
const sortedOverrideKeys = Object.keys(pathMapping)
.sort((a, b) => b.length - a.length);
// Iterate the key/values, only apply the first one that matches.
for (const leftPattern of sortedOverrideKeys) {
const rightPattern = pathMapping[leftPattern];
const asterisks = leftPattern.match(/\*/g) || [];
if (asterisks.length > 1) {
continue;
}
const replacePatternAsterisks = rightPattern.match(/\*/g) || [];
if (replacePatternAsterisks.length > asterisks.length) {
continue;
}
// Does it match?
const escapedLeftPattern = debugCore.utils.escapeRegexSpecialChars(leftPattern, '/*');
const leftRegexSegment = escapedLeftPattern
.replace(/\*/g, '(.*)')
.replace(/\\\\/g, '/');
const leftRegex = new RegExp(`^${leftRegexSegment}$`, 'i');
const overridePatternMatches = leftRegex.exec(forwardSlashSourcePath);
if (!overridePatternMatches) {
continue;
}
// Grab the value of the wildcard from the match above, replace the wildcard in the
// replacement pattern, and return the result.
const wildcardValue = overridePatternMatches[1];
let mappedPath = rightPattern.replace(/\*/g, wildcardValue);
// handling WSL case.
if (vscode.env.remoteName) {
return mappedPath;
}
mappedPath = debugCore.utils.properJoin(mappedPath); // Fix any ..'s
mappedPath = replaceWorkSpaceFolderPlaceholder(mappedPath);
return mappedPath;
}
return sourcePath;
}