Skip to content

Commit bbf793a

Browse files
authored
Merge pull request #16 from jtpio/filediffs
Unified cell and file diffs
2 parents 52511a5 + af6593d commit bbf793a

18 files changed

+1482
-309
lines changed

.github/workflows/build.yml

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,70 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v4
18+
- name: Checkout
19+
uses: actions/checkout@v4
2020

21-
- name: Base Setup
22-
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
21+
- name: Base Setup
22+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
2323

24-
- name: Install dependencies
25-
run: python -m pip install -U "jupyterlab>=4.0.0,<5"
24+
- name: Install dependencies
25+
run: python -m pip install -U "jupyterlab>=4.0.0,<5"
2626

27-
- name: Lint the extension
28-
run: |
29-
set -eux
30-
jlpm
31-
jlpm run lint:check
27+
- name: Lint the extension
28+
run: |
29+
set -eux
30+
jlpm
31+
jlpm run lint:check
3232
33-
- name: Build the extension
34-
run: |
35-
set -eux
36-
python -m pip install .[test]
33+
- name: Build the extension
34+
run: |
35+
set -eux
36+
python -m pip install .[test]
3737
38-
jupyter labextension list
39-
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
40-
python -m jupyterlab.browser_check
38+
jupyter labextension list
39+
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
40+
python -m jupyterlab.browser_check
4141
42-
- name: Package the extension
43-
run: |
44-
set -eux
42+
- name: Package the extension
43+
run: |
44+
set -eux
4545
46-
pip install build
47-
python -m build
48-
pip uninstall -y "jupyterlab_cell_diff" jupyterlab
46+
pip install build
47+
python -m build
48+
pip uninstall -y "jupyterlab_cell_diff" jupyterlab
4949
50-
- name: Upload extension packages
51-
uses: actions/upload-artifact@v4
52-
with:
53-
name: extension-artifacts
54-
path: dist/jupyterlab_cell_diff*
55-
if-no-files-found: error
50+
- name: Upload extension packages
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: extension-artifacts
54+
path: dist/jupyterlab_cell_diff*
55+
if-no-files-found: error
5656

5757
test_isolated:
5858
needs: build
5959
runs-on: ubuntu-latest
6060

6161
steps:
62-
- name: Install Python
63-
uses: actions/setup-python@v5
64-
with:
65-
python-version: '3.9'
66-
architecture: 'x64'
67-
- uses: actions/download-artifact@v4
68-
with:
69-
name: extension-artifacts
70-
- name: Install and Test
71-
run: |
72-
set -eux
73-
# Remove NodeJS, twice to take care of system and locally installed node versions.
74-
sudo rm -rf $(which node)
75-
sudo rm -rf $(which node)
76-
77-
pip install "jupyterlab>=4.0.0,<5" jupyterlab_cell_diff*.whl
78-
79-
jupyter labextension list
80-
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
81-
python -m jupyterlab.browser_check --no-browser-test
82-
62+
- name: Install Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: '3.9'
66+
architecture: 'x64'
67+
- uses: actions/download-artifact@v4
68+
with:
69+
name: extension-artifacts
70+
- name: Install and Test
71+
run: |
72+
set -eux
73+
# Remove NodeJS, twice to take care of system and locally installed node versions.
74+
sudo rm -rf $(which node)
75+
sudo rm -rf $(which node)
76+
77+
pip install "jupyterlab>=4.0.0,<5" jupyterlab_cell_diff*.whl
78+
79+
jupyter labextension list
80+
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
81+
python -m jupyterlab.browser_check --no-browser-test
8382
8483
check_links:
8584
name: Check Links

.github/workflows/check-release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Check Release
22
on:
33
push:
4-
branches: ["main"]
4+
branches: ['main']
55
pull_request:
6-
branches: ["*"]
6+
branches: ['*']
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -23,7 +23,6 @@ jobs:
2323
- name: Check Release
2424
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2
2525
with:
26-
2726
token: ${{ secrets.GITHUB_TOKEN }}
2827

2928
- name: Upload Distributions

