-
Notifications
You must be signed in to change notification settings - Fork 0
[issues/298] Warn user when generating link from file with unsaved changes #305
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
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. WalkthroughAdds a dirty-buffer warning when generating a RangeLink from a file with unsaved changes. When enabled via Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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.
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)
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
DirtyBufferWarningResultenum for type-safe dialog outcomeshandleDirtyBufferWarning()method with switch/exhaustive check patternrangelink.warnOnDirtyBuffersetting (default: true) to control the warningConfigReader.getBoolean()method for typed boolean settingsTest Plan
Documentation
Related
Summary by CodeRabbit
New Features
Documentation