Skip to content

Commit 17c65ee

Browse files
l0lawrenceCopilot
andcommitted
Remove --vscode diff option from emitter-diff (HTML report is sufficient)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a233572 commit 17c65ee

3 files changed

Lines changed: 9 additions & 140 deletions

File tree

eng/emitter-diff/README.md

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ contains no language-specific logic.
1515
```
1616
baseline emitter ─┐
1717
├─ generate (adapter) ─► <work>/baseline ─┐
18-
specs ─────────────────────┤ ├─► git diff ─► terminal / VS Code / HTML
18+
specs ─────────────────────┤ ├─► git diff ─► terminal / HTML
1919
├─ generate (adapter) ─► <work>/head ─────┘
2020
head emitter ─────┘ └─► (optional) run test suites
2121
```
@@ -53,14 +53,13 @@ npx tsx eng/emitter-diff/src/cli.ts --emitter python --baseline 0.34.0
5353
### Common options
5454

5555
By default the tool writes a **clickable HTML report** (`emitter-diff.html`) into the work dir and
56-
prints a `file://` link to it. Use `--vscode` for a live VS Code diff, `--terminal` for the full
57-
patch in your shell, or `--patch`/`--html` to write to a specific file.
56+
prints a `file://` link to it. Use `--terminal` for the full patch in your shell, or
57+
`--patch`/`--html` to write to a specific file.
5858

5959
| Option | Description |
6060
| ----------------------- | ------------------------------------------------------------------------------------- |
6161
| `--name <pattern>` | Filter which specs/packages are generated |
6262
| `--html <file>` | Write the rendered HTML report to this path (default: `<work-dir>/emitter-diff.html`) |
63-
| `--vscode` | Open the diff in VS Code instead of writing HTML |
6463
| `--terminal` | Print the full colored patch to the terminal instead |
6564
| `--patch <file>` | Write the raw unified diff to a file |
6665
| `--fail-on-diff` | Exit non-zero when output differs (CI gating) |
@@ -70,19 +69,13 @@ patch in your shell, or `--patch`/`--html` to write to a specific file.
7069
| `--opt key=value` | Repeatable adapter-specific option (e.g. `--opt flavor=azure`) |
7170
| `-- <args>` | Everything after `--` is forwarded to the adapter |
7271

73-
> `--open` is kept as an alias for `--vscode`.
74-
7572
### Examples
7673

7774
```bash
7875
# Default: writes a clickable emitter-diff.html and prints a file:// link.
7976
npx tsx eng/emitter-diff/src/cli.ts --emitter python --baseline 0.34.0 \
8077
--opt flavor=azure --name authentication-api-key
8178

82-
# Open the diff live in VS Code instead:
83-
npx tsx eng/emitter-diff/src/cli.ts --emitter python --baseline 0.34.0 \
84-
--opt flavor=azure --name authentication-api-key --vscode
85-
8679
# Compare two source folders and write an HTML report to a specific path:
8780
npx tsx eng/emitter-diff/src/cli.ts --emitter python \
8881
--baseline local:/path/to/old/http-client-python \
@@ -95,49 +88,6 @@ npx tsx eng/emitter-diff/src/cli.ts --emitter python \
9588
flavor=azure --run-tests --test-env test,mypy,pyright < sha > --opt
9689
```
9790