.github/workflows/prep-release.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
name: "Step 1: Prep Release"
1+
name: 'Step 1: Prep Release'
22
on:
33
workflow_dispatch:
44
inputs:
55
version_spec:
6-
description: "New Version Specifier"
7-
default: "next"
6+
description: 'New Version Specifier'
7+
default: 'next'
88
required: false
99
branch:
10-
description: "The branch to target"
10+
description: 'The branch to target'
1111
required: false
1212
post_version_spec:
13-
description: "Post Version Specifier"
13+
description: 'Post Version Specifier'
1414
required: false
1515
# silent:
1616
# description: "Set a placeholder in the changelog and don't publish the release."
1717
# required: false
1818
# type: boolean
1919
since:
20-
description: "Use PRs with activity since this date or git reference"
20+
description: 'Use PRs with activity since this date or git reference'
2121
required: false
2222
since_last_stable:
23-
description: "Use PRs with activity since the last stable git tag"
23+
description: 'Use PRs with activity since the last stable git tag'
2424
required: false
2525
type: boolean
2626
jobs:
@@ -45,6 +45,6 @@ jobs:
4545
since: ${{ github.event.inputs.since }}
4646
since_last_stable: ${{ github.event.inputs.since_last_stable }}
4747

48-
- name: "** Next Step **"
48+
- name: '** Next Step **'
4949
run: |
5050
echo "Optional): Review Draft Release: ${{ steps.prep-release.outputs.release_url }}"

.github/workflows/publish-release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: "Step 2: Publish Release"
1+
name: 'Step 2: Publish Release'
22
on:
33
workflow_dispatch:
44
inputs:
55
branch:
6-
description: "The target branch"
6+
description: 'The target branch'
77
required: false
88
release_url:
9-
description: "The URL of the draft GitHub release"
9+
description: 'The URL of the draft GitHub release'
1010
required: false
1111
steps_to_skip:
12-
description: "Comma separated list of steps to skip"
12+
description: 'Comma separated list of steps to skip'
1313
required: false
1414

1515
jobs:
@@ -47,13 +47,13 @@ jobs:
4747
token: ${{ steps.app-token.outputs.token }}
4848
release_url: ${{ steps.populate-release.outputs.release_url }}
4949

50-
- name: "** Next Step **"
50+
- name: '** Next Step **'
5151
if: ${{ success() }}
5252
run: |
5353
echo "Verify the final release"
5454
echo ${{ steps.finalize-release.outputs.release_url }}
5555
56-
- name: "** Failure Message **"
56+
- name: '** Failure Message **'
5757
if: ${{ failure() }}
5858
run: |
5959
echo "Failed to Publish the Draft Release Url:"

README.md

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,53 @@ jupyter labextension develop . --overwrite
3232

3333
### Commands
3434

35-
The extension provides a command to show cell diffs:
35+
The extension provides commands to show diffs in multiple formats:
3636

37-
- `jupyterlab-cell-diff:show-codemirror` - Show diff using `@codemirror/merge`
37+
- `jupyterlab-cell-diff:split-cell-diff` - Show cell diff using split view (side-by-side comparison)
38+
- `jupyterlab-cell-diff:unified-cell-diff` - Show cell diff using unified view
39+
- `jupyterlab-cell-diff:unified-file-diff` - Show file diff using unified view for regular Python files and other text files
3840

3941
https://github.com/user-attachments/assets/0dacd7f0-5963-4ebe-81da-2958f0117071
4042

4143
### Programmatic Usage
4244

45+
#### Split Cell Diff (Side-by-side View)
46+
4347
```typescript
44-
app.commands.execute('jupyterlab-cell-diff:show-codemirror', {
48+
app.commands.execute('jupyterlab-cell-diff:split-cell-diff', {
4549
cellId: 'cell-id',
4650
originalSource: 'print("Hello")',
47-
newSource: 'print("Hello, World!")'
51+
newSource: 'print("Hello, World!")',
52+
showActionButtons: true,
53+
openDiff: true
4854
});
4955
```
5056

