Skip to content

Add per-file diff stats (insertions/deletions) to tree view#143

Open
filoucool wants to merge 6 commits into
letmaik:masterfrom
filoucool:add-git-diff
Open

Add per-file diff stats (insertions/deletions) to tree view#143
filoucool wants to merge 6 commits into
letmaik:masterfrom
filoucool:add-git-diff

Conversation

@filoucool

Copy link
Copy Markdown

First off, thank you @letmaik for building and maintaining this extension. It has become one of my most used tools in VS Code and it's become an essential part of my workflow.

This PR adds an opt-in feature that displays per-file insertion and deletion counts (+N -N) next to each filename in the tree view, giving a quick sense of change magnitude without having to open individual diffs. This is personally something I use a lot during my work day. Being able to glance at which files have the heaviest changes without clicking into each one saves me a surprising amount of time. I've had this running in my custom build for a while now and recently decided to clean it up and share it with the community.

What it does

  • Runs git diff --numstat to gather per-file insertion/deletion counts for tracked files
  • Computes stats for untracked files by reading them directly (line count for text files, binary label for binary files)
  • Displays the stats after the filename in the tree item label (e.g. myFile.ts +42 -7)
  • Stats update live as files are edited (respects the existing 2-second debounce)
  • Fully toggleable via gitTreeCompare.showDiffStats setting (disabled by default)

Changes

  • src/gitHelper.ts -> Added IDiffStats interface, parseDiffNumstat() parser, computeUntrackedStats() for untracked files, and a showDiffStats path in diffIndex().
  • src/treeProvider.ts -> Reads the new config, passes stats through to FileElement, and formats them in toTreeItem() via a formatDiffStats() helper.
  • package.json -> Added gitTreeCompare.showDiffStats boolean config.

Ideally, insertions would be green and deletions red, but the VS Code TreeItem API does not support inline color formatting within labels or descriptions, so the stats are displayed as just plain text.

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant