Skip to content

Conversation

@couimet
Copy link
Owner

@couimet couimet commented Feb 5, 2026

Summary

Adds a warning dialog when generating a link from a file with unsaved changes. This prevents users from creating links that may point to incorrect positions after the file is saved. Users can choose to save first, continue anyway, or abort the operation.

Changes

  • Added DirtyBufferWarningResult enum for type-safe dialog outcomes
  • Implemented handleDirtyBufferWarning() method with switch/exhaustive check pattern
  • Added rangelink.warnOnDirtyBuffer setting (default: true) to control the warning
  • Added ConfigReader.getBoolean() method for typed boolean settings
  • Optimized to only read config when document is actually dirty
  • Added i18n message codes for warning text and button labels

Test Plan

  • All existing tests pass (1383 tests)
  • New tests added for:
    • Warning shown when document is dirty and setting enabled
    • Warning NOT shown when setting disabled
    • Warning NOT shown when document is not dirty
    • "Save & Generate" saves document and continues
    • "Generate Anyway" continues without saving
    • Dismissal aborts link generation
    • ConfigReader.getBoolean() behavior
    • package.json contract for new setting

Documentation

  • CHANGELOG.md: Entry added under [Unreleased] - Added section
  • README.md: Documented warnOnDirtyBuffer setting in restructured Configuration section

Related

Summary by CodeRabbit

  • New Features

    • Added a warning dialog when generating links from files with unsaved changes, offering "Save & Generate", "Generate Anyway", or dismiss to abort.
    • Added a new "Warn on Dirty Buffer" setting (enabled by default) to control this behavior.
  • Documentation

    • Updated settings documentation to describe the new warning and delimiter configuration format.

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Warning

Rate limit exceeded

@couimet has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

Adds a dirty-buffer warning when generating a RangeLink from a file with unsaved changes. When enabled via rangelink.warnOnDirtyBuffer (default: true), a dialog offers "Save & Generate", "Generate Anyway", or dismiss; generation is aborted on dismiss or failed save.

Changes

Cohort / File(s) Summary
Docs & Manifest
packages/rangelink-vscode-extension/CHANGELOG.md, packages/rangelink-vscode-extension/README.md, packages/rangelink-vscode-extension/package.json
Documented Dirty Buffer Warning and added new boolean setting rangelink.warnOnDirtyBuffer (default: true).
Core Logic
packages/rangelink-vscode-extension/src/RangeLinkService.ts
Integrated dirty-buffer check into generateLinkFromSelection() and added handleDirtyBufferWarning() flow handling SaveAndGenerate, GenerateAnyway, Dismissed, and SaveFailed outcomes; added relevant imports and error handling.
Config API & Tests
packages/rangelink-vscode-extension/src/config/ConfigReader.ts, packages/rangelink-vscode-extension/src/config/__tests__/ConfigReader.test.ts, packages/rangelink-vscode-extension/src/__tests__/helpers/createMockConfigReader.ts
Added ConfigReader.getBoolean(key, defaultValue) with tests and test helper getBoolean mock.
Types & Constants
packages/rangelink-vscode-extension/src/types/DirtyBufferWarningResult.ts, packages/rangelink-vscode-extension/src/types/MessageCode.ts, packages/rangelink-vscode-extension/src/types/index.ts, packages/rangelink-vscode-extension/src/constants/settingKeys.ts
Added DirtyBufferWarningResult enum and exported it; added new MessageCode entries for dirty-buffer warnings; added SETTING_WARN_ON_DIRTY_BUFFER constant.
Localization
packages/rangelink-vscode-extension/src/i18n/messages.en.ts
Added localized strings for the dirty-buffer warning text, continue button, save button, and save-failed message.
Tests
packages/rangelink-vscode-extension/src/__tests__/RangeLinkService.test.ts, packages/rangelink-vscode-extension/src/__tests__/constants/packageJsonContracts.test.ts
Comprehensive tests for dirty-buffer warning scenarios (save, continue, dismiss, failed save) and package.json contract test updated for new config property.

Sequence Diagram

sequenceDiagram
    participant User
    participant Extension as RangeLink Service
    participant Config as Config Reader
    participant Dialog as VSCode Dialog
    participant Document

    User->>Extension: Trigger generateLinkFromSelection()
    Extension->>Document: check document.isDirty
    alt document is dirty
        Extension->>Config: getBoolean("warnOnDirtyBuffer")
        Config-->>Extension: true
        Extension->>Dialog: show warning (message + "Save & Generate", "Generate Anyway")
        Dialog-->>Extension: SaveAndGenerate / GenerateAnyway / Dismissed
        alt SaveAndGenerate
            Extension->>Document: save()
            Document-->>Extension: saved / save failed
            alt saved
                Extension->>Extension: generate link
                Extension-->>User: return link
            else save failed
                Extension-->>User: abort (show save-failed message)
            end
        else GenerateAnyway
            Extension->>Extension: generate link (unsaved buffer)
            Extension-->>User: return link
        else Dismissed
            Extension-->>User: abort (no link)
        end
    else document is clean
        Extension->>Extension: generate link
        Extension-->>User: return link
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #250 — Modifies RangeLinkService.ts and its generate flow; likely to interact with the dirty-buffer gating added here.
  • PR #256 — Adjusts i18n/message handling and RangeLinkService messaging; overlaps with new MessageCode entries and messages.

Poem

🐰
I sniff the buffer, quiet and wary,
"Save?" I ask, with whiskers airy.
Click save, or carry on—your call;
RangeLinks now better, short or tall.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and clearly summarizes the main change: adding a warning when generating links from unsaved files.
Linked Issues check ✅ Passed The implementation fully satisfies #298 requirements: detects dirty buffers, displays a warning dialog with save/continue/dismiss options, allows generation to proceed, and includes a configurable setting.
Out of Scope Changes check ✅ Passed All changes directly support the dirty buffer warning feature. ConfigReader.getBoolean() and test infrastructure additions are appropriate supporting changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issues/298

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/rangelink-vscode-extension/src/RangeLinkService.ts`:
- Around line 15-18: Reorder the imports in RangeLinkService.ts so all type-only
imports come before value imports: move the "import type {
PasteDestinationManager } from './destinations/PasteDestinationManager';" (and
the "import type { PasteDestination } from './destinations/PasteDestination';"
if not already first) above the non-type imports (RangeLinkExtensionError and
RangeLinkExtensionErrorCodes) to satisfy ESLint import/order.
- Around line 446-449: The handler for DirtyBufferWarningResult.SaveAndGenerate
(in handleDirtyBufferWarning) currently awaits document.save() but ignores its
boolean result; change it to capture the save result (e.g., const saved = await
document.save()) and if saved is false log that the save was canceled/failed and
return an abort result (for example DirtyBufferWarningResult.Cancel or other
existing "abort" enum value) so link generation does not proceed against an
unsaved buffer; ensure the logger still records the user's choice when save
succeeds and only continue to return SaveAndGenerate when saved === true.

couimet added a commit that referenced this pull request Feb 6, 2026
Addresses CodeRabbit review feedback on PR #305:

1. Import order: Move `import type` statements before value imports to satisfy ESLint import/order rule.

2. Save result handling: `document.save()` returns a boolean — if save fails or is cancelled, link generation now aborts with a user-facing warning instead of silently proceeding with a dirty buffer.

Adds `SaveFailed` enum value to `DirtyBufferWarningResult` for semantic clarity (distinct from `Dismissed`).

Ref: #305 (review)
Adds i18n message codes and English translations for the dirty buffer warning
feature that will alert users when generating links from files with unsaved changes.

Message codes added:
- WARN_LINK_DIRTY_BUFFER: Warning message text
- WARN_LINK_DIRTY_BUFFER_SAVE: "Save & Generate" button label
- WARN_LINK_DIRTY_BUFFER_CONTINUE: "Generate Anyway" button label
Adds the `rangelink.warnOnDirtyBuffer` setting (default: true) that controls
whether a warning is shown when generating a link from a file with unsaved changes.

Changes:
- Added setting to package.json contributes.configuration
- Added SETTING_WARN_ON_DIRTY_BUFFER constant
- Added ConfigReader.getBoolean() method for boolean settings
- Added tests for the new config method and package.json contract
…tion()`

Adds a warning dialog when generating a link from a file with unsaved changes.
This helps users avoid creating links that may point to incorrect positions after the file is saved.

User options:
- "Save & Generate": Save the file first, then generate the link
- "Generate Anyway": Generate the link without saving
- Dismiss: Abort link generation

The warning respects the `rangelink.warnOnDirtyBuffer` setting (default: true).
Config is only read when document is actually dirty (optimization).

Implementation uses `DirtyBufferWarningResult` enum for richer API instead of boolean return values.
Uses switch statement with exhaustive checking and UNEXPECTED_CODE_PATH default.

Changes:
- DirtyBufferWarningResult.ts: New enum for warning dialog outcomes
- RangeLinkService.ts: Added handleDirtyBufferWarning() with switch/exhaustive check pattern
- RangeLinkService.test.ts: Added 6 tests for dirty buffer warning behavior
- createMockConfigReader.ts: Added getBoolean support
- CHANGELOG.md: Added entry for dirty buffer warning feature
- README.md: Documented warnOnDirtyBuffer setting with restructured Configuration section
Addresses CodeRabbit review feedback on PR #305:

1. Import order: Move `import type` statements before value imports to satisfy ESLint import/order rule.

2. Save result handling: `document.save()` returns a boolean — if save fails or is cancelled, link generation now aborts with a user-facing warning instead of silently proceeding with a dirty buffer.

Adds `SaveFailed` enum value to `DirtyBufferWarningResult` for semantic clarity (distinct from `Dismissed`).

Ref: #305 (review)
@couimet couimet merged commit 690c9c0 into main Feb 6, 2026
2 checks passed
@couimet couimet deleted the issues/298 branch February 6, 2026 03:49
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.

Warn user when generating link from file with unsaved changes

1 participant