Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sourcemap predictor not filtering nested session on windows #1723

Merged
merged 2 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he
- fix: useWebview debug sessions getting stuck if program exits without attaching ([#1666](https://github.com/microsoft/vscode-js-debug/issues/1666))
- fix: do not to translate "promise rejection" ([#1658](https://github.com/microsoft/vscode-js-debug/issues/1658))
- fix: breakpoints not hitting early on in nested sourcemapped programs ([#1704](https://github.com/microsoft/vscode-js-debug/issues/1704))
- fix: sourcemap predictor not filtering nested session on windows ([#1719](https://github.com/microsoft/vscode-js-debug/issues/1719))
- fix: increase smart step backout threshold for better stepping ([#1700](https://github.com/microsoft/vscode-js-debug/issues/1700))
- fix: Blazor sources sometimes being missing ([dotnet/runtime#86754](https://github.com/dotnet/runtime/issues/86754))

Expand Down
7 changes: 3 additions & 4 deletions src/adapter/breakpointPredictor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Event } from 'vscode';
import { EventEmitter } from '../common/events';
import { OutFiles } from '../common/fileGlobList';
import { ILogger, LogTag } from '../common/logging';
import { fixDriveLetterAndSlashes, forceForwardSlashes } from '../common/pathUtils';
import { fixDriveLetterAndSlashes } from '../common/pathUtils';
import { ISourceMapMetadata } from '../common/sourceMaps/sourceMap';
import { ISourceMapFactory } from '../common/sourceMaps/sourceMapFactory';
import {
Expand Down Expand Up @@ -216,10 +216,9 @@ export class TargetedBreakpointSearch extends BreakpointSearch {

// if some paths have not been found yet, do one operation to find all of them
if (toFind.length) {
const spSet = new Set(toFind.map(i => forceForwardSlashes(sourcePaths[i])));
const spSet = new Set(toFind.map(i => fixDriveLetterAndSlashes(sourcePaths[i])));
const entry = this.createMapping({
filter: (_, meta) =>
!meta || meta.discovered.some(d => spSet.has(forceForwardSlashes(d.resolvedPath))),
filter: (_, meta) => !meta || meta.discovered.some(d => spSet.has(d.resolvedPath)),
});
for (const i of toFind) {
this.sourcePathToCompiled.set(sourcePaths[i], entry);
Expand Down
14 changes: 9 additions & 5 deletions src/common/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,19 @@ export function properRelative(fromPath: string, toPath: string): string {
}

const splitRe = /\/|\\/;
const fileUriPrefix = 'file:///';

const isWindowsFileUri = (aPath: string) =>
aPath.startsWith(fileUriPrefix) && aPath[fileUriPrefix.length + 1] === ':';

export const properSplit = (path: string) => path.split(splitRe);

export function fixDriveLetter(aPath: string, uppercaseDriveLetter = false): string {
if (!aPath) return aPath;

if (aPath.match(/file:\/\/\/[A-Za-z]:/)) {
const prefixLen = 'file:///'.length;
aPath = 'file:///' + aPath[prefixLen].toLowerCase() + aPath.substr(prefixLen + 1);
if (isWindowsFileUri(aPath)) {
const prefixLen = fileUriPrefix.length;
aPath = fileUriPrefix + aPath[prefixLen].toLowerCase() + aPath.substr(prefixLen + 1);
} else if (isWindowsPath(aPath)) {
// If the path starts with a drive letter, ensure lowercase. VS Code uses a lowercase drive letter
const driveLetter = uppercaseDriveLetter ? aPath[0].toUpperCase() : aPath[0].toLowerCase();
Expand All @@ -179,8 +183,8 @@ export function fixDriveLetterAndSlashes(aPath: string, uppercaseDriveLetter = f
if (!aPath) return aPath;

aPath = fixDriveLetter(aPath, uppercaseDriveLetter);
if (aPath.match(/file:\/\/\/[A-Za-z]:/)) {
const prefixLen = 'file:///'.length;
if (isWindowsFileUri(aPath)) {
const prefixLen = fileUriPrefix.length;
aPath = aPath.substr(0, prefixLen + 1) + aPath.substr(prefixLen + 1).replace(/\//g, '\\');
} else if (isWindowsPath(aPath)) {
aPath = aPath.replace(/\//g, '\\');
Expand Down
14 changes: 14 additions & 0 deletions src/test/sources/pretty-print-sources-bps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
}
reason : changed
}
{
breakpoint : {
column : 1
id : <number>
line : 9
source : {
name : localhost꞉8001/pretty/ugly.js
path : ${workspaceFolder}/web/pretty/ugly.js
sourceReference : <number>
}
verified : true
}
reason : changed
}
{
allThreadsStopped : false
description : Paused on breakpoint
Expand Down
7 changes: 5 additions & 2 deletions src/test/sources/pretty-print.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ describe('pretty print sources', () => {
});
p.load();

p.log(await p.dap.once('breakpoint'));
const { threadId } = p.log(await p.dap.once('stopped'));
const stopped = p.dap.once('stopped');
for (let i = 0; i < 2; i++) {
p.log(await p.dap.once('breakpoint'));
}
const { threadId } = p.log(await stopped);
p.dap.prettyPrintSource({ source });
const pretty = p.dap.once('loadedSource');

Expand Down