From 99d583ff24c2c4f6663e86f81524fd6fe7d84ce2 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 11:02:09 +0100 Subject: [PATCH 01/25] start progress on enhanced logging --- .../src/debugging/DebugAdapter.ts | 188 +++++++++++++++++- .../src/debugging/variableStore.ts | 36 ++++ 2 files changed, 214 insertions(+), 10 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index b25456b02..88b9bf1b8 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -25,6 +25,12 @@ import { VariableStore } from "./variableStore"; import { SourceMapsRegistry } from "./SourceMapsRegistry"; import { BreakpointsController } from "./BreakpointsController"; import { CDPSession } from "./CDPSession"; +import Cdp from "vscode-js-debug/src/cdp/api"; +import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes"; +import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; +import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; +import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; +import { getSourceSuffix } from "vscode-js-debug/src/adapter/templates"; function typeToCategory(type: string) { switch (type) { @@ -143,7 +149,64 @@ export class DebugAdapter extends DebugSession { } }; + async formatDefaultString ( + // thread: Thread, + args: ReadonlyArray, + ) { + const useMessageFormat = args.length > 1 && args[0].type === 'string'; + const formatResult = useMessageFormat + ? externalFormatMessage(args[0].value, args.slice(1) as AnyObject[], messageFormatters) + : externalFormatMessage('', args as AnyObject[], messageFormatters); + + const output = formatResult.result + '\n'; + + if (formatResult.usedAllSubs && !args.some(previewAsObject)) { + return { output }; + } else { + return await this.formatComplexStringOutput(output, args); + } + }; + + async formatComplexStringOutput ( + // thread: Thread, + output: string, + args: ReadonlyArray, + ) { + const outputVar = await this.createVariableForOutputEvent(args as CDPRemoteObject[]); + + return { output, variablesReference: outputVar }; + }; + + private async handleConsoleAPICall(message: any) { + const string = 'string'; + const object = { key: 'value', key2: 'value2' }; + const set = new Set([1, 2, 3, 3]); + const array100 = new Array(100).fill(0).map((_, i) => i); + const array1000 = new Array(1000).fill(0).map((_, i) => i); + const int = 1; + const float = 1.1; + const func = function() {}; + const anonymousFunc = () => {}; + + + // console.log(string); + // console.log(object); + // console.log(set); + // console.log(array100); + // console.log(array1000); + // console.log(int); + // console.log(float); + // console.log(func); + // console.log(anonymousFunc); + // console.log(string, object, set, + // array100, + // array1000, + // int, + // float, + // func, + // anonymousFunc); + // We wrap console calls and add stack information as last three arguments, however // some logs may baypass that, especially when printed in initialization phase, so we // need to detect whether the wrapper has added the stack info or not @@ -153,6 +216,7 @@ export class DebugAdapter extends DebugSession { // console. const argsLen = message.params.args.length; let output: OutputEvent; + if (argsLen > 0 && message.params.args[0].value === "__RNIDE_INTERNAL") { // We return here to avoid passing internal logs to the user debug console, // but they will still be visible in metro log feed. @@ -171,20 +235,38 @@ export class DebugAdapter extends DebugSession { generatedColumn1Based - 1 ); - const variablesRefDapID = this.createVariableForOutputEvent(message.params.args.slice(0, -3)); + const testOutput = await this.formatDefaultString(message.params.args.slice(0, -3)); output = new OutputEvent( - (await formatMessage(message.params.args.slice(0, -3))) + "\n", + // (await formatMessage(message.params.args.slice(0, -3))) + "\n", + testOutput.output, typeToCategory(message.params.type) ); + + // Old method to compare + // output = new OutputEvent( + // (await formatMessage(message.params.args.slice(0, -3))) + "\n", + // typeToCategory(message.params.type) + // ); + // output.body = { + // ...output.body, + // //@ts-ignore source, line, column and group are valid fields + // source: new Source(sourceURL, sourceURL), + // line: this.linesStartAt1 ? lineNumber1Based : lineNumber1Based - 1, + // column: this.columnsStartAt1 ? columnNumber0Based + 1 : columnNumber0Based, + // variablesReference: variablesRefDapID, + // }; + + // this.sendEvent(output); + output.body = { - ...output.body, + ...testOutput, //@ts-ignore source, line, column and group are valid fields source: new Source(sourceURL, sourceURL), line: this.linesStartAt1 ? lineNumber1Based : lineNumber1Based - 1, column: this.columnsStartAt1 ? columnNumber0Based + 1 : columnNumber0Based, - variablesReference: variablesRefDapID, }; + } else { const variablesRefDapID = this.createVariableForOutputEvent(message.params.args); @@ -204,21 +286,73 @@ export class DebugAdapter extends DebugSession { ); } - private createVariableForOutputEvent(args: CDPRemoteObject[]) { - // we create empty object that is needed for DAP OutputEvent to display - // collapsed args properly, the object references the array of args array - const argsObjectDapID = this.variableStore.pushReplVariable( - args.map((arg: CDPRemoteObject, index: number) => { + private async createVariableForOutputEvent(args: CDPRemoteObject[]) { + const prepareVariables = await Promise.all( + args.map(async (arg: CDPRemoteObject, index: number) => { + // if (arg.type === "object") { + // if (arg?.subtype === "array") { + // const match = String(arg.description).match(/\(([0-9]+)\)/); + // const length = match ? +match[1] : 0; + + // // if (length < 100) { + // // arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); + // // arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); + + // // return [{ name: `arg${index}`, value: arg }]; + // // } + + // // const stackObjectProperties = await this.variableStore.getProperties( + // // this.variableStore.adaptCDPObjectId(arg.objectId), + // // (params: object) => { + // // const response = this.cdpSession.sendCDPMessage("Runtime.getProperties", params); + // // return response; + // // } + // // ); + + // // console.log("LOG PROPERTIES -> ", stackObjectProperties); + + // // const chunkSize = 100; + // // const chunks = []; + // // for (let i = 0; i < length; i += chunkSize) { + // // const chunk = stackObjectProperties.slice(i, i + chunkSize); + // // // do whatever + // // const chunkVariablesObjectDapID = this.variableStore.pushReplVariable(chunk.map(value => ({ + // // value: value.value, + // // name: value.name, + // // }))); + + // // chunks.push({ + // // name: `[${i}..${i + chunkSize - 1}]`, + // // value: { + // // type: "object", + // // objectId: chunkVariablesObjectDapID.toString(), + // // description: '', + // // }, + // // }); + // // } + + // arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); + // arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); + // return { name: `arg${index}`, value: arg, indexedVariables: length > 100 ? length : undefined, + // namedVariables: length > 100 ? 1 : undefined}; + // } + // } + if (arg.type === "object") { + arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); } + return { name: `arg${index}`, value: arg }; }) ); + // we create empty object that is needed for DAP OutputEvent to display + // collapsed args properly, the object references the array of args array + const argsObjectDapID = this.variableStore.pushReplVariable(prepareVariables); return this.variableStore.pushReplVariable([ { - name: "", + name: "", value: { type: "object", objectId: argsObjectDapID.toString(), @@ -413,6 +547,40 @@ export class DebugAdapter extends DebugSession { return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); } ); + + if (args.filter === "indexed") { + const fn = function( + this: unknown[], + start: number, + count: number, + ) { + const result = {}; + const from = start === -1 ? 0 : start; + const to = count === -1 ? this.length : start + count; + for (let i = from; i < to && i < this.length; ++i) { + const descriptor = Object.getOwnPropertyDescriptor(this, i); + if (descriptor) { + Object.defineProperty(result, i, descriptor); + } + } + + return result; + }; + let stringified = '' + fn; + const endIndex = stringified.lastIndexOf('}'); + stringified = stringified.slice(0, endIndex) + getSourceSuffix(undefined) + + stringified.slice(endIndex); + + const partialValue = await this.cdpSession.sendCDPMessage("Runtime.callFunctionOn", { + objectId: args.variablesReference, + functionDeclaration: stringified.replaceAll('\n', ''), + arguments: [args.start, args.count], + }); + + console.log('partialValue', partialValue); + } + + this.sendResponse(response); } diff --git a/packages/vscode-extension/src/debugging/variableStore.ts b/packages/vscode-extension/src/debugging/variableStore.ts index 88dc233bb..14e1fd1e9 100644 --- a/packages/vscode-extension/src/debugging/variableStore.ts +++ b/packages/vscode-extension/src/debugging/variableStore.ts @@ -13,6 +13,27 @@ export class VariableStore { private CDPtoDAPObjectIdMap: Map = new Map(); private DAPtoCDPObjectIdMap: Map = new Map(); + + public async getProperties( + id: number, + fetchProperties: (params: object) => Promise, + ) { + let properties: CDPPropertyDescriptor[]; + if (this.DAPtoCDPObjectIdMap.has(id)) { + const cdpObjectId = this.convertDAPObjectIdToCDP(id); + properties = ( + await fetchProperties({ + objectId: cdpObjectId, + ownProperties: true, + }) + ).result as CDPPropertyDescriptor[]; + } else { + properties = this.replVariables.get(id) as CDPPropertyDescriptor[]; + } + + return properties; + } + /** * If exist it returns a local variables if not it tries to fetch them from cdp. * @param id VariableId. @@ -51,6 +72,21 @@ export class VariableStore { } else { variablesReference = Number(prop.value.objectId); } + + if (prop.value.subtype === "array") { + const match = String(prop.value.description).match(/\(([0-9]+)\)/); + const length = match ? +match[1] : 0; + + return { + name: prop.name, + value, + type: "object", + variablesReference, + indexedVariables: length > 100 ? length : undefined, + namedVariables: length > 100 ? 1 : undefined + }; + } + return { name: prop.name, value, From 2774a0e2f6e9206e22852df2af775b17dd1f8a4e Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 12:30:09 +0100 Subject: [PATCH 02/25] Fix cdp function call --- .../src/debugging/DebugAdapter.ts | 38 +++++++++++++------ .../src/debugging/variableStore.ts | 1 + 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 88b9bf1b8..5e36390b7 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -30,7 +30,6 @@ import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; -import { getSourceSuffix } from "vscode-js-debug/src/adapter/templates"; function typeToCategory(type: string) { switch (type) { @@ -566,18 +565,35 @@ export class DebugAdapter extends DebugSession { return result; }; + let stringified = '' + fn; - const endIndex = stringified.lastIndexOf('}'); - stringified = stringified.slice(0, endIndex) + getSourceSuffix(undefined) - + stringified.slice(endIndex); - - const partialValue = await this.cdpSession.sendCDPMessage("Runtime.callFunctionOn", { - objectId: args.variablesReference, - functionDeclaration: stringified.replaceAll('\n', ''), - arguments: [args.start, args.count], - }); + // const endIndex = stringified.lastIndexOf('}'); + // stringified = stringified.slice(0, endIndex) + getSourceSuffix(undefined) + // + stringified.slice(endIndex); + try { + const partialValue = await this.cdpSession.sendCDPMessage("Runtime.callFunctionOn", { + objectId: args.variablesReference.toString(), + functionDeclaration: stringified.replaceAll("\n", ""), + arguments: [args.start, args.count].map(value => ({ value })), + }); + + console.log('partialValue', partialValue); + const cdpValue = this.variableStore.adaptCDPObjectId(partialValue.result.objectId); + + response.body.variables = await this.variableStore.get( + cdpValue, + (params: object) => { + return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); + } + ); + - console.log('partialValue', partialValue); + this.sendResponse(response); + + return; + } catch(e) { + console.log('error', e); + } } diff --git a/packages/vscode-extension/src/debugging/variableStore.ts b/packages/vscode-extension/src/debugging/variableStore.ts index 14e1fd1e9..3122b2240 100644 --- a/packages/vscode-extension/src/debugging/variableStore.ts +++ b/packages/vscode-extension/src/debugging/variableStore.ts @@ -51,6 +51,7 @@ export class VariableStore { await fetchProperties({ objectId: cdpObjectId, ownProperties: true, + generatePreview: true, }) ).result as CDPPropertyDescriptor[]; isCDPObject = true; From 8b85e6e8466e32e11f422feaaa7ad8d623b4edeb Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 16:01:26 +0100 Subject: [PATCH 03/25] working solution --- .../src/debugging/DebugAdapter.ts | 28 +++++++++++++------ .../src/debugging/variableStore.ts | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 5e36390b7..c386e9d83 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -30,6 +30,7 @@ import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; +import { getSourceSuffix } from "vscode-js-debug/src/adapter/templates"; function typeToCategory(type: string) { switch (type) { @@ -540,12 +541,19 @@ export class DebugAdapter extends DebugSession { args: DebugProtocol.VariablesArguments ): Promise { response.body = response.body || {}; - response.body.variables = await this.variableStore.get( - args.variablesReference, - (params: object) => { - return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); - } - ); + response.body.variables = []; + + if (args.filter !== "indexed" && args.filter !== "named") { + response.body.variables = await this.variableStore.get( + args.variablesReference, + (params: object) => { + return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); + } + ); + } + + console.log('args', args); + console.log('response', response); if (args.filter === "indexed") { const fn = function( @@ -572,15 +580,15 @@ export class DebugAdapter extends DebugSession { // + stringified.slice(endIndex); try { const partialValue = await this.cdpSession.sendCDPMessage("Runtime.callFunctionOn", { - objectId: args.variablesReference.toString(), - functionDeclaration: stringified.replaceAll("\n", ""), + functionDeclaration: stringified, + objectId: this.variableStore.convertDAPObjectIdToCDP(args.variablesReference), arguments: [args.start, args.count].map(value => ({ value })), }); console.log('partialValue', partialValue); const cdpValue = this.variableStore.adaptCDPObjectId(partialValue.result.objectId); - response.body.variables = await this.variableStore.get( + const properties = await this.variableStore.get( cdpValue, (params: object) => { return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); @@ -588,6 +596,8 @@ export class DebugAdapter extends DebugSession { ); + response.body.variables = properties; + this.sendResponse(response); return; diff --git a/packages/vscode-extension/src/debugging/variableStore.ts b/packages/vscode-extension/src/debugging/variableStore.ts index 3122b2240..ad505eda0 100644 --- a/packages/vscode-extension/src/debugging/variableStore.ts +++ b/packages/vscode-extension/src/debugging/variableStore.ts @@ -140,7 +140,7 @@ export class VariableStore { return dapObjectID; } - private convertDAPObjectIdToCDP(dapObjectID: number) { + public convertDAPObjectIdToCDP(dapObjectID: number) { return this.DAPtoCDPObjectIdMap.get(dapObjectID); } } From a4918683406061178dc500cdb8031e7d2d9e477f Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 16:44:50 +0100 Subject: [PATCH 04/25] clean code --- .gitmodules | 3 + .../src/debugging/DebugAdapter.ts | 168 ++---------------- .../vscode-extension/src/debugging/cdp.ts | 1 + .../src/debugging/templates/getArraySlots.ts | 20 +++ .../src/debugging/templates/index.ts | 1 + .../src/debugging/variableStore.ts | 22 +-- packages/vscode-js-debug | 1 + 7 files changed, 44 insertions(+), 172 deletions(-) create mode 100644 packages/vscode-extension/src/debugging/templates/getArraySlots.ts create mode 100644 packages/vscode-extension/src/debugging/templates/index.ts create mode 160000 packages/vscode-js-debug diff --git a/.gitmodules b/.gitmodules index 4f501af9c..504d5842e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "packages/simulator-server"] path = packages/simulator-server url = git@github.com:software-mansion-labs/simulator-server.git +[submodule "packages/vscode-js-debug"] + path = packages/vscode-js-debug + url = git@github.com:software-mansion-labs/vscode-js-debug.git diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index c386e9d83..6d95f19d0 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -30,7 +30,7 @@ import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; -import { getSourceSuffix } from "vscode-js-debug/src/adapter/templates"; +import getArraySlots from "./templates"; function typeToCategory(type: string) { switch (type) { @@ -149,8 +149,8 @@ export class DebugAdapter extends DebugSession { } }; + // Based on https://github.com/microsoft/vscode-js-debug/blob/3be255753c458f231e32c9ef5c60090236780060/src/adapter/console/textualMessage.ts#L83 async formatDefaultString ( - // thread: Thread, args: ReadonlyArray, ) { const useMessageFormat = args.length > 1 && args[0].type === 'string'; @@ -163,50 +163,13 @@ export class DebugAdapter extends DebugSession { if (formatResult.usedAllSubs && !args.some(previewAsObject)) { return { output }; } else { - return await this.formatComplexStringOutput(output, args); - } - }; - - async formatComplexStringOutput ( - // thread: Thread, - output: string, - args: ReadonlyArray, - ) { - const outputVar = await this.createVariableForOutputEvent(args as CDPRemoteObject[]); + const outputVar = await this.createVariableForOutputEvent(args as CDPRemoteObject[]); - return { output, variablesReference: outputVar }; + return { output, variablesReference: outputVar }; + } }; - private async handleConsoleAPICall(message: any) { - const string = 'string'; - const object = { key: 'value', key2: 'value2' }; - const set = new Set([1, 2, 3, 3]); - const array100 = new Array(100).fill(0).map((_, i) => i); - const array1000 = new Array(1000).fill(0).map((_, i) => i); - const int = 1; - const float = 1.1; - const func = function() {}; - const anonymousFunc = () => {}; - - - // console.log(string); - // console.log(object); - // console.log(set); - // console.log(array100); - // console.log(array1000); - // console.log(int); - // console.log(float); - // console.log(func); - // console.log(anonymousFunc); - // console.log(string, object, set, - // array100, - // array1000, - // int, - // float, - // func, - // anonymousFunc); - // We wrap console calls and add stack information as last three arguments, however // some logs may baypass that, especially when printed in initialization phase, so we // need to detect whether the wrapper has added the stack info or not @@ -238,27 +201,10 @@ export class DebugAdapter extends DebugSession { const testOutput = await this.formatDefaultString(message.params.args.slice(0, -3)); output = new OutputEvent( - // (await formatMessage(message.params.args.slice(0, -3))) + "\n", testOutput.output, typeToCategory(message.params.type) ); - // Old method to compare - // output = new OutputEvent( - // (await formatMessage(message.params.args.slice(0, -3))) + "\n", - // typeToCategory(message.params.type) - // ); - // output.body = { - // ...output.body, - // //@ts-ignore source, line, column and group are valid fields - // source: new Source(sourceURL, sourceURL), - // line: this.linesStartAt1 ? lineNumber1Based : lineNumber1Based - 1, - // column: this.columnsStartAt1 ? columnNumber0Based + 1 : columnNumber0Based, - // variablesReference: variablesRefDapID, - // }; - - // this.sendEvent(output); - output.body = { ...testOutput, //@ts-ignore source, line, column and group are valid fields @@ -289,55 +235,6 @@ export class DebugAdapter extends DebugSession { private async createVariableForOutputEvent(args: CDPRemoteObject[]) { const prepareVariables = await Promise.all( args.map(async (arg: CDPRemoteObject, index: number) => { - // if (arg.type === "object") { - // if (arg?.subtype === "array") { - // const match = String(arg.description).match(/\(([0-9]+)\)/); - // const length = match ? +match[1] : 0; - - // // if (length < 100) { - // // arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); - // // arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); - - // // return [{ name: `arg${index}`, value: arg }]; - // // } - - // // const stackObjectProperties = await this.variableStore.getProperties( - // // this.variableStore.adaptCDPObjectId(arg.objectId), - // // (params: object) => { - // // const response = this.cdpSession.sendCDPMessage("Runtime.getProperties", params); - // // return response; - // // } - // // ); - - // // console.log("LOG PROPERTIES -> ", stackObjectProperties); - - // // const chunkSize = 100; - // // const chunks = []; - // // for (let i = 0; i < length; i += chunkSize) { - // // const chunk = stackObjectProperties.slice(i, i + chunkSize); - // // // do whatever - // // const chunkVariablesObjectDapID = this.variableStore.pushReplVariable(chunk.map(value => ({ - // // value: value.value, - // // name: value.name, - // // }))); - - // // chunks.push({ - // // name: `[${i}..${i + chunkSize - 1}]`, - // // value: { - // // type: "object", - // // objectId: chunkVariablesObjectDapID.toString(), - // // description: '', - // // }, - // // }); - // // } - - // arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); - // arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); - // return { name: `arg${index}`, value: arg, indexedVariables: length > 100 ? length : undefined, - // namedVariables: length > 100 ? 1 : undefined}; - // } - // } - if (arg.type === "object") { arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); @@ -543,41 +440,9 @@ export class DebugAdapter extends DebugSession { response.body = response.body || {}; response.body.variables = []; - if (args.filter !== "indexed" && args.filter !== "named") { - response.body.variables = await this.variableStore.get( - args.variablesReference, - (params: object) => { - return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); - } - ); - } - - console.log('args', args); - console.log('response', response); - if (args.filter === "indexed") { - const fn = function( - this: unknown[], - start: number, - count: number, - ) { - const result = {}; - const from = start === -1 ? 0 : start; - const to = count === -1 ? this.length : start + count; - for (let i = from; i < to && i < this.length; ++i) { - const descriptor = Object.getOwnPropertyDescriptor(this, i); - if (descriptor) { - Object.defineProperty(result, i, descriptor); - } - } - - return result; - }; + const stringified = '' + getArraySlots; - let stringified = '' + fn; - // const endIndex = stringified.lastIndexOf('}'); - // stringified = stringified.slice(0, endIndex) + getSourceSuffix(undefined) - // + stringified.slice(endIndex); try { const partialValue = await this.cdpSession.sendCDPMessage("Runtime.callFunctionOn", { functionDeclaration: stringified, @@ -585,27 +450,28 @@ export class DebugAdapter extends DebugSession { arguments: [args.start, args.count].map(value => ({ value })), }); - console.log('partialValue', partialValue); - const cdpValue = this.variableStore.adaptCDPObjectId(partialValue.result.objectId); - const properties = await this.variableStore.get( - cdpValue, + this.variableStore.adaptCDPObjectId(partialValue.result.objectId), (params: object) => { return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); } ); - response.body.variables = properties; - - this.sendResponse(response); - - return; } catch(e) { - console.log('error', e); + Logger.error('[CDP] Failed to retrieve array partially', e); } } + if (args.filter !== "indexed" && args.filter !== "named") { + response.body.variables = await this.variableStore.get( + args.variablesReference, + (params: object) => { + return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); + } + ); + } + this.sendResponse(response); } diff --git a/packages/vscode-extension/src/debugging/cdp.ts b/packages/vscode-extension/src/debugging/cdp.ts index 19a7ed81b..cd67b3764 100644 --- a/packages/vscode-extension/src/debugging/cdp.ts +++ b/packages/vscode-extension/src/debugging/cdp.ts @@ -14,6 +14,7 @@ export type CDPRemoteObject = } | { type: "object"; + subtype?: "array"; objectId: string; className: string; description?: string; diff --git a/packages/vscode-extension/src/debugging/templates/getArraySlots.ts b/packages/vscode-extension/src/debugging/templates/getArraySlots.ts new file mode 100644 index 000000000..112f768a7 --- /dev/null +++ b/packages/vscode-extension/src/debugging/templates/getArraySlots.ts @@ -0,0 +1,20 @@ +// Based on https://github.com/microsoft/vscode-js-debug/blob/3be255753c458f231e32c9ef5c60090236780060/src/adapter/templates/getArraySlots.ts#L11 +function getArraySlots( + this: unknown[], + start: number, + count: number, + ) { + const result = {}; + const from = start === -1 ? 0 : start; + const to = count === -1 ? this.length : start + count; + for (let i = from; i < to && i < this.length; ++i) { + const descriptor = Object.getOwnPropertyDescriptor(this, i); + if (descriptor) { + Object.defineProperty(result, i, descriptor); + } + } + + return result; + }; + + export default getArraySlots; \ No newline at end of file diff --git a/packages/vscode-extension/src/debugging/templates/index.ts b/packages/vscode-extension/src/debugging/templates/index.ts new file mode 100644 index 000000000..37dd142dd --- /dev/null +++ b/packages/vscode-extension/src/debugging/templates/index.ts @@ -0,0 +1 @@ +export { default } from'./getArraySlots'; diff --git a/packages/vscode-extension/src/debugging/variableStore.ts b/packages/vscode-extension/src/debugging/variableStore.ts index ad505eda0..26d826266 100644 --- a/packages/vscode-extension/src/debugging/variableStore.ts +++ b/packages/vscode-extension/src/debugging/variableStore.ts @@ -13,27 +13,6 @@ export class VariableStore { private CDPtoDAPObjectIdMap: Map = new Map(); private DAPtoCDPObjectIdMap: Map = new Map(); - - public async getProperties( - id: number, - fetchProperties: (params: object) => Promise, - ) { - let properties: CDPPropertyDescriptor[]; - if (this.DAPtoCDPObjectIdMap.has(id)) { - const cdpObjectId = this.convertDAPObjectIdToCDP(id); - properties = ( - await fetchProperties({ - objectId: cdpObjectId, - ownProperties: true, - }) - ).result as CDPPropertyDescriptor[]; - } else { - properties = this.replVariables.get(id) as CDPPropertyDescriptor[]; - } - - return properties; - } - /** * If exist it returns a local variables if not it tries to fetch them from cdp. * @param id VariableId. @@ -83,6 +62,7 @@ export class VariableStore { value, type: "object", variablesReference, + // We split into 100 chunks, so no need to do it for less than 100 items indexedVariables: length > 100 ? length : undefined, namedVariables: length > 100 ? 1 : undefined }; diff --git a/packages/vscode-js-debug b/packages/vscode-js-debug new file mode 160000 index 000000000..9a436b1a3 --- /dev/null +++ b/packages/vscode-js-debug @@ -0,0 +1 @@ +Subproject commit 9a436b1a3060958110959c590eac9d1a8d548922 From 089cdd10c39e365d8c4923723af0190d62d6b74a Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 16:45:07 +0100 Subject: [PATCH 05/25] clean code --- packages/vscode-extension/package-lock.json | 614 ++++++++++++++------ packages/vscode-extension/package.json | 1 + 2 files changed, 447 insertions(+), 168 deletions(-) diff --git a/packages/vscode-extension/package-lock.json b/packages/vscode-extension/package-lock.json index 7be717dd5..445a3a0a2 100644 --- a/packages/vscode-extension/package-lock.json +++ b/packages/vscode-extension/package-lock.json @@ -78,6 +78,7 @@ "url-loader": "^4.1.1", "uuid": "^9.0.1", "vite": "^5.0.8", + "vscode-js-debug": "file:../vscode-js-debug", "vscode-test": "^1.5.0", "ws": "^8.14.2", "xml2js": "^0.6.2" @@ -86,6 +87,122 @@ "vscode": "^1.75.0" } }, + "../vscode-js-debug": { + "name": "js-debug", + "version": "1.96.0", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "@c4312/chromehash": "^0.3.1", + "@jridgewell/gen-mapping": "^0.3.3", + "@jridgewell/trace-mapping": "^0.3.22", + "@vscode/js-debug-browsers": "^1.1.2", + "@vscode/l10n": "^0.0.18", + "@vscode/win32-app-container-tokens": "^0.1.0", + "acorn": "^8.11.3", + "acorn-loose": "^8.4.0", + "astring": "^1.8.6", + "color": "^4.2.3", + "data-uri-to-buffer": "^6.0.1", + "default-browser": "^5.2.1", + "dotenv": "^16.4.1", + "eslint-visitor-keys": "^3.4.3", + "execa": "^5.1.1", + "glob-stream": "^8.0.0", + "got": "^11.8.6", + "inversify": "^6.0.2", + "js-xxhash": "^3.0.1", + "jsonc-parser": "^3.3.1", + "linkifyjs": "^4.1.3", + "micromatch": "^4.0.5", + "npm-run-all2": "^7.0.1", + "path-browserify": "^1.0.1", + "picomatch": "connor4312/picomatch#2fbe90b12eafa7dde816ff8c16be9e77271b0e0b", + "preact": "^10.19.3", + "reflect-metadata": "^0.2.1", + "signale": "^1.4.0", + "source-map-support": "^0.5.21", + "to-absolute-glob": "^3.0.0", + "vscode-tas-client": "^0.1.84", + "ws": "^8.17.1" + }, + "devDependencies": { + "@c4312/matcha": "^1.3.1", + "@pptr/testrunner": "^0.8.0", + "@types/chai": "^4.3.11", + "@types/chai-as-promised": "^7.1.8", + "@types/chai-string": "^1.4.5", + "@types/chai-subset": "^1.3.5", + "@types/color": "^3.0.6", + "@types/debug": "^4.1.12", + "@types/diff": "^5.0.9", + "@types/estree": "1.0.5", + "@types/express": "^4.17.21", + "@types/glob-stream": "^8.0.2", + "@types/gulp": "^4.0.17", + "@types/js-beautify": "^1.14.3", + "@types/json-schema": "^7.0.15", + "@types/linkifyjs": "^2.1.7", + "@types/long": "^4.0.2", + "@types/marked": "^5.0.2", + "@types/micromatch": "^4.0.6", + "@types/minimist": "^1.2.5", + "@types/mkdirp": "^1.0.2", + "@types/mocha": "^10.0.6", + "@types/node": "^20.11.11", + "@types/signale": "^1.4.7", + "@types/sinon": "^17.0.3", + "@types/stream-buffers": "^3.0.7", + "@types/tmp": "^0.2.6", + "@types/to-absolute-glob": "^2.0.3", + "@types/ws": "^8.5.10", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", + "@vscode/dwarf-debugging": "^0.0.2", + "@vscode/test-electron": "^2.4.1", + "chai": "^4.3.6", + "chai-as-promised": "^7.1.1", + "chai-string": "^1.5.0", + "chai-subset": "^1.6.0", + "diff": "^5.1.0", + "dprint": "^0.47.2", + "esbuild": "^0.23.1", + "eslint": "^8.56.0", + "eslint-plugin-header": "^3.1.1", + "eslint-plugin-react": "^7.33.2", + "express": "^4.21.1", + "glob": "^10.3.10", + "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", + "gulp-rename": "^2.0.0", + "gulp-util": "^3.0.8", + "https-proxy-agent": "^7.0.4", + "husky": "^9.0.7", + "jszip": "^3.10.1", + "marked": "^11.2.0", + "merge2": "^1.4.1", + "minimist": "^1.2.8", + "mocha": "^10.2.0", + "mocha-junit-reporter": "^2.2.1", + "mocha-multi-reporters": "^1.5.1", + "nyc": "^15.1.0", + "playwright": "^1.41.1", + "sinon": "^17.0.1", + "stream-buffers": "^3.0.2", + "ts-node": "^10.9.2", + "tsx": "^4.7.0", + "typescript": "^5.5.2", + "vsce": "^2.7.0" + }, + "engines": { + "node": ">=10", + "vscode": "^1.80.0" + } + }, + "js-debug": { + "extraneous": true + }, "node_modules/@ampproject/remapping": { "version": "2.2.1", "dev": true, @@ -1232,19 +1349,15 @@ "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.18", + "version": "0.3.25", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", + "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", "dev": true, - "license": "MIT", "dependencies": { - "@jridgewell/resolve-uri": "3.1.0", - "@jridgewell/sourcemap-codec": "1.4.14" + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "dev": true, - "license": "MIT" - }, "node_modules/@microsoft/1ds-core-js": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/@microsoft/1ds-core-js/-/1ds-core-js-4.3.4.tgz", @@ -2874,9 +2987,10 @@ "dev": true }, "node_modules/@types/json-schema": { - "version": "7.0.9", - "dev": true, - "license": "MIT" + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true }, "node_modules/@types/json5": { "version": "0.0.29", @@ -3294,13 +3408,13 @@ } }, "node_modules/@vscode/test-electron": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.4.0.tgz", - "integrity": "sha512-yojuDFEjohx6Jb+x949JRNtSn6Wk2FAh4MldLE3ck9cfvCqzwxF32QsNy1T9Oe4oT+ZfFcg0uPUCajJzOmPlTA==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.4.1.tgz", + "integrity": "sha512-Gc6EdaLANdktQ1t+zozoBVRynfIsMKMc94Svu1QreOBC8y76x4tvaK32TljrLi1LI2+PK58sDVbL7ALdqf3VRQ==", "dev": true, "dependencies": { "http-proxy-agent": "^7.0.2", - "https-proxy-agent": "^7.0.4", + "https-proxy-agent": "^7.0.5", "jszip": "^3.10.1", "ora": "^7.0.1", "semver": "^7.6.2" @@ -3310,13 +3424,10 @@ } }, "node_modules/@vscode/test-electron/node_modules/agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", + "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", "dev": true, - "dependencies": { - "debug": "^4.3.4" - }, "engines": { "node": ">= 14" } @@ -3335,12 +3446,12 @@ } }, "node_modules/@vscode/test-electron/node_modules/https-proxy-agent": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", - "integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", "dev": true, "dependencies": { - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "4" }, "engines": { @@ -3464,17 +3575,6 @@ "node": ">=10" } }, - "node_modules/@vscode/vsce/node_modules/mime": { - "version": "1.6.0", - "dev": true, - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/@vscode/vsce/node_modules/minimatch": { "version": "3.1.2", "dev": true, @@ -3497,22 +3597,6 @@ "node": ">=4" } }, - "node_modules/@vscode/vsce/node_modules/tmp": { - "version": "0.2.1", - "dev": true, - "license": "MIT", - "dependencies": { - "rimraf": "^3.0.0" - }, - "engines": { - "node": ">=8.17.0" - } - }, - "node_modules/@vscode/vsce/node_modules/url-join": { - "version": "4.0.1", - "dev": true, - "license": "MIT" - }, "node_modules/@vscode/vsce/node_modules/xml2js": { "version": "0.5.0", "dev": true, @@ -4271,16 +4355,15 @@ } }, "node_modules/call-bind": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", - "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz", + "integrity": "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==", "dev": true, "dependencies": { + "call-bind-apply-helpers": "^1.0.0", "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.1" + "set-function-length": "^1.2.2" }, "engines": { "node": ">= 0.4" @@ -4289,6 +4372,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz", + "integrity": "sha512-BhYE+WDaywFg2TBWYNXAE+8B1ATnThNBqXHP5nQu0jWJdVvY2hvkpyB3qOmtmDePiS5/BDQ8wASEWGMWRG148g==", + "dev": true, + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/callsites": { "version": "3.1.0", "dev": true, @@ -4799,6 +4895,35 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "dev": true, + "optional": true, + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/decompress-response/node_modules/mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "dev": true, + "optional": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/deep-extend": { "version": "0.6.0", "dev": true, @@ -4976,9 +5101,9 @@ } }, "node_modules/es-abstract": { - "version": "1.23.3", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.3.tgz", - "integrity": "sha512-e+HfNH61Bj1X9/jLc5v1owaLYuHdeHHSQlkhCBiTK8rBvKaULl/beGMxwrMXjpYrv4pz22BlY570vVePA2ho4A==", + "version": "1.23.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.5.tgz", + "integrity": "sha512-vlmniQ0WNPwXqA0BnmwV3Ng7HxiGlh6r5U6JcTMNx8OilcAGqVJBHJcPjqOMaczU9fRuRK5Px2BdVyPRnKMMVQ==", "dev": true, "dependencies": { "array-buffer-byte-length": "^1.0.1", @@ -4996,7 +5121,7 @@ "function.prototype.name": "^1.1.6", "get-intrinsic": "^1.2.4", "get-symbol-description": "^1.0.2", - "globalthis": "^1.0.3", + "globalthis": "^1.0.4", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.2", "has-proto": "^1.0.3", @@ -5012,10 +5137,10 @@ "is-string": "^1.0.7", "is-typed-array": "^1.1.13", "is-weakref": "^1.0.2", - "object-inspect": "^1.13.1", + "object-inspect": "^1.13.3", "object-keys": "^1.1.1", "object.assign": "^4.1.5", - "regexp.prototype.flags": "^1.5.2", + "regexp.prototype.flags": "^1.5.3", "safe-array-concat": "^1.1.2", "safe-regex-test": "^1.0.3", "string.prototype.trim": "^1.2.9", @@ -5870,9 +5995,10 @@ } }, "node_modules/esquery": { - "version": "1.4.0", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", "dev": true, - "license": "BSD-3-Clause", "dependencies": { "estraverse": "^5.1.0" }, @@ -6074,9 +6200,10 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, - "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -6204,14 +6331,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/find-up/node_modules/path-exists": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/find-yarn-workspace-root": { "version": "2.0.0", "dev": true, @@ -6507,9 +6626,10 @@ } }, "node_modules/globals": { - "version": "13.11.0", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, - "license": "MIT", "dependencies": { "type-fest": "^0.20.2" }, @@ -6537,15 +6657,16 @@ } }, "node_modules/globby": { - "version": "11.0.4", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", "dev": true, - "license": "MIT", "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", - "fast-glob": "^3.1.1", - "ignore": "^5.1.4", - "merge2": "^1.3.0", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", "slash": "^3.0.0" }, "engines": { @@ -6556,12 +6677,12 @@ } }, "node_modules/gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", "dev": true, - "dependencies": { - "get-intrinsic": "^1.1.3" + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -7273,9 +7394,10 @@ } }, "node_modules/jsonc-parser": { - "version": "3.2.0", - "dev": true, - "license": "MIT" + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "dev": true }, "node_modules/jszip": { "version": "3.10.1", @@ -7515,17 +7637,42 @@ } }, "node_modules/micromatch": { - "version": "4.0.4", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, - "license": "MIT", "dependencies": { - "braces": "^3.0.1", - "picomatch": "^2.2.3" + "braces": "^3.0.3", + "picomatch": "^2.3.1" }, "engines": { "node": ">=8.6" } }, + "node_modules/micromatch/node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "dev": true, + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/mime-db": { "version": "1.52.0", "dev": true, @@ -7569,9 +7716,13 @@ } }, "node_modules/minimist": { - "version": "1.2.6", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "dev": true, - "license": "MIT" + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/minipass": { "version": "4.2.8", @@ -7929,9 +8080,9 @@ } }, "node_modules/object-inspect": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", - "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", + "integrity": "sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==", "dev": true, "engines": { "node": ">= 0.4" @@ -8040,16 +8191,17 @@ } }, "node_modules/optionator": { - "version": "0.9.1", + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, - "license": "MIT", "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", - "word-wrap": "^1.2.3" + "word-wrap": "^1.2.5" }, "engines": { "node": ">= 0.8.0" @@ -8302,6 +8454,15 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/path-is-absolute": { "version": "1.0.1", "dev": true, @@ -8383,7 +8544,9 @@ "license": "ISC" }, "node_modules/picomatch": { - "version": "2.3.0", + "version": "2.3.1", + "resolved": "git+ssh://git@github.com/connor4312/picomatch.git#2fbe90b12eafa7dde816ff8c16be9e77271b0e0b", + "integrity": "sha512-NFpH2Othy/6fk2qamg3cjFa4P3RDgDpTNQGqZWT07WL80xef9hoLlIfHNRvWp4VDEOJVIzgChnDOHwvf5KP+jA==", "dev": true, "license": "MIT", "engines": { @@ -8527,11 +8690,12 @@ } }, "node_modules/qs": { - "version": "6.11.0", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", "dev": true, - "license": "BSD-3-Clause", "dependencies": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" }, "engines": { "node": ">=0.6" @@ -8765,15 +8929,15 @@ "license": "MIT" }, "node_modules/regexp.prototype.flags": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", - "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz", + "integrity": "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ==", "dev": true, "dependencies": { - "call-bind": "^1.0.6", + "call-bind": "^1.0.7", "define-properties": "^1.2.1", "es-errors": "^1.3.0", - "set-function-name": "^2.0.1" + "set-function-name": "^2.0.2" }, "engines": { "node": ">= 0.4" @@ -9127,13 +9291,18 @@ } }, "node_modules/side-channel": { - "version": "1.0.4", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", "dev": true, - "license": "MIT", "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -9189,33 +9358,6 @@ "simple-concat": "^1.0.0" } }, - "node_modules/simple-get/node_modules/decompress-response": { - "version": "6.0.0", - "dev": true, - "license": "MIT", - "optional": true, - "dependencies": { - "mimic-response": "^3.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/simple-get/node_modules/mimic-response": { - "version": "3.1.0", - "dev": true, - "license": "MIT", - "optional": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/sinon": { "version": "18.0.0", "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.0.tgz", @@ -9286,6 +9428,27 @@ "node": ">=0.10.0" } }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "peer": true, + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "node_modules/source-map-support/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/source-map/node_modules/tr46": { "version": "1.0.1", "dev": true, @@ -9739,25 +9902,6 @@ "license": "MIT", "peer": true }, - "node_modules/terser/node_modules/source-map": { - "version": "0.6.1", - "dev": true, - "license": "BSD-3-Clause", - "peer": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/terser/node_modules/source-map-support": { - "version": "0.5.21", - "dev": true, - "license": "MIT", - "peer": true, - "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -9804,6 +9948,15 @@ "dev": true, "license": "MIT" }, + "node_modules/tmp": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", + "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", + "dev": true, + "engines": { + "node": ">=14.14" + } + }, "node_modules/to-fast-properties": { "version": "2.0.0", "dev": true, @@ -10134,6 +10287,12 @@ "punycode": "^2.1.0" } }, + "node_modules/url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==", + "dev": true + }, "node_modules/url-loader": { "version": "4.1.1", "dev": true, @@ -10326,6 +10485,10 @@ } } }, + "node_modules/vscode-js-debug": { + "resolved": "../vscode-js-debug", + "link": true + }, "node_modules/vscode-test": { "version": "1.6.1", "dev": true, @@ -10512,9 +10675,10 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, - "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -10576,9 +10740,10 @@ } }, "node_modules/ws": { - "version": "8.14.2", + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", "dev": true, - "license": "MIT", "engines": { "node": ">=10.0.0" }, @@ -10706,6 +10871,119 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "vscode-js-debug": { + "name": "js-debug", + "version": "1.96.0", + "extraneous": true, + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "@c4312/chromehash": "^0.3.0", + "@jridgewell/gen-mapping": "^0.3.3", + "@jridgewell/trace-mapping": "^0.3.22", + "@vscode/js-debug-browsers": "^1.1.2", + "@vscode/l10n": "^0.0.18", + "@vscode/win32-app-container-tokens": "^0.1.0", + "acorn": "^8.11.3", + "acorn-loose": "^8.4.0", + "astring": "^1.8.6", + "color": "^4.2.3", + "data-uri-to-buffer": "^6.0.1", + "default-browser": "^5.2.1", + "dotenv": "^16.4.1", + "eslint-visitor-keys": "^3.4.3", + "execa": "^5.1.1", + "glob-stream": "^8.0.0", + "got": "^11.8.6", + "inversify": "^6.0.2", + "js-xxhash": "^3.0.1", + "jsonc-parser": "^3.3.1", + "linkifyjs": "^4.1.3", + "micromatch": "^4.0.5", + "npm-run-all2": "^7.0.1", + "path-browserify": "^1.0.1", + "picomatch": "connor4312/picomatch#2fbe90b12eafa7dde816ff8c16be9e77271b0e0b", + "preact": "^10.19.3", + "reflect-metadata": "^0.2.1", + "signale": "^1.4.0", + "source-map-support": "^0.5.21", + "to-absolute-glob": "^3.0.0", + "vscode-tas-client": "^0.1.84", + "ws": "^8.17.1" + }, + "devDependencies": { + "@c4312/matcha": "^1.3.1", + "@pptr/testrunner": "^0.8.0", + "@types/chai": "^4.3.11", + "@types/chai-as-promised": "^7.1.8", + "@types/chai-string": "^1.4.5", + "@types/chai-subset": "^1.3.5", + "@types/color": "^3.0.6", + "@types/debug": "^4.1.12", + "@types/diff": "^5.0.9", + "@types/estree": "1.0.5", + "@types/express": "^4.17.21", + "@types/glob-stream": "^8.0.2", + "@types/gulp": "^4.0.17", + "@types/js-beautify": "^1.14.3", + "@types/json-schema": "^7.0.15", + "@types/linkifyjs": "^2.1.7", + "@types/long": "^4.0.2", + "@types/marked": "^5.0.2", + "@types/micromatch": "^4.0.6", + "@types/minimist": "^1.2.5", + "@types/mkdirp": "^1.0.2", + "@types/mocha": "^10.0.6", + "@types/node": "^20.11.11", + "@types/signale": "^1.4.7", + "@types/sinon": "^17.0.3", + "@types/stream-buffers": "^3.0.7", + "@types/tmp": "^0.2.6", + "@types/to-absolute-glob": "^2.0.3", + "@types/ws": "^8.5.10", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", + "@vscode/dwarf-debugging": "^0.0.2", + "@vscode/test-electron": "^2.4.1", + "chai": "^4.3.6", + "chai-as-promised": "^7.1.1", + "chai-string": "^1.5.0", + "chai-subset": "^1.6.0", + "diff": "^5.1.0", + "dprint": "^0.47.2", + "esbuild": "^0.23.1", + "eslint": "^8.56.0", + "eslint-plugin-header": "^3.1.1", + "eslint-plugin-react": "^7.33.2", + "express": "^4.21.1", + "glob": "^10.3.10", + "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", + "gulp-rename": "^2.0.0", + "gulp-util": "^3.0.8", + "https-proxy-agent": "^7.0.4", + "husky": "^9.0.7", + "jszip": "^3.10.1", + "marked": "^11.2.0", + "merge2": "^1.4.1", + "minimist": "^1.2.8", + "mocha": "^10.2.0", + "mocha-junit-reporter": "^2.2.1", + "mocha-multi-reporters": "^1.5.1", + "nyc": "^15.1.0", + "playwright": "^1.41.1", + "sinon": "^17.0.1", + "stream-buffers": "^3.0.2", + "ts-node": "^10.9.2", + "tsx": "^4.7.0", + "typescript": "^5.5.2", + "vsce": "^2.7.0" + }, + "engines": { + "node": ">=10", + "vscode": "^1.80.0" + } } } } diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index 00750aed1..fa64ed792 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -455,6 +455,7 @@ "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test" }, "devDependencies": { + "vscode-js-debug": "file:../vscode-js-debug", "@babel/preset-react": "^7.23.3", "@expo/fingerprint": "^0.10.3", "@expo/package-manager": "^1.1.2", From 6254b61ff6b748dfc7962ebd926a0733c922614c Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 16:49:48 +0100 Subject: [PATCH 06/25] chore: remove old solution --- .../src/debugging/DebugAdapter.ts | 24 +++++++------ .../src/debugging/logFormatting.ts | 36 ------------------- 2 files changed, 13 insertions(+), 47 deletions(-) delete mode 100644 packages/vscode-extension/src/debugging/logFormatting.ts diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 6d95f19d0..59354ba48 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -13,7 +13,11 @@ import { StackFrame, } from "@vscode/debugadapter"; import { DebugProtocol } from "@vscode/debugprotocol"; -import { formatMessage } from "./logFormatting"; +import Cdp from "vscode-js-debug/src/cdp/api"; +import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes"; +import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; +import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; +import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; import { Logger } from "../Logger"; import { inferDAPScopePresentationHintFromCDPType, @@ -25,11 +29,6 @@ import { VariableStore } from "./variableStore"; import { SourceMapsRegistry } from "./SourceMapsRegistry"; import { BreakpointsController } from "./BreakpointsController"; import { CDPSession } from "./CDPSession"; -import Cdp from "vscode-js-debug/src/cdp/api"; -import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes"; -import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; -import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; -import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; import getArraySlots from "./templates"; function typeToCategory(type: string) { @@ -198,15 +197,15 @@ export class DebugAdapter extends DebugSession { generatedColumn1Based - 1 ); - const testOutput = await this.formatDefaultString(message.params.args.slice(0, -3)); + const formattedOutput = await this.formatDefaultString(message.params.args.slice(0, -3)); output = new OutputEvent( - testOutput.output, + formattedOutput.output, typeToCategory(message.params.type) ); output.body = { - ...testOutput, + ...formattedOutput, //@ts-ignore source, line, column and group are valid fields source: new Source(sourceURL, sourceURL), line: this.linesStartAt1 ? lineNumber1Based : lineNumber1Based - 1, @@ -216,12 +215,15 @@ export class DebugAdapter extends DebugSession { } else { const variablesRefDapID = this.createVariableForOutputEvent(message.params.args); + const formattedOutput = await this.formatDefaultString(message.params.args); + output = new OutputEvent( - (await formatMessage(message.params.args)) + "\n", + formattedOutput.output, typeToCategory(message.params.type) ); + output.body = { - ...output.body, + ...formattedOutput, //@ts-ignore source, line, column and group are valid fields variablesReference: variablesRefDapID, }; diff --git a/packages/vscode-extension/src/debugging/logFormatting.ts b/packages/vscode-extension/src/debugging/logFormatting.ts deleted file mode 100644 index 0504ddfc1..000000000 --- a/packages/vscode-extension/src/debugging/logFormatting.ts +++ /dev/null @@ -1,36 +0,0 @@ -import util from "util"; -import { CDPRemoteObject } from "./cdp"; - -function format(anything: unknown) { - const formatted = util.inspect(anything, { - showHidden: false, - depth: Infinity, - colors: false, - maxArrayLength: 20, - compact: true, - }); - if (typeof anything === "string") { - // remote single quotes - return formatted.slice(1, -1); - } - return formatted; -} - -export async function formatMessage(args: CDPRemoteObject[]): Promise { - return args - .map((arg) => { - switch (arg.type) { - case "object": - return format(arg.description || "[Object]"); - case "string": - case "number": - case "boolean": - return arg.value; - case "undefined": - return format(undefined); - case "function": - return format(arg.description || "[Function]"); - } - }) - .join(" "); -} From 9205918697c96409fff395a02e6f91a2adb7b6b2 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 16:53:29 +0100 Subject: [PATCH 07/25] chore: run prettier --- .../src/debugging/DebugAdapter.ts | 44 ++++++++----------- .../src/debugging/templates/getArraySlots.ts | 30 ++++++------- .../src/debugging/templates/index.ts | 2 +- .../src/debugging/variableStore.ts | 2 +- 4 files changed, 34 insertions(+), 44 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 59354ba48..6f3972a88 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -15,7 +15,11 @@ import { import { DebugProtocol } from "@vscode/debugprotocol"; import Cdp from "vscode-js-debug/src/cdp/api"; import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes"; -import { messageFormatters, previewAsObject, previewRemoteObject } from "vscode-js-debug/src/adapter/objectPreview"; +import { + messageFormatters, + previewAsObject, + previewRemoteObject, +} from "vscode-js-debug/src/adapter/objectPreview"; import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; import { Logger } from "../Logger"; @@ -149,15 +153,13 @@ export class DebugAdapter extends DebugSession { }; // Based on https://github.com/microsoft/vscode-js-debug/blob/3be255753c458f231e32c9ef5c60090236780060/src/adapter/console/textualMessage.ts#L83 - async formatDefaultString ( - args: ReadonlyArray, - ) { - const useMessageFormat = args.length > 1 && args[0].type === 'string'; + async formatDefaultString(args: ReadonlyArray) { + const useMessageFormat = args.length > 1 && args[0].type === "string"; const formatResult = useMessageFormat ? externalFormatMessage(args[0].value, args.slice(1) as AnyObject[], messageFormatters) - : externalFormatMessage('', args as AnyObject[], messageFormatters); + : externalFormatMessage("", args as AnyObject[], messageFormatters); - const output = formatResult.result + '\n'; + const output = formatResult.result + "\n"; if (formatResult.usedAllSubs && !args.some(previewAsObject)) { return { output }; @@ -166,7 +168,7 @@ export class DebugAdapter extends DebugSession { return { output, variablesReference: outputVar }; } - }; + } private async handleConsoleAPICall(message: any) { // We wrap console calls and add stack information as last three arguments, however @@ -199,11 +201,8 @@ export class DebugAdapter extends DebugSession { const formattedOutput = await this.formatDefaultString(message.params.args.slice(0, -3)); - output = new OutputEvent( - formattedOutput.output, - typeToCategory(message.params.type) - ); - + output = new OutputEvent(formattedOutput.output, typeToCategory(message.params.type)); + output.body = { ...formattedOutput, //@ts-ignore source, line, column and group are valid fields @@ -211,17 +210,13 @@ export class DebugAdapter extends DebugSession { line: this.linesStartAt1 ? lineNumber1Based : lineNumber1Based - 1, column: this.columnsStartAt1 ? columnNumber0Based + 1 : columnNumber0Based, }; - } else { const variablesRefDapID = this.createVariableForOutputEvent(message.params.args); const formattedOutput = await this.formatDefaultString(message.params.args); - output = new OutputEvent( - formattedOutput.output, - typeToCategory(message.params.type) - ); - + output = new OutputEvent(formattedOutput.output, typeToCategory(message.params.type)); + output.body = { ...formattedOutput, //@ts-ignore source, line, column and group are valid fields @@ -441,15 +436,15 @@ export class DebugAdapter extends DebugSession { ): Promise { response.body = response.body || {}; response.body.variables = []; - + if (args.filter === "indexed") { - const stringified = '' + getArraySlots; + const stringified = "" + getArraySlots; try { const partialValue = await this.cdpSession.sendCDPMessage("Runtime.callFunctionOn", { functionDeclaration: stringified, objectId: this.variableStore.convertDAPObjectIdToCDP(args.variablesReference), - arguments: [args.start, args.count].map(value => ({ value })), + arguments: [args.start, args.count].map((value) => ({ value })), }); const properties = await this.variableStore.get( @@ -460,8 +455,8 @@ export class DebugAdapter extends DebugSession { ); response.body.variables = properties; - } catch(e) { - Logger.error('[CDP] Failed to retrieve array partially', e); + } catch (e) { + Logger.error("[CDP] Failed to retrieve array partially", e); } } @@ -474,7 +469,6 @@ export class DebugAdapter extends DebugSession { ); } - this.sendResponse(response); } diff --git a/packages/vscode-extension/src/debugging/templates/getArraySlots.ts b/packages/vscode-extension/src/debugging/templates/getArraySlots.ts index 112f768a7..83e8984a4 100644 --- a/packages/vscode-extension/src/debugging/templates/getArraySlots.ts +++ b/packages/vscode-extension/src/debugging/templates/getArraySlots.ts @@ -1,20 +1,16 @@ // Based on https://github.com/microsoft/vscode-js-debug/blob/3be255753c458f231e32c9ef5c60090236780060/src/adapter/templates/getArraySlots.ts#L11 -function getArraySlots( - this: unknown[], - start: number, - count: number, - ) { - const result = {}; - const from = start === -1 ? 0 : start; - const to = count === -1 ? this.length : start + count; - for (let i = from; i < to && i < this.length; ++i) { - const descriptor = Object.getOwnPropertyDescriptor(this, i); - if (descriptor) { - Object.defineProperty(result, i, descriptor); - } - } +function getArraySlots(this: unknown[], start: number, count: number) { + const result = {}; + const from = start === -1 ? 0 : start; + const to = count === -1 ? this.length : start + count; + for (let i = from; i < to && i < this.length; ++i) { + const descriptor = Object.getOwnPropertyDescriptor(this, i); + if (descriptor) { + Object.defineProperty(result, i, descriptor); + } + } - return result; - }; + return result; +} - export default getArraySlots; \ No newline at end of file +export default getArraySlots; diff --git a/packages/vscode-extension/src/debugging/templates/index.ts b/packages/vscode-extension/src/debugging/templates/index.ts index 37dd142dd..acb3c6f44 100644 --- a/packages/vscode-extension/src/debugging/templates/index.ts +++ b/packages/vscode-extension/src/debugging/templates/index.ts @@ -1 +1 @@ -export { default } from'./getArraySlots'; +export { default } from "./getArraySlots"; diff --git a/packages/vscode-extension/src/debugging/variableStore.ts b/packages/vscode-extension/src/debugging/variableStore.ts index 26d826266..6934def37 100644 --- a/packages/vscode-extension/src/debugging/variableStore.ts +++ b/packages/vscode-extension/src/debugging/variableStore.ts @@ -64,7 +64,7 @@ export class VariableStore { variablesReference, // We split into 100 chunks, so no need to do it for less than 100 items indexedVariables: length > 100 ? length : undefined, - namedVariables: length > 100 ? 1 : undefined + namedVariables: length > 100 ? 1 : undefined, }; } From 3c9404e1b0a0989dc670793af41b8ee61f3d49f4 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Thu, 12 Dec 2024 18:55:30 +0100 Subject: [PATCH 08/25] chore: fix TS --- packages/vscode-extension/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-extension/tsconfig.json b/packages/vscode-extension/tsconfig.json index f41f5907f..1cd20f028 100644 --- a/packages/vscode-extension/tsconfig.json +++ b/packages/vscode-extension/tsconfig.json @@ -5,7 +5,7 @@ "outDir": "out", "lib": ["es6", "dom", "ESNext"], "sourceMap": true, - "rootDir": "src", + "rootDirs": ["src", "../vscode-js-debug"], "strict": true, "esModuleInterop": true, "resolveJsonModule": true, From b8038d7c5914a68770fae3af2d210c410c8b9381 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Fri, 13 Dec 2024 11:57:00 +0100 Subject: [PATCH 09/25] Update typecheck-extension.yml --- .github/workflows/typecheck-extension.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index b3dd0aa97..d4bec1f42 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -24,6 +24,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: true - name: Setup node uses: actions/setup-node@v4 From 3aa90e21b83e980ca0a1debff7938793059981d6 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Fri, 13 Dec 2024 12:14:42 +0100 Subject: [PATCH 10/25] Revert submodules checkout --- .github/workflows/typecheck-extension.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index d4bec1f42..b3dd0aa97 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -24,8 +24,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: true - name: Setup node uses: actions/setup-node@v4 From 2724c810948d923aca0c95c4450621171788d4d5 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Fri, 13 Dec 2024 12:20:10 +0100 Subject: [PATCH 11/25] Update typecheck-extension.yml --- .github/workflows/typecheck-extension.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index b3dd0aa97..bdaa898d1 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -25,6 +25,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: software-mansion-labs/vscode-js-debug + path: packages/vscode-js-debug + - name: Setup node uses: actions/setup-node@v4 with: From c2c0e7859fea7a3ffcf226a65a09817359e3c2df Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Fri, 13 Dec 2024 13:02:57 +0100 Subject: [PATCH 12/25] Update typecheck-extension.yml --- .github/workflows/typecheck-extension.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index bdaa898d1..ceaa77864 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -21,6 +21,7 @@ jobs: runs-on: ubuntu-latest env: WORKING_DIRECTORY: packages/vscode-extension + SUBMODULE_DIRECTORY: packages/vscode-js-debug steps: - name: Checkout uses: actions/checkout@v4 @@ -37,6 +38,10 @@ jobs: cache: "npm" cache-dependency-path: packages/vscode-extension/package-lock.json + - name: Install submodule node dependencies + working-directory: ${{ env.SUBMODULE_DIRECTORY }} + run: npm i + - name: Install node dependencies working-directory: ${{ env.WORKING_DIRECTORY }} run: npm i From e13188889c421e0f8f9e8bd18db753aa89ee8be0 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 17:32:38 +0100 Subject: [PATCH 13/25] chore: setup pipeline with vscode-js-debug --- .github/workflows/typecheck-extension.yml | 4 ---- packages/vscode-extension/package-lock.json | 2 +- packages/vscode-extension/package.json | 3 ++- .../src/debugging/DebugAdapter.ts | 16 ++++++++-------- packages/vscode-extension/tsconfig.json | 2 +- packages/vscode-js-debug | 2 +- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index ceaa77864..fd64fc6e7 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -38,10 +38,6 @@ jobs: cache: "npm" cache-dependency-path: packages/vscode-extension/package-lock.json - - name: Install submodule node dependencies - working-directory: ${{ env.SUBMODULE_DIRECTORY }} - run: npm i - - name: Install node dependencies working-directory: ${{ env.WORKING_DIRECTORY }} run: npm i diff --git a/packages/vscode-extension/package-lock.json b/packages/vscode-extension/package-lock.json index 445a3a0a2..e6b39077b 100644 --- a/packages/vscode-extension/package-lock.json +++ b/packages/vscode-extension/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "react-native-ide", "version": "1.0.0", + "hasInstallScript": true, "license": "https://ide.swmansion.com/legal", "devDependencies": { "@babel/preset-react": "^7.23.3", @@ -91,7 +92,6 @@ "name": "js-debug", "version": "1.96.0", "dev": true, - "hasInstallScript": true, "license": "MIT", "dependencies": { "@c4312/chromehash": "^0.3.1", diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index fa64ed792..cd0db25eb 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -452,7 +452,8 @@ "typecheck": "tsc --noEmit", "format": "prettier --write --list-different src", "build:tests": "tsc --project tsconfig.test.json", - "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test" + "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test", + "preinstall": "cd ../vscode-js-debug && npm install && npx tsc" }, "devDependencies": { "vscode-js-debug": "file:../vscode-js-debug", diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 6f3972a88..617cff277 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -12,16 +12,16 @@ import { Source, StackFrame, } from "@vscode/debugadapter"; -import { DebugProtocol } from "@vscode/debugprotocol"; -import Cdp from "vscode-js-debug/src/cdp/api"; -import { AnyObject } from "vscode-js-debug/src/adapter/objectPreview/betterTypes"; +import { DebugProtocol } from "@vscode/debugprotocol"; +import {Cdp} from "vscode-js-debug/out/cdp/index"; +import { AnyObject } from "vscode-js-debug/out/adapter/objectPreview/betterTypes"; import { messageFormatters, previewAsObject, previewRemoteObject, -} from "vscode-js-debug/src/adapter/objectPreview"; -import { formatMessage as externalFormatMessage } from "vscode-js-debug/src/adapter/messageFormat"; -import { PreviewContextType } from "vscode-js-debug/src/adapter/objectPreview/contexts"; +} from "vscode-js-debug/out/adapter/objectPreview"; +import { formatMessage } from "vscode-js-debug/out/adapter/messageFormat"; +import { PreviewContextType } from "vscode-js-debug/out/adapter/objectPreview/contexts"; import { Logger } from "../Logger"; import { inferDAPScopePresentationHintFromCDPType, @@ -156,8 +156,8 @@ export class DebugAdapter extends DebugSession { async formatDefaultString(args: ReadonlyArray) { const useMessageFormat = args.length > 1 && args[0].type === "string"; const formatResult = useMessageFormat - ? externalFormatMessage(args[0].value, args.slice(1) as AnyObject[], messageFormatters) - : externalFormatMessage("", args as AnyObject[], messageFormatters); + ? formatMessage(args[0].value, args.slice(1) as AnyObject[], messageFormatters) + : formatMessage("", args as AnyObject[], messageFormatters); const output = formatResult.result + "\n"; diff --git a/packages/vscode-extension/tsconfig.json b/packages/vscode-extension/tsconfig.json index 1cd20f028..f41f5907f 100644 --- a/packages/vscode-extension/tsconfig.json +++ b/packages/vscode-extension/tsconfig.json @@ -5,7 +5,7 @@ "outDir": "out", "lib": ["es6", "dom", "ESNext"], "sourceMap": true, - "rootDirs": ["src", "../vscode-js-debug"], + "rootDir": "src", "strict": true, "esModuleInterop": true, "resolveJsonModule": true, diff --git a/packages/vscode-js-debug b/packages/vscode-js-debug index 9a436b1a3..a5794161f 160000 --- a/packages/vscode-js-debug +++ b/packages/vscode-js-debug @@ -1 +1 @@ -Subproject commit 9a436b1a3060958110959c590eac9d1a8d548922 +Subproject commit a5794161fde3e3b55df4633104d3aba414194aad From ff0d0bbf04427f66bb2dd14d38ec56bf1774deaa Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 17:44:35 +0100 Subject: [PATCH 14/25] chore: improve setup --- .github/workflows/typecheck-extension.yml | 6 ------ packages/vscode-extension/package.json | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index fd64fc6e7..b3dd0aa97 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -21,16 +21,10 @@ jobs: runs-on: ubuntu-latest env: WORKING_DIRECTORY: packages/vscode-extension - SUBMODULE_DIRECTORY: packages/vscode-js-debug steps: - name: Checkout uses: actions/checkout@v4 - - uses: actions/checkout@v4 - with: - repository: software-mansion-labs/vscode-js-debug - path: packages/vscode-js-debug - - name: Setup node uses: actions/setup-node@v4 with: diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index cd0db25eb..28afa6389 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -453,7 +453,7 @@ "format": "prettier --write --list-different src", "build:tests": "tsc --project tsconfig.test.json", "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test", - "preinstall": "cd ../vscode-js-debug && npm install && npx tsc" + "preinstall": "cd ../vscode-js-debug && git submodule update && npm install && npx tsc" }, "devDependencies": { "vscode-js-debug": "file:../vscode-js-debug", From ca9f05efb1e889e054255c2d155c6ee2ae5ba826 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 17:48:25 +0100 Subject: [PATCH 15/25] chore: fix pipeline --- .github/workflows/lint-extension.yml | 5 +++++ .github/workflows/typecheck-extension.yml | 5 +++++ packages/vscode-extension/package.json | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-extension.yml b/.github/workflows/lint-extension.yml index 3677eddff..9c10c676e 100644 --- a/.github/workflows/lint-extension.yml +++ b/.github/workflows/lint-extension.yml @@ -25,6 +25,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: software-mansion-labs/vscode-js-debug + path: packages/vscode-js-debug + - name: Setup node uses: actions/setup-node@v4 with: diff --git a/.github/workflows/typecheck-extension.yml b/.github/workflows/typecheck-extension.yml index b3dd0aa97..bdaa898d1 100644 --- a/.github/workflows/typecheck-extension.yml +++ b/.github/workflows/typecheck-extension.yml @@ -25,6 +25,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: software-mansion-labs/vscode-js-debug + path: packages/vscode-js-debug + - name: Setup node uses: actions/setup-node@v4 with: diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index 28afa6389..cd0db25eb 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -453,7 +453,7 @@ "format": "prettier --write --list-different src", "build:tests": "tsc --project tsconfig.test.json", "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test", - "preinstall": "cd ../vscode-js-debug && git submodule update && npm install && npx tsc" + "preinstall": "cd ../vscode-js-debug && npm install && npx tsc" }, "devDependencies": { "vscode-js-debug": "file:../vscode-js-debug", From 2f9151349d975eb19ad719a5daa222098f088d72 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 17:51:44 +0100 Subject: [PATCH 16/25] chore: fix lint --- packages/vscode-extension/src/debugging/DebugAdapter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 617cff277..b8607166d 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -12,8 +12,8 @@ import { Source, StackFrame, } from "@vscode/debugadapter"; -import { DebugProtocol } from "@vscode/debugprotocol"; -import {Cdp} from "vscode-js-debug/out/cdp/index"; +import { DebugProtocol } from "@vscode/debugprotocol"; +import { Cdp } from "vscode-js-debug/out/cdp/index"; import { AnyObject } from "vscode-js-debug/out/adapter/objectPreview/betterTypes"; import { messageFormatters, From 016ee4638ce2183a14cd64b542f12c208b1dbabc Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 17:56:10 +0100 Subject: [PATCH 17/25] chore: add git submodule update so user don't need to do it manually --- packages/vscode-extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index cd0db25eb..28afa6389 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -453,7 +453,7 @@ "format": "prettier --write --list-different src", "build:tests": "tsc --project tsconfig.test.json", "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test", - "preinstall": "cd ../vscode-js-debug && npm install && npx tsc" + "preinstall": "cd ../vscode-js-debug && git submodule update && npm install && npx tsc" }, "devDependencies": { "vscode-js-debug": "file:../vscode-js-debug", From 19eaf6f6e7ae8f191aa4bc840c674289180442a8 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 18:07:29 +0100 Subject: [PATCH 18/25] Update DebugAdapter.ts --- packages/vscode-extension/src/debugging/DebugAdapter.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index b8607166d..7f62bedc1 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -21,7 +21,6 @@ import { previewRemoteObject, } from "vscode-js-debug/out/adapter/objectPreview"; import { formatMessage } from "vscode-js-debug/out/adapter/messageFormat"; -import { PreviewContextType } from "vscode-js-debug/out/adapter/objectPreview/contexts"; import { Logger } from "../Logger"; import { inferDAPScopePresentationHintFromCDPType, @@ -233,7 +232,7 @@ export class DebugAdapter extends DebugSession { const prepareVariables = await Promise.all( args.map(async (arg: CDPRemoteObject, index: number) => { if (arg.type === "object") { - arg.description = previewRemoteObject(arg, PreviewContextType.PropertyValue); + arg.description = previewRemoteObject(arg, "propertyValue"); arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); } From 1a115acfc5593b133dbf1157bf306914e7f45e6c Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Mon, 16 Dec 2024 18:43:50 +0100 Subject: [PATCH 19/25] Remove unused flag --- packages/vscode-extension/src/debugging/variableStore.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vscode-extension/src/debugging/variableStore.ts b/packages/vscode-extension/src/debugging/variableStore.ts index 6934def37..97752e50a 100644 --- a/packages/vscode-extension/src/debugging/variableStore.ts +++ b/packages/vscode-extension/src/debugging/variableStore.ts @@ -30,7 +30,6 @@ export class VariableStore { await fetchProperties({ objectId: cdpObjectId, ownProperties: true, - generatePreview: true, }) ).result as CDPPropertyDescriptor[]; isCDPObject = true; From b7554189070317354867400c38b6b6672030dfa6 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Tue, 17 Dec 2024 13:18:15 +0100 Subject: [PATCH 20/25] chore: filter out primitives from collapsed args --- .../src/debugging/DebugAdapter.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 7f62bedc1..66d4d5f14 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -229,16 +229,23 @@ export class DebugAdapter extends DebugSession { } private async createVariableForOutputEvent(args: CDPRemoteObject[]) { - const prepareVariables = await Promise.all( + const prepareVariables = (await Promise.all( args.map(async (arg: CDPRemoteObject, index: number) => { + // Don't create variables for primitive types, we do it here + // instead of .filter to keep indexes consistent + if (arg.type !== "object" && arg.type !== "function") { + return null; + } + + arg.description = previewRemoteObject(arg, "propertyValue"); + if (arg.type === "object") { - arg.description = previewRemoteObject(arg, "propertyValue"); arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); } - return { name: `arg${index}`, value: arg }; }) - ); + )).filter(value => value !== null); + // we create empty object that is needed for DAP OutputEvent to display // collapsed args properly, the object references the array of args array const argsObjectDapID = this.variableStore.pushReplVariable(prepareVariables); From 4c31aafd92b2585a5386dba99e47eff87c618f53 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Tue, 17 Dec 2024 16:07:28 +0100 Subject: [PATCH 21/25] chore: don't display named arguments when orignally there was just one argument --- packages/vscode-extension/src/debugging/DebugAdapter.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 66d4d5f14..b793228b0 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -250,6 +250,11 @@ export class DebugAdapter extends DebugSession { // collapsed args properly, the object references the array of args array const argsObjectDapID = this.variableStore.pushReplVariable(prepareVariables); + // If originally there was only one argument, we don't want to display named arguments + if (args.length === 1) { + return argsObjectDapID; + } + return this.variableStore.pushReplVariable([ { name: "", From 57750e9475178114cf6c386c4a97df2cb75d8682 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Tue, 17 Dec 2024 16:10:23 +0100 Subject: [PATCH 22/25] chore: remove unnecessary file + improve comments --- packages/vscode-extension/src/debugging/DebugAdapter.ts | 3 ++- packages/vscode-extension/src/debugging/templates/index.ts | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 packages/vscode-extension/src/debugging/templates/index.ts diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index b793228b0..115924934 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -32,7 +32,7 @@ import { VariableStore } from "./variableStore"; import { SourceMapsRegistry } from "./SourceMapsRegistry"; import { BreakpointsController } from "./BreakpointsController"; import { CDPSession } from "./CDPSession"; -import getArraySlots from "./templates"; +import getArraySlots from "./templates/getArraySlots"; function typeToCategory(type: string) { switch (type) { @@ -152,6 +152,7 @@ export class DebugAdapter extends DebugSession { }; // Based on https://github.com/microsoft/vscode-js-debug/blob/3be255753c458f231e32c9ef5c60090236780060/src/adapter/console/textualMessage.ts#L83 + // We use that to format and truncate console.log messages async formatDefaultString(args: ReadonlyArray) { const useMessageFormat = args.length > 1 && args[0].type === "string"; const formatResult = useMessageFormat diff --git a/packages/vscode-extension/src/debugging/templates/index.ts b/packages/vscode-extension/src/debugging/templates/index.ts deleted file mode 100644 index acb3c6f44..000000000 --- a/packages/vscode-extension/src/debugging/templates/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./getArraySlots"; From 21e4c4f7ccd808540321a849248f272eea00ef3b Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Tue, 17 Dec 2024 20:08:32 +0100 Subject: [PATCH 23/25] chore: replace npx with npm exec and run lint --- packages/vscode-extension/package.json | 2 +- .../src/debugging/DebugAdapter.ts | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index 28afa6389..4d3deb538 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -453,7 +453,7 @@ "format": "prettier --write --list-different src", "build:tests": "tsc --project tsconfig.test.json", "test": "npm run build:extension-code && npm run build:webview && npm run build:tests && vscode-test", - "preinstall": "cd ../vscode-js-debug && git submodule update && npm install && npx tsc" + "preinstall": "cd ../vscode-js-debug && git submodule update && npm install && npm exec tsc" }, "devDependencies": { "vscode-js-debug": "file:../vscode-js-debug", diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 115924934..053d05aaa 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -230,22 +230,24 @@ export class DebugAdapter extends DebugSession { } private async createVariableForOutputEvent(args: CDPRemoteObject[]) { - const prepareVariables = (await Promise.all( - args.map(async (arg: CDPRemoteObject, index: number) => { - // Don't create variables for primitive types, we do it here - // instead of .filter to keep indexes consistent - if (arg.type !== "object" && arg.type !== "function") { - return null; - } + const prepareVariables = ( + await Promise.all( + args.map(async (arg: CDPRemoteObject, index: number) => { + // Don't create variables for primitive types, we do it here + // instead of .filter to keep indexes consistent + if (arg.type !== "object" && arg.type !== "function") { + return null; + } - arg.description = previewRemoteObject(arg, "propertyValue"); + arg.description = previewRemoteObject(arg, "propertyValue"); - if (arg.type === "object") { - arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); - } - return { name: `arg${index}`, value: arg }; - }) - )).filter(value => value !== null); + if (arg.type === "object") { + arg.objectId = this.variableStore.adaptCDPObjectId(arg.objectId).toString(); + } + return { name: `arg${index}`, value: arg }; + }) + ) + ).filter((value) => value !== null); // we create empty object that is needed for DAP OutputEvent to display // collapsed args properly, the object references the array of args array From 5c1db413a9c55c4a601ec3d5e5c963145cac316e Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Tue, 17 Dec 2024 20:48:42 +0100 Subject: [PATCH 24/25] chore: refactore and add comment --- .../src/debugging/DebugAdapter.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index 053d05aaa..ea2761900 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -451,7 +451,14 @@ export class DebugAdapter extends DebugSession { response.body = response.body || {}; response.body.variables = []; - if (args.filter === "indexed") { + if (args.filter !== "indexed" && args.filter !== "named") { + response.body.variables = await this.variableStore.get( + args.variablesReference, + (params: object) => { + return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); + } + ); + } else if (args.filter === "indexed") { const stringified = "" + getArraySlots; try { @@ -472,15 +479,11 @@ export class DebugAdapter extends DebugSession { } catch (e) { Logger.error("[CDP] Failed to retrieve array partially", e); } - } - - if (args.filter !== "indexed" && args.filter !== "named") { - response.body.variables = await this.variableStore.get( - args.variablesReference, - (params: object) => { - return this.cdpSession.sendCDPMessage("Runtime.getProperties", params); - } - ); + } else if (args.filter === "named") { + // We do nothing for named variables. We set 'named' and 'indexed' only for arrays in variableStore + // so the 'named' here means "display chunks" (which I is handled by Debugger). If we'd get the properties + // here we would get all indexed properties even when passing `nonIndexedPropertiesOnly: true` param + // to Runtime.getProperties. I assume that this property just does not work yet as it's marked as experimental. } this.sendResponse(response); From dd5effe05a7e5eba1acbe7a8892d91caa4c326d4 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Tue, 17 Dec 2024 23:11:56 +0100 Subject: [PATCH 25/25] Update packages/vscode-extension/src/debugging/DebugAdapter.ts Co-authored-by: Krzysztof Magiera --- packages/vscode-extension/src/debugging/DebugAdapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-extension/src/debugging/DebugAdapter.ts b/packages/vscode-extension/src/debugging/DebugAdapter.ts index ea2761900..8b6a65c51 100644 --- a/packages/vscode-extension/src/debugging/DebugAdapter.ts +++ b/packages/vscode-extension/src/debugging/DebugAdapter.ts @@ -481,7 +481,7 @@ export class DebugAdapter extends DebugSession { } } else if (args.filter === "named") { // We do nothing for named variables. We set 'named' and 'indexed' only for arrays in variableStore - // so the 'named' here means "display chunks" (which I is handled by Debugger). If we'd get the properties + // so the 'named' here means "display chunks" (which is handled by Debugger). If we'd get the properties // here we would get all indexed properties even when passing `nonIndexedPropertiesOnly: true` param // to Runtime.getProperties. I assume that this property just does not work yet as it's marked as experimental. }