98-
## Viewing the diff in VS Code
99-
100-
`--vscode` gives you a native, side-by-side source diff of the two generated trees. VS Code has
101-
no CLI to diff two _folders_ (`code --diff` only compares two files), so the tool stages the
102-
comparison as a throwaway git working tree under `<work-dir>/vscode-diff`: the **baseline** tree
103-
is committed, the **head** tree is overlaid on top and left staged. Opening that folder shows
104-
every changed generated file in the **Source Control** panel with red/green diffs — click any
105-
file for the side-by-side view.
106-
107-
```bash
108-
# Keep the scratch dir so it survives the run, and open the diff in VS Code:
109-
npx tsx eng/emitter-diff/src/cli.ts --emitter python \
110-
--baseline npm:0.60.0 --opt flavor=azure --name encode/duration \
111-
--work-dir ./emitter-diff-out --vscode
112-
```
113-
114-
If you generated the trees without `--vscode` (or want to reopen later), build the same view by
115-
hand from the `baseline/` and `head/` folders under your `--work-dir` and open it in VS Code:
116-
117-
```bash
118-
cd ./emitter-diff-out
119-
git init -q vscode-diff
120-
cp -r baseline/. vscode-diff/
121-
git -C vscode-diff add -A && git -C vscode-diff commit -qm baseline
122-
# overlay head on top, keeping .git
123-
find vscode-diff -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
124-
cp -r head/. vscode-diff/
125-
git -C vscode-diff add -A
126-
code vscode-diff # browse changes in the Source Control panel
127-
```
128-
129-
```powershell
130-
# PowerShell equivalent of the overlay step:
131-
cd .\emitter-diff-out
132-
git init -q vscode-diff
133-
Copy-Item -Recurse -Force .\baseline\* .\vscode-diff
134-
git -C vscode-diff add -A; git -C vscode-diff commit -qm baseline
135-
Get-ChildItem .\vscode-diff -Force | Where-Object Name -ne ".git" | Remove-Item -Recurse -Force
136-
Copy-Item -Recurse -Force .\head\* .\vscode-diff
137-
git -C vscode-diff add -A
138-
code vscode-diff
139-
```
140-
14191
## CI integration
14292

14393
`.github/workflows/ci-emitter-diff-python.yml` runs on PRs that touch the python emitter or this

eng/emitter-diff/src/cli.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { join, resolve } from "node:path";
1010
import { parseArgs } from "node:util";
1111

12-
import { diffDirs, openInVsCode, printDiff, printSummary, writeHtml, writePatch } from "./diff.js";
12+
import { diffDirs, printDiff, printSummary, writeHtml, writePatch } from "./diff.js";
1313
import { getAdapter, listAdapters } from "./registry.js";
1414
import {
1515
classifyRef,
@@ -42,7 +42,6 @@ ${color.bold("Options:")}
4242
--work-dir <dir> Scratch dir (default: a temp dir).
4343
--html <file> Write the rendered HTML diff to this path.
4444
Default output: a clickable HTML report in the work dir.
45-
--vscode Open the diff in VS Code instead of writing HTML.
4645
--terminal Print the full colored patch to the terminal instead.
4746
--patch <file> Write the raw unified diff to a file.
4847
--fail-on-diff Exit non-zero when output differs (CI gating). Exit
@@ -74,8 +73,6 @@ async function main(): Promise<number> {
7473
specs: { type: "string" },
7574
name: { type: "string" },
7675
"work-dir": { type: "string" },
77-
open: { type: "boolean" },
78-
vscode: { type: "boolean" },
7976
terminal: { type: "boolean" },
8077
patch: { type: "string" },
8178
html: { type: "string" },
@@ -119,9 +116,7 @@ async function main(): Promise<number> {
119116
// path handed to them — the resolved emitter dir and the baseline/head output
120117
// dirs — must be absolute or outputs land in the wrong tree and the diff is
121118
// silently empty (a false "no differences").
122-
const workDir = ensureDir(
123-
values["work-dir"] ? resolve(values["work-dir"]) : defaultWorkDir(),
124-
);
119+
const workDir = ensureDir(values["work-dir"] ? resolve(values["work-dir"]) : defaultWorkDir());
125120
log.info(`${color.dim("work dir:")} ${workDir}`);
126121

127122
const ctx: AdapterContext = {
@@ -220,14 +215,10 @@ async function main(): Promise<number> {
220215

221216
// Decide how to present the diff. Explicit flags win; otherwise the default
222217
// is a clickable HTML report written to the work dir.
223-
const wantsVsCode = Boolean(values.vscode || values.open);
224218
const wantsTerminal = Boolean(values.terminal);
225219
const wantsPatch = Boolean(values.patch);
226220
const htmlTarget =
227-
values.html ??
228-
(!wantsVsCode && !wantsTerminal && !wantsPatch
229-
? join(workDir, "emitter-diff.html")
230-
: undefined);
221+
values.html ?? (!wantsTerminal && !wantsPatch ? join(workDir, "emitter-diff.html") : undefined);
231222

232223
if (!diff.hasChanges) {
233224
log.success("No differences between baseline and head output.");
@@ -239,7 +230,6 @@ async function main(): Promise<number> {
239230

240231
if (wantsPatch) writePatch(diff, values.patch as string, log);
241232
if (htmlTarget) await writeHtml(diff, htmlTarget, log);
242-
if (wantsVsCode) await openInVsCode(baselineOut, headOut, workDir, log);
243233

244234
// Optionally run test suites.
245235
if (values["run-tests"]) {

eng/emitter-diff/src/diff.ts

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
* Diff engine. One canonical unified patch (`git diff --no-index`) is the
33
* source of truth; it is then rendered for whichever environment is in use:
44
* - terminal: colored patch + summary
5-
* - local `--open`: VS Code folder diff
65
* - CI `--html`: rendered via diff2html (optional dependency, lazily loaded)
76
*/
8-
import { cpSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7+
import { readFileSync, writeFileSync } from "node:fs";
98
import { createRequire } from "node:module";
10-
import { basename, dirname, join, resolve } from "node:path";
9+
import { basename, dirname, resolve } from "node:path";
1110
import { pathToFileURL } from "node:url";
1211

1312
import type { Logger } from "./types.js";
14-
import { color, run, runChecked } from "./util.js";
13+
import { color, run } from "./util.js";
1514

1615
export interface DiffResult {
1716
/** The unified patch text (empty when there are no differences). */
@@ -190,73 +189,3 @@ ${body}
190189
log.success(`Wrote HTML diff to ${abs}`);
191190
log.info(`${color.bold("Open it:")} ${pathToFileURL(abs).href}`);
192191
}
193-
194-
/**
195-
* Open a native side-by-side diff of the two generated trees in VS Code.
196-
*
197-
* VS Code has no CLI to diff two folders (`code --diff` only compares two
198-
* files), so we materialize the comparison as a throwaway git working-tree
199-
* change: commit the baseline tree, then overlay the head tree on top and leave
200-
* it unstaged. Opening that folder surfaces every changed generated file in the
201-
* Source Control view with red/green side-by-side diffs.
202-
*/
203-
export async function openInVsCode(
204-
baselineDir: string,
205-
headDir: string,
206-
workDir: string,
207-
log: Logger,
208-
): Promise<void> {
209-
log.step("Preparing VS Code diff");
210-
const repo = join(workDir, "vscode-diff");
211-
rmSync(repo, { recursive: true, force: true });
212-
mkdirSync(repo, { recursive: true });
213-
214-
const git = (args: string[]) =>
215-
runChecked("git", [
216-
"-C",
217-
repo,
218-
"-c",
219-
"user.email=emitter-diff@local",
220-
"-c",
221-
"user.name=emitter-diff",
222-
"-c",
223-
"commit.gpgsign=false",
224-
"-c",
225-
"core.autocrlf=false",
226-
...args,
227-
]);
228-
229-
await git(["init", "-q"]);
230-
// Commit the baseline tree as the starting point.
231-
cpSync(baselineDir, repo, { recursive: true });
232-
await git(["add", "-A"]);
233-
await git(["commit", "-q", "-m", "baseline", "--allow-empty"]);
234-
235-
// Overlay the head tree (keeping .git), then stage so VS Code shows the diff.
236-
for (const entry of readdirSync(repo)) {
237-
if (entry === ".git") continue;
238-
rmSync(join(repo, entry), { recursive: true, force: true });
239-
}
240-
cpSync(headDir, repo, { recursive: true });
241-
// Drop all index entries first, then re-add. A plain `git add -A` decides a
242-
// file is unchanged from (size, mtime) and skips re-hashing it; because the
243-
// baseline commit and the head overlay are written within the same second,
244-
// a same-size content edit would be treated as clean and never staged (so it
245-
// would silently not appear in VS Code). Clearing the index forces git to
246-
// re-hash every file's content, surfacing every real modification.
247-
await git(["rm", "-r", "--cached", "-q", "--", "."]);
248-
await git(["add", "-A"]);
249-
250-
const result = await run("code", [repo]);
251-
if (result.code !== 0) {
252-
log.warn(
253-
"Could not launch VS Code (`code` not on PATH?). Open the folder manually " +
254-
`and use the Source Control view to browse the diff: ${repo}`,
255-
);
256-
return;
257-
}
258-
log.success(
259-
`Opened ${repo} in VS Code — use the Source Control panel to browse the diff ` +
260-
"(baseline = last commit, head = working tree).",
261-
);
262-
}

0 commit comments

Comments
 (0)