Urgent.News

What's breaking now, across thousands of outlets.

Tech

How a Live Unsaved-Changes Diff Works in a VS Code Extension

| Baselines, Myers line diffs, debouncing, undo/redo, and the edge cases behind SavePoint Diff's gutter markers. I recently shipped SavePoint Diff , a VS Code extension that shows gutter markers for unsaved changes. Here's the design, in case you're thinking about building something similar. The core idea: a baseline Everything revolves around one string per file, the baseline , meaning the last…

SavePoint Diff is a VS Code extension that highlights unsaved changes through gutter markers. Its core concept revolves around a baseline, which represents the last saved content of each file. When a file is opened, its content is captured as the baseline. Upon editing, the baseline is compared against the current buffer, and the result is displayed as gutter decorations. Saving the file overwrites the baseline with the current content, and the markers are then cleared.

To optimize performance, the diffing process is delayed until typing pauses, using a configurable debounce time. Larger files above a certain size threshold are excluded from live diffing to conserve resources. Undo and redo actions are free because the diff is always recomputed from the baseline versus the current text. This approach results in an empty diff when reverting to the saved state, causing the markers to disappear, and their reappearance upon redoing the changes.

The extension handles several edge cases, such as normalizing CRLF and lone CR line endings, reordering multi-change reverts to prevent earlier edits from affecting later ones, and automatically syncing the baseline when a file stops being dirty without a save. Invalid settings, like a bad maxFileSize value, now fall back to the default configuration.

Additionally, the extension supports savepoints, which are essentially baseline moves to the current in-memory content without writing to disk. The MIT-licensed code is available for further development or contributions on GitHub and the Visual Studio Marketplace.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Git seance: I let deleted functions speak from beyond the grave (with local Gemma)

This is a submission for the Hacktoberfest Open-Source AI Challenge: Ghost in the Machine What I Built Every repository is a graveyard.

  • Script reads repository's git history to summon deleted functions
  • Identifies functions never returned, reveals writer, addition date, removal commit
  • Demonstrated on psf/requests repo, uncovered seven "ghosts" from last 400 commits

More from Friday 30 October →