Skip to content

Support external diff algorithms in internal diff editor #84981

Open

Description

@pvspain

Reopening closed feature request #30694

Openness, extensibility and customisability are the features that keep me coming back to VSCode. Being built upon an OSS core (Electron) was strong evidence of a change of culture at Microsoft.

In that spirit, would you please reconsider the original request from myfairsyer. Different diffing algorithms produce significantly different results and are suited to different purposes. There is no one-size-fits-all solution.

Paraphrasing myfairsyer, please consider abstracting the diff functionality to allow different hunk-list providers. Respecting the algorithm set in Git configuration would be an ideal baseline.

As another example, BeyondCompare allows significant customisation, including 2 of the 4 algorithms offered by Git.

Activity

  1. added
    diff-editor
    feature-request
    on Nov 18, 2019
  2. ksze commented on Nov 21, 2019

    @ksze

    Yep, I agree that VS code should support external diff tools with their known algorithms.

  3. Hermholtz commented on Nov 29, 2019

    @Hermholtz

    I'm missing Git's "patience" algo.

    In my opinion there's a place for API and extensibility here. We could have various diff algorithms available as extensions, in addition to a good set provided right inside VS Code.

  4. vscodebot commented on Jan 15, 2020

    @vscodebot

    This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  5. vscodebot commented on Feb 14, 2020

    @vscodebot

    🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  6. daevski commented on Feb 23, 2022

    @daevski

    Yeah, this is ridiculous; notepad++ compare on the left, vscode compare on the right.

    notepad++vs-vscode-compare

  7. bersbersbers commented on Mar 18, 2022

    @bersbersbers

    I would like to reference feature request #145068 here (disclaimer: it is taking votes, and I am the author) which may or may not make sense considering when defining an interface for alternative diff algorithms or diff extensions (in which case it might also be implemented independent of the diff algorithm as some kind of post-processing.)

    In essence, I propose another change category (in addition to the current ones, which are green = line added and red = line removed). This new category (let's call it gray) shall represent lines which have no other change but being commented out or in (using language-specific grammar rules) with respect to the reference lines, allowing to overscroll them more easily because color and font style encode the only change (enabling/disabling the line).

  8. 0dB commented on Sep 28, 2022

    @0dB

    this is ridiculous; notepad++ compare on the left, vscode compare on the right.

    Highlighting inside a line is an Ediff feature. Diff just looks for changed lines, no matter what the algorithm is. The difference between the diff algorithms (the original diff, myers, minimal, patience, histogram) is how the lines between two files are ligned up. So it seems Ediff is being used on the left by notepad++ and not on the right. In Emacs for example you can activate Ediff for displaying a diff / diff3 output (and this is independent from the diff algorithm).

  9. pawk3k commented on Aug 21, 2023

    @pawk3k

    Do you have any updates on that? Do you have any plans on adding support for external diff tools? 🤔 . I'm thinking more about using difftasctic as a diff tool for vs code.
    I'm not the only one here :
    https://news.ycombinator.com/item?id=30841244.
    https://stackoverflow.com/questions/73671245/how-to-change-the-diff-tool-used-by-vscode-for-git
    Also, if anyone knows if it's possible right now, how can we achieve that?

  10. maffinyep commented on Feb 4, 2025

    @maffinyep

    up

  11. quenbyako commented on Mar 14, 2026

    @quenbyako

    Bump this feature. I got same issue when i started to work with code reviewing of AI slop code (yes, who knew that it's the reason), and it's extremely hard to see, what AI refactored, what moved to other part etc. Histogram diffs work amazingly perfect especially when AI (or any other junior dev with auto fixing tools) writes code and maintainer has to review it somehow.

  12. zamkorus commented on Oct 19, 2026

    @zamkorus

    Henning Dieterichs (@hediet), here is a concrete design for this as a proposed API. Would you accept a PR along these lines? I'm happy to change the design before writing it.

    Summary

    An extension contributes a diff algorithm, and the built-in diff editor uses it only to compute the diff. Rendering, highlighting and navigation stay as they are. The algorithm is selected in diffEditor.diffAlgorithm next to the built-in ones.

    Contribution and API

    "contributes": {
      "diffAlgorithms": [
        { "id": "histogram", "title": "%histogram.title%", "description": "%histogram.description%" }
      ]
    }
    • The setting value is "<extension id>:<id>". Contributed algorithms appear in the setting's enum before their extension activates, as editor.defaultFormatter lists formatters.
    • The implicit activation event is onDiffAlgorithm:<extension id>:<id>, like onTerminalProfile:<id>.
    declare module 'vscode' {
    
    	// https://github.com/microsoft/vscode/issues/84981
    
    	export interface DiffAlgorithmOptions {
    		readonly ignoreTrimWhitespace: boolean;
    		/** 0 means no limit. */
    		readonly maxComputationTimeMs: number;
    		readonly computeMoves: boolean;
    		readonly extendToSubwords: boolean;
    	}
    
    	/** Half-open UTF-16 offsets into the text passed to `computeDiff`. */
    	export interface DiffOffsetRange {
    		readonly start: number;
    		readonly endExclusive: number;
    	}
    
    	export interface DiffReplacement {
    		readonly range: DiffOffsetRange;
    		readonly newText: string;
    	}
    
    	export interface DiffMove {
    		readonly range: { readonly original: DiffOffsetRange; readonly modified: DiffOffsetRange };
    	}
    
    	export interface DiffAlgorithmResult {
    		readonly edits: { readonly replacements: readonly DiffReplacement[] };
    		readonly moves: readonly DiffMove[];
    		readonly hitTimeout: boolean;
    	}
    
    	export interface DiffAlgorithmProvider {
    		/**
    		 * `original` and `modified` are the documents' lines joined with `\n`.
    		 * Replacements must be sorted, non-overlapping and index into `original`.
    		 */
    		computeDiff(original: string, modified: string, options: DiffAlgorithmOptions, token: CancellationToken): ProviderResult<DiffAlgorithmResult>;
    	}
    
    	export namespace workspace {
    		/** Registers an algorithm the calling extension declares in `contributes.diffAlgorithms`. */
    		export function registerDiffAlgorithmProvider(id: string, provider: DiffAlgorithmProvider): Disposable;
    	}
    }

    DiffAlgorithmResult has the same shape as the result of @vscode/diff's computeDiff, so a provider can wrap that package and return its result unchanged.

    Architecture

    Editor layer

    • WorkerBasedDocumentDiffProvider already delegates to an IDocumentDiffProvider object. IDocumentDiffFactoryOptions and the option validation would be widened to accept extension ids. The web worker only ever receives built-in names.
    • The conversion from offset edits to LinesDiff in externalLinesDiffComputer.ts would move into a shared function that both paths use.
    • The diff cache key would include the algorithm, which it doesn't today.

    Workbench

    • A diffAlgorithms extension point and an IDiffAlgorithmsService would track contributions and registered providers. A workbench contribution would keep the setting's enum in sync.
    • A workbench IDiffProviderFactoryService would replace the editor's default; its only production caller is diffEditorViewModel.ts. Built-in names take today's worker path. An extension id gets an IDocumentDiffProvider that activates the extension, calls it over RPC, then validates and converts the result.
    • The RPC has $registerDiffAlgorithmProvider and $unregisterDiffAlgorithmProvider on the main thread and $computeDiff(handle, original, modified, options, token) in the extension host. Documents travel as { uri, versionId } and are read from ExtHostDocuments. Text is sent only for models the extension host doesn't mirror.

    Safety

    • Every call gets the cancellation token and a hard deadline.
    • A result is accepted only if its replacements are sorted, non-overlapping and in range, and applying them to original gives modified.
    • A missing provider, an error, a timeout or an invalid result falls back to advanced and notifies the user once.

    Scope

    • First PR: the diff editor only. Quick diff, notebook diffs, chat and mergeEditor.diffAlgorithm can follow separately.
    • Unit tests: cover the conversion, the provider resolution and the fallback.
    • API test: in vscode-api-tests, a provider that wraps @vscode/diff must produce the same diff as advanced-external.

    Open questions

    1. Which namespace should it live in: workspace, window (like registerTerminalProfileProvider) or languages?
    2. Should the value be "<extension id>:<id>" in diffEditor.diffAlgorithm, or a separate setting?
    3. Should the provider receive strings or TextDocuments? Strings keep @vscode/diff compatibility, while documents save one copy of the text.
    4. Should moves have no inner changes, as advanced-external does today, or should DiffMove get optional replacements?
    5. Should there be one global choice or a per-language setting?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

diff-editorfeature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions