Skip to content

Commit b64507e

Browse files
authored
fix: group node internals and WASM to clean up loaded sources view (#2073)
![](https://memes.peet.io/img/24-09-3dcf61d0-09e8-46e9-9ea7-d42b6b72396b.png)
1 parent 714bff3 commit b64507e

11 files changed

+450
-177
lines changed

package-lock.json

Lines changed: 401 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"@typescript-eslint/eslint-plugin": "^6.20.0",
116116
"@typescript-eslint/parser": "^6.20.0",
117117
"@vscode/dwarf-debugging": "^0.0.2",
118-
"@vscode/test-electron": "^2.3.9",
118+
"@vscode/test-electron": "^2.4.1",
119119
"chai": "^4.3.6",
120120
"chai-as-promised": "^7.1.1",
121121
"chai-string": "^1.5.0",

src/adapter/dwarf/wasmSymbolProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export interface IWasmWorkerFactory extends IDisposable {
4646
prompt(): void;
4747
}
4848

49+
export const ensureWATExtension = (path: string) => path.replace(/\.wasm$/i, '') + '.wat';
50+
4951
@injectable()
5052
export class WasmWorkerFactory implements IWasmWorkerFactory {
5153
private cdpCounter = 0;
@@ -362,7 +364,8 @@ class DecompiledWasmSymbols implements IWasmSymbols {
362364
protected readonly cdp: Cdp.Api,
363365
files: string[],
364366
) {
365-
files.push(this.decompiledUrl = event.url.replace('.wasm', '.wat'));
367+
this.decompiledUrl = ensureWATExtension(event.url);
368+
files.push(this.decompiledUrl);
366369
this.files = files;
367370
}
368371

src/adapter/scriptSkipper/implementation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ICdpApi } from '../../cdp/connection';
99
import { MapUsingProjection } from '../../common/datastructure/mapUsingProjection';
1010
import { EventEmitter } from '../../common/events';
1111
import { ILogger, LogTag } from '../../common/logging';
12-
import { node15InternalsPrefix } from '../../common/node15Internal';
12+
import { node15InternalsPrefix, nodeInternalsToken } from '../../common/node15Internal';
1313
import { memoizeLast, trailingEdgeThrottle, truthy } from '../../common/objUtils';
1414
import * as pathUtils from '../../common/pathUtils';
1515
import { getDeferred, IDeferred } from '../../common/promiseUtil';
@@ -50,7 +50,7 @@ function preprocessAuthoredGlobs(
5050
userSkipPatterns: ReadonlyArray<string>,
5151
): string[] {
5252
const authoredGlobs = userSkipPatterns
53-
.filter(pattern => !pattern.includes('<node_internals>'))
53+
.filter(pattern => !pattern.includes(nodeInternalsToken))
5454
.map(pattern =>
5555
urlUtils.isAbsolute(pattern)
5656
? urlUtils.absolutePathToFileUrlWithDetection(spr.rebaseLocalToRemote(pattern))

src/adapter/source.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { relative } from 'path';
77
import { URL } from 'url';
88
import Cdp from '../cdp/api';
99
import { checkContentHash } from '../common/hash/checkContentHash';
10+
import { node15InternalsPrefix, nodeInternalsToken } from '../common/node15Internal';
1011
import { once } from '../common/objUtils';
1112
import { forceForwardSlashes, isSubdirectoryOf } from '../common/pathUtils';
1213
import { delay, getDeferred, IDeferred } from '../common/promiseUtil';
@@ -327,7 +328,11 @@ export class Source {
327328
return 'repl';
328329
}
329330

330-
if (this.absolutePath.startsWith('<node_internals>')) {
331+
if (this.url.startsWith(node15InternalsPrefix)) {
332+
return nodeInternalsToken + '/' + this.url.slice(node15InternalsPrefix.length);
333+
}
334+
335+
if (this.absolutePath.startsWith(nodeInternalsToken)) {
331336
return this.absolutePath;
332337
}
333338

src/adapter/sourceContainer.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { sourceMapParseFailed } from '../dap/errors';
2323
import { IInitializeParams } from '../ioc-extras';
2424
import { IStatistics } from '../telemetry/classification';
2525
import { extractErrorDetails } from '../telemetry/dapTelemetryReporter';
26-
import { IWasmSymbolProvider, IWasmSymbols } from './dwarf/wasmSymbolProvider';
26+
import { ensureWATExtension, IWasmSymbolProvider, IWasmSymbols } from './dwarf/wasmSymbolProvider';
2727
import { IResourceProvider } from './resourceProvider';
2828
import { ScriptSkipper } from './scriptSkipper/implementation';
2929
import { IScriptSkipper } from './scriptSkipper/scriptSkipper';
@@ -706,23 +706,25 @@ export class SourceContainer {
706706

707707
const todo: Promise<unknown>[] = [];
708708
for (const url of symbols.files) {
709-
const absolutePath = await this.sourcePathResolver.urlToAbsolutePath({ url });
710-
const resolvedUrl = absolutePath ? utils.absolutePathToFileUrl(absolutePath) : url;
709+
let absolutePath: string | undefined;
710+
let resolvedUrl: string;
711+
let contentGetter: ContentGetter;
712+
if (url === symbols.decompiledUrl) {
713+
absolutePath = ensureWATExtension(compiled.absolutePath);
714+
resolvedUrl = ensureWATExtension(compiled.url);
715+
contentGetter = () => symbols.getDisassembly();
716+
} else {
717+
absolutePath = await this.sourcePathResolver.urlToAbsolutePath({ url });
718+
resolvedUrl = absolutePath ? utils.absolutePathToFileUrl(absolutePath) : url;
719+
contentGetter = () => this.resourceProvider.fetch(resolvedUrl).then(r => r.body);
720+
}
711721

712722
this.logger.verbose(LogTag.RuntimeSourceCreate, 'Creating wasm source from source map', {
713723
inputUrl: url,
714724
absolutePath,
715725
resolvedUrl,
716726
});
717727

718-
const fileUrl = absolutePath && utils.absolutePathToFileUrl(absolutePath);
719-
const contentGetter = url === symbols.decompiledUrl
720-
? () => symbols.getDisassembly()
721-
: () =>
722-
fileUrl
723-
? this.resourceProvider.fetch(fileUrl).then(r => r.body)
724-
: Promise.resolve(`Could not read ${url}`);
725-
726728
const source = new SourceFromMap(this, resolvedUrl, absolutePath, contentGetter);
727729
source.compiledToSourceUrl.set(compiled, url);
728730
compiled.sourceMap.sourceByUrl.set(url, source);

src/build/generate-contributions.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
preferredDebugTypes,
1818
} from '../common/contributionUtils';
1919
import { knownToolToken } from '../common/knownTools';
20+
import { nodeInternalsToken } from '../common/node15Internal';
2021
import { mapValues, sortKeys, walkObject } from '../common/objUtils';
2122
import {
2223
AnyLaunchConfiguration,
@@ -196,7 +197,7 @@ const baseConfigurationAttributes: ConfigurationAttributes<IBaseConfiguration> =
196197
skipFiles: {
197198
type: 'array',
198199
description: refString('browser.skipFiles.description'),
199-
default: ['<node_internals>/**'],
200+
default: ['${/**'],
200201
},
201202
smartStep: {
202203
type: 'boolean',
@@ -403,7 +404,7 @@ const nodeAttachConfig: IDebugger<INodeAttachConfiguration> = {
403404
request: 'attach',
404405
name: '${1:Attach}',
405406
port: 9229,
406-
skipFiles: ['<node_internals>/**'],
407+
skipFiles: [`${nodeInternalsToken}/**`],
407408
},
408409
},
409410
{
@@ -417,7 +418,7 @@ const nodeAttachConfig: IDebugger<INodeAttachConfiguration> = {
417418
port: 9229,
418419
localRoot: '^"\\${workspaceFolder}"',
419420
remoteRoot: '${3:Absolute path to the remote directory containing the program}',
420-
skipFiles: ['<node_internals>/**'],
421+
skipFiles: [`${nodeInternalsToken}/**`],
421422
},
422423
},
423424
{
@@ -428,7 +429,7 @@ const nodeAttachConfig: IDebugger<INodeAttachConfiguration> = {
428429
request: 'attach',
429430
name: '${1:Attach by Process ID}',
430431
processId: '^"\\${command:PickProcess}"',
431-
skipFiles: ['<node_internals>/**'],
432+
skipFiles: [`${nodeInternalsToken}/**`],
432433
},
433434
},
434435
],
@@ -510,7 +511,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
510511
request: 'launch',
511512
name: '${2:Launch Program}',
512513
program: '^"\\${workspaceFolder}/${1:app.js}"',
513-
skipFiles: ['<node_internals>/**'],
514+
skipFiles: [`${nodeInternalsToken}/**`],
514515
},
515516
},
516517
{
@@ -522,7 +523,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
522523
name: '${1:Launch via NPM}',
523524
runtimeExecutable: 'npm',
524525
runtimeArgs: ['run-script', 'debug'],
525-
skipFiles: ['<node_internals>/**'],
526+
skipFiles: [`${nodeInternalsToken}/**`],
526527
},
527528
},
528529
{
@@ -537,7 +538,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
537538
restart: true,
538539
console: 'integratedTerminal',
539540
internalConsoleOptions: 'neverOpen',
540-
skipFiles: ['<node_internals>/**'],
541+
skipFiles: [`${nodeInternalsToken}/**`],
541542
},
542543
},
543544
{
@@ -557,7 +558,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
557558
'^"\\${workspaceFolder}/${1:test}"',
558559
],
559560
internalConsoleOptions: 'openOnSessionStart',
560-
skipFiles: ['<node_internals>/**'],
561+
skipFiles: [`${nodeInternalsToken}/**`],
561562
},
562563
},
563564
{
@@ -571,7 +572,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
571572
args: ['${1:generator}'],
572573
console: 'integratedTerminal',
573574
internalConsoleOptions: 'neverOpen',
574-
skipFiles: ['<node_internals>/**'],
575+
skipFiles: [`${nodeInternalsToken}/**`],
575576
},
576577
},
577578
{
@@ -583,7 +584,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
583584
name: 'Gulp ${1:task}',
584585
program: '^"\\${workspaceFolder}/node_modules/gulp/bin/gulp.js"',
585586
args: ['${1:task}'],
586-
skipFiles: ['<node_internals>/**'],
587+
skipFiles: [`${nodeInternalsToken}/**`],
587588
},
588589
},
589590
{
@@ -595,7 +596,7 @@ const nodeLaunchConfig: IDebugger<INodeLaunchConfiguration> = {
595596
name: 'Electron Main',
596597
runtimeExecutable: '^"electron"',
597598
program: '^"\\${workspaceFolder}/main.js"',
598-
skipFiles: ['<node_internals>/**'],
599+
skipFiles: [`${nodeInternalsToken}/**`],
599600
},
600601
},
601602
],