51-
#### Command Arguments
57+
#### Unified Cell Diff
58+
59+
```typescript
60+
app.commands.execute('jupyterlab-cell-diff:unified-cell-diff', {
61+
cellId: 'cell-id',
62+
originalSource: 'print("Hello")',
63+
newSource: 'print("Hello, World!")',
64+
showActionButtons: true
65+
});
66+
```
5267

53-
The `jupyterlab-cell-diff:show-codemirror` command accepts the following arguments:
68+
#### Unified File Diff
69+
70+
```typescript
71+
app.commands.execute('jupyterlab-cell-diff:unified-file-diff', {
72+
filePath: '/path/to/file.py',
73+
originalSource: 'print("Hello")',
74+
newSource: 'print("Hello, World!")',
75+
showActionButtons: true
76+
});
77+
```
78+
79+
### Command Arguments
80+
81+
#### `jupyterlab-cell-diff:split-cell-diff` (Split View)
5482

5583
| Argument | Type | Required | Description |
5684
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------ |
@@ -61,6 +89,35 @@ The `jupyterlab-cell-diff:show-codemirror` command accepts the following argumen
6189
| `notebookPath` | `string` | No | Path to the notebook containing the cell. If not provided, uses the current notebook |
6290
| `openDiff` | `boolean` | No | Whether to open the diff widget automatically (default: `true`) |
6391

92+
#### `jupyterlab-cell-diff:unified-cell-diff` (Unified View)
93+
94+
| Argument | Type | Required | Description |
95+
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------ |
96+
| `cellId` | `string` | No | ID of the cell to show diff for. If not provided, uses the active cell |
97+
| `originalSource` | `string` | Yes | Original source code to compare against |
98+
| `newSource` | `string` | Yes | New source code to compare with |
99+
| `showActionButtons` | `boolean` | No | Whether to show action buttons for chunk acceptance (default: `true`) |
100+
| `notebookPath` | `string` | No | Path to the notebook containing the cell. If not provided, uses the current notebook |
101+
102+
#### `jupyterlab-cell-diff:unified-file-diff` (File Diff)
103+
104+
| Argument | Type | Required | Description |
105+
| ------------------- | --------- | -------- | --------------------------------------------------------------------- |
106+
| `filePath` | `string` | No | Path to the file to diff. Defaults to current file in editor. |
107+
| `originalSource` | `string` | Yes | Original source code to compare against |
108+
| `newSource` | `string` | Yes | New source code to compare with |
109+
| `showActionButtons` | `boolean` | No | Whether to show action buttons for chunk acceptance (default: `true`) |
110+
111+
## Architecture
112+
113+
### Diff Strategies
114+
115+
The extension provides two diff viewing strategies:
116+
117+
- **Split diff** (`split-cell-diff`): Uses CodeMirror's two-pane view. Displays original and modified code side-by-side in separate panels with diff highlighting.
118+
119+
- **Unified diff** (`unified-cell-diff`/`unified-file-diff`): Uses CodeMirror's `unifiedMergeView`. Displays changes in a single unified view with added/removed lines clearly marked. Can be used for both cell diffs and regular file diffs.
120+
64121
## Uninstall
65122

66123
To remove the extension, execute:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@
5757
},
5858
"dependencies": {
5959
"@codemirror/lang-python": "^6.2.1",
60-
"@codemirror/merge": "^6.10.2",
60+
"@codemirror/merge": "^6.11.0",
6161
"@codemirror/view": "^6.38.2",
62+
"@jupyter/ydoc": "^3.1.0",
6263
"@jupyterlab/application": "^4.0.0",
6364
"@jupyterlab/cells": "^4.0.0",
6465
"@jupyterlab/codeeditor": "^4.0.0",
6566
"@jupyterlab/codemirror": "^4.4.7",
6667
"@jupyterlab/coreutils": "^6.0.0",
68+
"@jupyterlab/fileeditor": "^4.0.0",
6769
"@jupyterlab/notebook": "^4.0.0",
6870
"@jupyterlab/services": "^7.0.0",
6971
"@jupyterlab/translation": "^4.0.0",

0 commit comments

Comments
 (0)