Skip to content

Commit

Permalink
Enhance Console logs (#846)
Browse files Browse the repository at this point in the history
This PR aims to improve the debugging experience by making it similar to
Chrome DevTools.

It improves the preview, formatting and truncating of console logs and
splits large arrays into smaller changes, where chunks are fetched on
expand - similarly as `vscode-js-debug` does. The more detailed previews
are generated based on `preview` property from the debugger, so it may
not work on older RN versions.

The main idea was not to reinvent the wheel but to reuse as much of
https://github.com/microsoft/vscode-js-debug as possible. Thus we forked
it with small patch
software-mansion-labs/vscode-js-debug@a579416
that allows us to build it - otherwise the TS on our side failed.
`vscode-js-debug` sits in our repo as a git submodule and no additional
steps should be necessary (preinstall script should take care of pulling
it, installing and building).

|Before|After|
|-|-|
|<img width="615" alt="logs-before"
src="https://github.com/user-attachments/assets/a018e8f7-3762-4f95-9e00-10fa3449bb14"
/>|<img width="605" alt="logs-after"
src="https://github.com/user-attachments/assets/938f7444-7636-48a0-8b63-ea0d51a861bd"
/>|

|Before|After|
|-|-|
|<img width="613" alt="large-arrays-before"
src="https://github.com/user-attachments/assets/f8ab617e-7655-42cb-9923-0938ad56e401"
/>|<img width="477" alt="large-arrays-after"
src="https://github.com/user-attachments/assets/a27909cd-43c7-4350-9cd5-c7a1a9069778"
/>|

### How Has This Been Tested: 

Update `printLogs` method with:

```
function printLogs() {
    const string = 'string';
    const object = { key: 'value', key2: 'value2' };
    const set = new Set([1, 2, 3, 3]);
    const array1000 = new Array(1000).fill(0).map((_, i) => i);
    const array101 = new Array(101).fill(0).map((_, i) => array1000);
    const int = 1;
    const float = 1.1;
    const func = function() {};
    const anonymousFunc = () => {};

    console.log(string, array1000, array101, object, set,
      int,
      float,
      func,
      anonymousFunc);
}
```

Tested on react-native-76, react-native-73.

---------

Co-authored-by: Krzysztof Magiera <[email protected]>
  • Loading branch information
maciekstosio and kmagiera authored Dec 17, 2024
1 parent 5099f61 commit 58b15ca
Show file tree
Hide file tree
Showing 11 changed files with 598 additions and 234 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/lint-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/typecheck-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "packages/simulator-server"]
path = packages/simulator-server
url = [email protected]:software-mansion-labs/simulator-server.git
[submodule "packages/vscode-js-debug"]
path = packages/vscode-js-debug
url = [email protected]:software-mansion-labs/vscode-js-debug.git
Loading

0 comments on commit 58b15ca

Please sign in to comment.