src/common/node15Internal.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@
66
* URL prefix that Node 15 and onwards uses for its internals.
77
*/
88
export const node15InternalsPrefix = 'node:';
9+
10+
/**
11+
* Token the debugger uses to represent node internals.
12+
*/
13+
export const nodeInternalsToken = '<node_internals>';

src/configuration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { homedir } from 'os';
66
import { SourceMapTimeouts } from './adapter/sourceContainer';
77
import { DebugType } from './common/contributionUtils';
8+
import { nodeInternalsToken } from './common/node15Internal';
89
import { assertNever, filterValues } from './common/objUtils';
910
import Dap from './dap/api';
1011
import { AnyRestartOptions } from './targets/node/restartPolicy';
@@ -859,7 +860,7 @@ const nodeBaseDefaults: INodeBaseConfiguration = {
859860
resolveSourceMapLocations: ['**', '!**/node_modules/**'],
860861
autoAttachChildProcesses: true,
861862
runtimeSourcemapPausePatterns: [],
862-
skipFiles: ['<node_internals>/**'],
863+
skipFiles: [`${nodeInternalsToken}/**`],
863864
};
864865

865866
export const terminalBaseDefaults: ITerminalLaunchConfiguration = {

src/targets/node/nodeSourcePathResolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as path from 'path';
66
import { URL } from 'url';
77
import { IFsUtils } from '../../common/fsUtils';
88
import { ILogger } from '../../common/logging';
9+
import { nodeInternalsToken } from '../../common/node15Internal';
910
import { fixDriveLetterAndSlashes, properResolve } from '../../common/pathUtils';
1011
import { SourceMap } from '../../common/sourceMaps/sourceMap';
1112
import {
@@ -102,7 +103,7 @@ export class NodeSourcePathResolver extends SourcePathResolverBase<IOptions> {
102103
// require('cluster') will import a file simply named "cluster". For these
103104
// paths, prefix them as internal.
104105
else if (!path.isAbsolute(url)) {
105-
return `<node_internals>/${url}`;
106+
return `${nodeInternalsToken}/${url}`;
106107
} // Otherwise, use default overrides.
107108
else {
108109
url = this.sourceMapOverrides.apply(url);

src/ui/configuration/nodeDebugConfigurationResolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DebugType } from '../../common/contributionUtils';
1313
import { EnvironmentVars } from '../../common/environmentVars';
1414
import { findOpenPort } from '../../common/findOpenPort';
1515
import { existsInjected, IFsUtils, LocalFsUtils } from '../../common/fsUtils';
16+
import { nodeInternalsToken } from '../../common/node15Internal';
1617
import { forceForwardSlashes, isSubpathOrEqualTo } from '../../common/pathUtils';
1718
import { some } from '../../common/promiseUtil';
1819
import { getNormalizedBinaryName, nearestDirectoryWhere } from '../../common/urlUtils';
@@ -326,7 +327,7 @@ export async function createLaunchConfigFromContext(
326327
type: DebugType.Node,
327328
request: 'launch',
328329
name: l10n.t('Launch Program'),
329-
skipFiles: ['<node_internals>/**'],
330+
skipFiles: [`${nodeInternalsToken}/**`],
330331
};
331332

332333
if (existingConfig && existingConfig.noDebug) {

0 commit comments

Comments
 (0)