Skip to content

feat(scm): Customizable SCM Graph History Item Formatting (GitLens-style Variable Support) #260232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Zahariel1942
Copy link

Overview

This PR implements customizable formatting for SCM Graph History items in VS Code #255719, allowing users to personalize how commit history is displayed in the Source Control Graph view. Inspired by GitLens, it introduces a configuration option for variable-based formatting, enabling greater flexibility and clarity for teams and individuals.

Key Changes

1. Configuration Setting

Added "scm.graph.historyItemFormat" to src/vs/workbench/contrib/scm/browser/scm.contribution.ts:

  • Type: string
  • Description: Controls the format of each history item in the Source Control Graph view. Supports variables:
    • ${author} — Commit author name
    • ${authorEmail} — Author email
    • ${subject} — Commit subject/title
    • ${message} — Full commit message
    • ${hash} — Full commit hash
    • ${displayId} — Shortened commit hash
    • ${date} — Relative date (e.g., "2 hours ago")
    • ${timestamp} — Full timestamp

Examples:

  • ${subject}
  • ${displayId} - ${subject}
  • ${author} • ${subject}
  • [${displayId}] ${subject} by ${author}
  • ${subject} (${date})

2. Formatting Function

Introduced formatHistoryItem in src/vs/workbench/contrib/scm/browser/util.ts:

  • Replaces variables in the format string with actual commit data.
  • Handles missing values gracefully (empty string fallback).
  • Preserves line breaks in commit messages.
  • Removes trailing spaces for clean appearance.

3. Renderer Integration

Updated HistoryItemRenderer in src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts:

  • Observes configuration changes for "scm.graph.historyItemFormat" using VS Code's observable pattern.
  • Uses autorun for real-time UI updates when settings change.
  • Applies custom formatting via formatHistoryItem.

4. Comprehensive Testing

Added test coverage in src/vs/workbench/contrib/scm/test/browser/util.test.ts:

  • Tests all supported variables.
  • Validates default and multi-variable formats.
  • Checks handling of missing values and edge cases.
  • Includes GitLens-style example formats.

@Zahariel1942
Copy link
Author

@microsoft-github-policy-service agree

@Zahariel1942 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

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.

2 participants