scm: show added and removed line counts in the Source Control view - #329140
scm: show added and removed line counts in the Source Control view#329140thexin7 wants to merge 2 commits into
Conversation
b4165fc to
2da20e0
Compare
|
@microsoft-github-policy-service agree |
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
There was a problem hiding this comment.
Pull request overview
Adds per-resource and per-group line-change statistics to Source Control, backed by a proposed SCM API and Git integration.
Changes:
- Adds proposed diff-statistics API plumbing.
- Renders configurable, themed, accessible
+/-counts. - Computes Git statistics with tests for untracked-file line counting.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/vscode-dts/vscode.proposed.scmDiffStatistics.d.ts |
Defines the proposed API. |
src/vs/workbench/contrib/scm/common/scm.ts |
Adds internal statistics types. |
src/vs/workbench/contrib/scm/browser/scmViewPane.ts |
Renders and announces statistics. |
src/vs/workbench/contrib/scm/browser/scm.contribution.ts |
Registers the visibility setting. |
src/vs/workbench/contrib/scm/browser/media/scm.css |
Styles statistics. |
src/vs/workbench/api/common/extHostSCM.ts |
Serializes extension-provided statistics. |
src/vs/workbench/api/common/extHost.protocol.ts |
Extends the SCM protocol tuple. |
src/vs/workbench/api/browser/mainThreadSCM.ts |
Deserializes statistics. |
src/vs/platform/extensions/common/extensionsApiProposals.ts |
Registers the API proposal. |
extensions/git/tsconfig.json |
Includes the proposal declaration. |
extensions/git/src/test/diffStatistics.test.ts |
Tests file-line counting. |
extensions/git/src/repository.ts |
Computes and attaches statistics. |
extensions/git/src/git.ts |
Runs and parses Git diff statistics. |
extensions/git/package.json |
Enables the proposal for Git. |
build/lib/stylelint/vscode-known-variables.json |
Allows the new theme variables. |
| /** | ||
| * Untracked files are not reported by `git diff`, so their line count is read from | ||
| * disk. Files larger than this are skipped to bound the amount of I/O per status | ||
| * update. | ||
| */ | ||
| const DIFF_STATISTICS_MAX_FILE_SIZE = 1024 * 1024; |
| return undefined; | ||
| }); | ||
|
|
||
| await this.applyDiffStatistics(indexGroup, workingTreeGroup, untrackedGroup, similarityThreshold, cancellationToken); |
| * resources, while the group header is re-rendered on every scroll. Cache the result | ||
| * keyed on the resources array, which is replaced whenever the group changes. | ||
| */ | ||
| const resourceGroupDiffStatistics = new WeakMap<readonly ISCMResource[], ISCMResourceDiffStatistics | null>(); |
| } | ||
|
|
||
| private async diffFilesWithStats(ref: string | undefined, options: { cached: boolean; similarityThreshold?: number }): Promise<DiffChange[]> { | ||
| const args = ['diff', '--raw', '--numstat', '--diff-filter=ADMR', '-z']; |
| await fs.rm(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| test('countFileLines', async () => { |
Adds a proposed `SourceControlResourceState.diffStatistics` API and renders the reported insertions/deletions next to each resource, as well as the aggregate of a resource group on its header. The git extension fills the statistics in from `git diff --raw --numstat` for the index and the working tree. It skips repositories that hit the status limit, and can be turned off entirely with `git.diffStatistics`.
2da20e0 to
4586fe0
Compare
|
Force-pushed a rewrite that squashes this down to a single commit and cuts the diff from +490 to +327. The inline review comments above are now outdated, so here is how each one was handled:
Two things I did not take:
Also fixed while verifying: the accessible label said Verified against a repository with staged, unstaged, deleted, added and untracked files — the rendered counts match |
Fixes #306507
Shows how many lines each change adds and removes in the Source Control view — next to every resource, and aggregated on the resource group header.
Full window
How it works
SourceControlResourceState.diffStatistics(scmDiffStatistics)git diff --raw --numstatper group (index + working tree), off switch viagit.diffStatistics+N/-Mper resource and per group, with dedicated theme colorsThe counts reuse the existing
scmGraph.historyItemHover*Foregroundramp through two new colors,scm.diffStatisticsInsertionsForegroundandscm.diffStatisticsDeletionsForeground, so the graph and the resource list stay on one palette.Scope
Deliberately not covered, to keep the change small:
--diff-filter=ADMR; the shared--rawparser does not model them today.Cost control: the two diff commands only run when
git.diffStatisticsis enabled, and are skipped entirely for repositories that hitgit.statusLimit.Verifying
+N/ red-M, and that each group header shows the sum.git diff --numstatandgit diff --cached --numstat."git.diffStatistics": falseand confirm the counts disappear without a reload.Screen reader labels read as
README.md, Index Modified, 9 insertions, src— the visual counts arearia-hiddenso they are not announced twice.