From bb134aa28986a6891ab005d57e7c59fb58fdb7dd Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Tue, 3 Aug 2021 12:32:58 -0700 Subject: [PATCH] chore: take ownership of the default launch types For #1065 --- .vscode/launch.json | 4 +- CHANGELOG.md | 5 +- COMMON_PROBLEMS.md | 16 ---- gulpfile.js | 12 +-- package-lock.json | 80 ------------------- package.json | 5 +- src/build/generate-contributions.ts | 64 +++++++++------ src/build/strings.ts | 3 +- src/common/contributionUtils.ts | 19 +++-- src/extension.ts | 49 +++++++----- .../nodeConfigurationProvider.test.ts | 4 +- .../baseConfigurationResolver.ts | 2 + src/vsDebugServer.ts | 3 +- 13 files changed, 94 insertions(+), 172 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 59d15e96d..c309bf814 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,7 +53,7 @@ }, { "name": "Extension", - "type": "extensionHost", + "type": "pwa-extensionHost", "request": "launch", "skipFiles": [ "/**" @@ -173,4 +173,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d31cc6bb..2464c6a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,11 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes here may be available in the [nightly release](https://github.com/microsoft/vscode-js-debug/#nightly-extension) before they're in stable. Note that the minor version (`v1.X.0`) corresponds to the VS Code version js-debug is shipped in, but the patch version (`v1.50.X`) is not meaningful. -## Nightly +## v1.60 (August 2021) +### v1.60.0 - 2021-08-03 + +- chore: take ownership of the default launch types ([#1065](https://github.com/microsoft/vscode-js-debug/issues/1065)) - fix: apply electron updates for debugging vscode webviews ([ref](https://github.com/microsoft/vscode/issues/128637)) ## v1.59 (July 2021) diff --git a/COMMON_PROBLEMS.md b/COMMON_PROBLEMS.md index 333363d0a..ee0ccd77d 100644 --- a/COMMON_PROBLEMS.md +++ b/COMMON_PROBLEMS.md @@ -41,19 +41,3 @@ You launch your app, but the debugger doesn't connect to it. You're using an old ### Solution We've seen some transient issues with early Node 10 point releases. To fix this we, recommend updating to a later Node 10 release (10.22.1 being the most recent at the time of writing), or to a newer version of Node altogether if nothing is keeping you on 10. - -## My configuration property shows as invalid - -### Symptoms - -You're adding a configuration property to your launch.json, but it shows an invalid, even if it works. - -### Solution - -This can happen for newly introduced options. To fix this, you should prefix your launch type with `pwa-`, for example: - -- `node` -> `pwa-node` -- `chrome` -> `pwa-chrome` -- `extensionHost` -> `pwa-extensionHost` - -This is needed because the old configuration types are still "owned" by the old debuggers, and just redirect to this new debugger. While most additional options will be blindly passed along, they don't appear the old schemas and some may not work. diff --git a/gulpfile.js b/gulpfile.js index bcd0a7a1d..f656bb6b6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,7 +8,6 @@ const gulp = require('gulp'); const minimist = require('minimist'); const nls = require('vscode-nls-dev'); const path = require('path'); -const replace = require('gulp-replace'); const sourcemaps = require('gulp-sourcemaps'); const tsb = require('gulp-tsb'); const rename = require('gulp-rename'); @@ -39,13 +38,6 @@ const distDir = 'dist'; const distSrcDir = `${distDir}/src`; const nodeTargetsDir = `targets/node`; -/** - * If --drop-in is set, commands and debug types will be set to 'chrome' and - * 'node', rendering them incompatible with the base debuggers. Useful - * to only set this to true to publish, and develop as namespaced extensions. - */ -const namespace = process.argv.includes('--drop-in') ? '' : 'pwa-'; - /** * Whether we're running a nightly build. */ @@ -86,7 +78,6 @@ async function readJson(file) { return JSON.parse(contents); } -const replaceNamespace = () => replace(/NAMESPACE\((.*?)\)/g, `${namespace}$1`); const tsProject = tsb.create('./tsconfig.json'); gulp.task('clean-assertions', () => del(['src/test/**/*.txt.actual'])); @@ -99,7 +90,6 @@ gulp.task('compile:ts', () => tsProject .src() .pipe(sourcemaps.init()) - .pipe(replaceNamespace()) .pipe(tsProject()) .pipe( sourcemaps.write('.', { @@ -162,7 +152,7 @@ gulp.task('compile:dynamic', async () => { gulp.task('compile:static', () => merge( - gulp.src(['LICENSE', 'package.json']).pipe(replaceNamespace()), + gulp.src(['LICENSE', 'package.json']), gulp.src(['resources/**/*', 'README.md', 'src/**/*.sh'], { base: '.' }), ).pipe(gulp.dest(buildDir)), ); diff --git a/package-lock.json b/package-lock.json index eccaa9521..1d6d87de6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2316,12 +2316,6 @@ "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==", "dev": true }, - "binaryextensions": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/binaryextensions/-/binaryextensions-2.3.0.tgz", - "integrity": "sha512-nAihlQsYGyc5Bwq6+EsubvANYGExeJKHDO3RjnvwU042fawQTQfM3Kxn7IHUXQOz4bzfwsGYYHGSvXyW4zOGLg==", - "dev": true - }, "bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", @@ -5779,27 +5773,6 @@ "integrity": "sha512-97Vba4KBzbYmR5VBs9mWmK+HwIf5mj+/zioxfZhOKeXtx5ZjBk57KFlePf5nxq9QsTtFl0ejnHE3zTC9MHXqyQ==", "dev": true }, - "gulp-replace": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/gulp-replace/-/gulp-replace-1.1.3.tgz", - "integrity": "sha512-HcPHpWY4XdF8zxYkDODHnG2+7a3nD/Y8Mfu3aBgMiCFDW3X2GiOKXllsAmILcxe3KZT2BXoN18WrpEFm48KfLQ==", - "dev": true, - "requires": { - "@types/node": "^14.14.41", - "@types/vinyl": "^2.0.4", - "istextorbinary": "^3.0.0", - "replacestream": "^4.0.3", - "yargs-parser": ">=5.0.0-security.0" - }, - "dependencies": { - "@types/node": { - "version": "14.17.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.4.tgz", - "integrity": "sha512-8kQ3+wKGRNN0ghtEn7EGps/B8CzuBz1nXZEIGGLP2GnwbqYn4dbTs7k+VKLTq1HvZLRCIDtN3Snx1Ege8B7L5A==", - "dev": true - } - } - }, "gulp-sourcemaps": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/gulp-sourcemaps/-/gulp-sourcemaps-3.0.0.tgz", @@ -6741,16 +6714,6 @@ "istanbul-lib-report": "^3.0.0" } }, - "istextorbinary": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/istextorbinary/-/istextorbinary-3.3.0.tgz", - "integrity": "sha512-Tvq1W6NAcZeJ8op+Hq7tdZ434rqnMx4CCZ7H0ff83uEloDvVbqAwaMTZcafKGJT0VHkYzuXUiCY4hlXQg6WfoQ==", - "dev": true, - "requires": { - "binaryextensions": "^2.2.0", - "textextensions": "^3.2.0" - } - }, "jest-worker": { "version": "27.0.2", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.0.2.tgz", @@ -10126,43 +10089,6 @@ "remove-trailing-separator": "^1.1.0" } }, - "replacestream": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/replacestream/-/replacestream-4.0.3.tgz", - "integrity": "sha512-AC0FiLS352pBBiZhd4VXB1Ab/lh0lEgpP+GGvZqbQh8a5cmXVoTe5EX/YeTFArnp4SRGTHh1qCHu9lGs1qG8sA==", - "dev": true, - "requires": { - "escape-string-regexp": "^1.0.3", - "object-assign": "^4.0.1", - "readable-stream": "^2.0.2" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - } - } - }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -11366,12 +11292,6 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, - "textextensions": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/textextensions/-/textextensions-3.3.0.tgz", - "integrity": "sha512-mk82dS8eRABNbeVJrEiN5/UMSCliINAuz8mkUwH4SwslkNP//gbEzlWNS5au0z5Dpx40SQxzqZevZkn+WYJ9Dw==", - "dev": true - }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index 66c7a8cfa..e9785391d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "description": "An extension for debugging Node.js programs and Chrome.", "license": "MIT", "engines": { - "vscode": "^1.58.0-insider", + "vscode": "^1.60.0-insider", "node": ">=10" }, "icon": "resources/logo.png", @@ -136,7 +136,6 @@ "gulp": "^4.0.2", "gulp-filter": "^7.0.0", "gulp-rename": "^2.0.0", - "gulp-replace": "^1.1.3", "gulp-sourcemaps": "^3.0.0", "gulp-tsb": "^4.0.6", "gulp-util": "^3.0.8", @@ -184,7 +183,7 @@ { "id": "jsBrowserBreakpoints", "name": "Browser breakpoints", - "when": "debugConfigurationType == 'NAMESPACE(chrome)'" + "when": "debugConfigurationType == 'pwa-chrome'" } ] }, diff --git a/src/build/generate-contributions.ts b/src/build/generate-contributions.ts index 8eb3e1d99..e86f4c2f3 100644 --- a/src/build/generate-contributions.ts +++ b/src/build/generate-contributions.ts @@ -11,6 +11,7 @@ import { Contributions, DebugType, IConfigurationTypes, + preferredDebugTypes, } from '../common/contributionUtils'; import { knownToolToken } from '../common/knownTools'; import { mapValues, sortKeys, walkObject } from '../common/objUtils'; @@ -1038,39 +1039,50 @@ export const debuggers = [ function buildDebuggers() { // eslint-disable-next-line const output: any[] = []; - for (const d of debuggers) { - let entry = output.find(o => o.type === d.type); - if (!entry) { - // eslint-disable-next-line - const { request, configurationAttributes, required, defaults, ...rest } = d; - entry = { - ...rest, - aiKey: appInsightsKey, - configurationAttributes: {}, - configurationSnippets: [], - }; - output.push(entry); + const ensureEntryForType = (type: string, d: typeof debuggers[0]) => { + let entry = output.find(o => o.type === type); + if (entry) { + return entry; } - entry.configurationSnippets.push(...d.configurationSnippets); - entry.configurationAttributes[d.request] = { - required: d.required, - properties: mapValues( - d.configurationAttributes as { [key: string]: DescribedAttribute }, - ({ docDefault: _, ...attrs }) => attrs, - ), + // eslint-disable-next-line + const { request, configurationAttributes, required, defaults, ...rest } = d; + entry = { + ...rest, + type, + aiKey: appInsightsKey, + configurationAttributes: {}, + configurationSnippets: [], }; + output.push(entry); + return entry; + }; + + for (const d of debuggers) { + const primary = ensureEntryForType(d.type, d); + const entries = [primary]; + const preferred = preferredDebugTypes.get(d.type); + if (preferred) { + entries.unshift(ensureEntryForType(preferred, d)); + } + + entries[0].configurationSnippets.push(...d.configurationSnippets); + + for (const entry of entries) { + entry.configurationAttributes[d.request] = { + required: d.required, + properties: mapValues( + d.configurationAttributes as { [key: string]: DescribedAttribute }, + ({ docDefault: _, ...attrs }) => attrs, + ), + }; + } } return walkObject(output, sortKeys); } const configurationSchema: ConfigurationAttributes = { - [Configuration.UsePreviewDebugger]: { - type: 'boolean', - default: true, - description: refString('configuration.usePreview'), - }, [Configuration.NpmScriptLens]: { enum: ['top', 'all', 'never'], default: 'top', @@ -1408,7 +1420,9 @@ if (require.main === module) { }, activationEvents: [ ...[...allCommands].map(cmd => `onCommand:${cmd}`), - ...debuggers.map(dbg => `onDebugResolve:${dbg.type}`), + ...[...debuggers.map(dbg => dbg.type), ...preferredDebugTypes.keys()].map( + t => `onDebugResolve:${t}`, + ), `onWebviewPanel:${Contributions.DiagnosticsView}`, ], contributes: { diff --git a/src/build/strings.ts b/src/build/strings.ts index 89e0bdfc2..b0fb5fff4 100644 --- a/src/build/strings.ts +++ b/src/build/strings.ts @@ -275,7 +275,6 @@ const strings = { 'Where a "Run" and "Debug" code lens should be shown in your npm scripts. It may be on "all", scripts, on "top" of the script section, or "never".', 'configuration.terminalOptions': 'Default launch options for the JavaScript debug terminal and npm scripts.', - 'configuration.usePreview': 'Use the new in-preview JavaScript debugger for Node.js and Chrome.', 'configuration.suggestPrettyPrinting': 'Whether to suggest pretty printing JavaScript code that looks minified when you step into it.', 'configuration.automaticallyTunnelRemoteServer': @@ -297,7 +296,7 @@ const strings = { 'Auto attach to every Node.js process launched in the terminal.', 'configuration.autoAttachMode.disabled': 'Auto attach is disabled and not shown in status bar.', 'configuration.breakOnConditionalError': - 'Whether to stop when conditional breakpoints throw an error. Note: your launch.json `type` must be prefixed with `pwa-` to use this, such as `pwa-node`.', + 'Whether to stop when conditional breakpoints throw an error.', 'configuration.unmapMissingSources': "Configures whether sourcemapped file where the original file can't be read will automatically be unmapped. If this is false (default), a prompt is shown.", 'configuration.defaultRuntimeExecutables': diff --git a/src/common/contributionUtils.ts b/src/common/contributionUtils.ts index 45a879601..11873b9e2 100644 --- a/src/common/contributionUtils.ts +++ b/src/common/contributionUtils.ts @@ -19,7 +19,7 @@ export const enum Contributions { export const enum Commands { AddCustomBreakpoints = 'extension.js-debug.addCustomBreakpoints', - AttachProcess = 'extension.NAMESPACE(node-debug).attachNodeProcess', + AttachProcess = 'extension.pwa-node-debug.attachNodeProcess', AutoAttachClearVariables = 'extension.js-debug.clearAutoAttachVariables', AutoAttachSetVariables = 'extension.js-debug.setAutoAttachVariables', AutoAttachToProcess = 'extension.js-debug.autoAttachToProcess', @@ -41,12 +41,19 @@ export const enum Commands { OpenEdgeDevTools = 'extension.js-debug.openEdgeDevTools', } +export const preferredDebugTypes: ReadonlyMap = new Map([ + [DebugType.Node, 'node'], + [DebugType.Chrome, 'chrome'], + [DebugType.ExtensionHost, 'extensionHost'], + [DebugType.Edge, 'msedge'], +]); + export const enum DebugType { - ExtensionHost = 'NAMESPACE(extensionHost)', + ExtensionHost = 'pwa-extensionHost', Terminal = 'node-terminal', - Node = 'NAMESPACE(node)', - Chrome = 'NAMESPACE(chrome)', - Edge = 'NAMESPACE(msedge)', + Node = 'pwa-node', + Chrome = 'pwa-chrome', + Edge = 'pwa-msedge', } // constructing it this way makes sure we can't forget to add a type: @@ -104,7 +111,6 @@ export const enum AutoAttachMode { Always = 'always', } export const enum Configuration { - UsePreviewDebugger = 'debug.javascript.usePreview', NpmScriptLens = 'debug.javascript.codelens.npmScripts', TerminalDebugConfig = 'debug.javascript.terminalOptions', PickAndAttachDebugOptions = 'debug.javascript.pickAndAttachOptions', @@ -126,7 +132,6 @@ export type DebugByLinkState = 'on' | 'off' | 'always'; * Type map for {@link Configuration} properties. */ export interface IConfigurationTypes { - [Configuration.UsePreviewDebugger]: boolean; [Configuration.NpmScriptLens]: 'all' | 'top' | 'never'; [Configuration.TerminalDebugConfig]: Partial; [Configuration.PickAndAttachDebugOptions]: Partial; diff --git a/src/extension.ts b/src/extension.ts index f8c1207af..f2ece2c66 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,7 +4,13 @@ import { tmpdir } from 'os'; import * as vscode from 'vscode'; -import { allDebugTypes, Commands, registerCommand } from './common/contributionUtils'; +import { + allDebugTypes, + Commands, + DebugType, + preferredDebugTypes, + registerCommand, +} from './common/contributionUtils'; import { extensionId } from './configuration'; import { createGlobalContainer } from './ioc'; import { IExtensionContribution } from './ioc-extras'; @@ -45,28 +51,27 @@ export function activate(context: vscode.ExtensionContext) { registerCommand(vscode.commands, Commands.ToggleSkipping, toggleSkippingFile), ); - context.subscriptions.push( - ...services - .getAll(IDebugConfigurationResolver) - .map(provider => - vscode.debug.registerDebugConfigurationProvider( - provider.type, - provider as vscode.DebugConfigurationProvider, - ), - ), + const debugResolvers = services.getAll(IDebugConfigurationResolver); + for (const resolver of debugResolvers) { + const cast = resolver as vscode.DebugConfigurationProvider; + context.subscriptions.push( + vscode.debug.registerDebugConfigurationProvider(resolver.type, cast), + ); - ...services - .getAll(IDebugConfigurationProvider) - .map(provider => - vscode.debug.registerDebugConfigurationProvider( - provider.type, - provider as vscode.DebugConfigurationProvider, - vscode.DebugConfigurationProviderTriggerKind !== undefined - ? provider.triggerKind - : undefined, - ), - ), - ); + const preferred = preferredDebugTypes.get(resolver.type as DebugType); + if (preferred) { + context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(preferred, cast)); + } + } + + const debugProviders = services.getAll(IDebugConfigurationProvider); + for (const provider of debugProviders) { + vscode.debug.registerDebugConfigurationProvider( + provider.type, + provider as vscode.DebugConfigurationProvider, + vscode.DebugConfigurationProviderTriggerKind !== undefined ? provider.triggerKind : undefined, + ); + } const sessionManager = new VSCodeSessionManager(services); context.subscriptions.push( diff --git a/src/test/extension/nodeConfigurationProvider.test.ts b/src/test/extension/nodeConfigurationProvider.test.ts index 89ba49138..32f708ae0 100644 --- a/src/test/extension/nodeConfigurationProvider.test.ts +++ b/src/test/extension/nodeConfigurationProvider.test.ts @@ -111,7 +111,7 @@ describe('NodeDebugConfigurationProvider', () => { result.cwd = result.cwd!.toLowerCase(); expect(result).to.containSubset({ - type: 'pwa-node', + type: DebugType.Node, cwd: testFixturesDir.toLowerCase(), name: 'Launch Program', program: join('${workspaceFolder}', 'hello.js'), @@ -129,7 +129,7 @@ describe('NodeDebugConfigurationProvider', () => { result.cwd = result.cwd!.toLowerCase(); expect(result).to.containSubset({ - type: 'pwa-node', + type: DebugType.Node, cwd: testFixturesDir.toLowerCase(), name: 'Launch Program', program: join('${workspaceFolder}', 'hello.js'), diff --git a/src/ui/configuration/baseConfigurationResolver.ts b/src/ui/configuration/baseConfigurationResolver.ts index 0c353590b..0522afa9e 100644 --- a/src/ui/configuration/baseConfigurationResolver.ts +++ b/src/ui/configuration/baseConfigurationResolver.ts @@ -43,6 +43,8 @@ export abstract class BaseConfigurationResolver { + config.type = this.getType(); // ensure type is set for aliased configurations + if ('__pendingTargetId' in config) { return config as T; } diff --git a/src/vsDebugServer.ts b/src/vsDebugServer.ts index 7981de74c..e92d2c17d 100644 --- a/src/vsDebugServer.ts +++ b/src/vsDebugServer.ts @@ -14,6 +14,7 @@ import 'reflect-metadata'; import { Readable, Writable } from 'stream'; import { DebugConfiguration } from 'vscode'; import * as nls from 'vscode-nls'; +import { DebugType } from './common/contributionUtils'; import { getDeferred, IDeferred } from './common/promiseUtil'; import { IPseudoAttachConfiguration } from './configuration'; import DapConnection from './dap/connection'; @@ -63,7 +64,7 @@ class VsDebugServer implements ISessionLauncher { 'root', localize('session.rootSessionName', 'JavaScript debug adapter'), deferredConnection.promise, - { type: 'pwa-chrome', name: 'root', request: 'launch' }, + { type: DebugType.Chrome, name: 'root', request: 'launch' }, ); if (inputStream && outputStream) { this.launchRootFromExisting(deferredConnection, rootSession, inputStream, outputStream);