feat(lsp): support untitled:// URI scheme for unsaved documents#192
feat(lsp): support untitled:// URI scheme for unsaved documents#192tinovyatkin merged 2 commits intomainfrom
Conversation
Enable the LSP server to lint unsaved Dockerfile buffers that have not yet been saved to disk. Editors assign an untitled: URI to new documents instead of the usual file: scheme, and the server now handles this gracefully instead of silently failing. Changes: - uriToPath returns a synthetic cwd-based path for non-file URIs so config discovery and workspace settings matching still work. - isUntitledURI helper for scheme detection. - Pull diagnostics for closed untitled documents return empty results instead of attempting to read from a non-existent path. - contentForURI returns os.ErrNotExist for closed untitled documents instead of reading the wrong file. Inspired by oxc-project/oxc#19287. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds handling for virtual/untitled URIs in the LSP server: detects non-file URIs, avoids reading unsaved documents from disk, returns empty FullDocumentDiagnosticReport for closed untitled docs, and generates synthetic paths for non-file URIs to enable project config discovery. Tests for these behaviors were added. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Language Server Protocol (LSP) server's capabilities by extending its support to unsaved Dockerfile documents. Previously, the server could not process files using the 'untitled:' URI scheme, leading to a lack of features like linting for new, unsaved files. The changes introduce mechanisms to correctly interpret these URIs, generate appropriate temporary paths for internal processing, and handle the lifecycle of these in-memory documents, ensuring a consistent user experience across both saved and unsaved files. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is a great feature that improves the LSP experience for unsaved files. The approach of using a synthetic path for config discovery is clever, and the changes are well-tested. I have one main suggestion to improve consistency in handling different types of virtual URIs (like untitled: and vscode-notebook-cell:), which will make the implementation more robust.
Merging this PR will not alter performance
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/lspserver/execute_command_test.go`:
- Around line 156-163: The test TestContentForURI_UntitledURI_ClosedDocument
currently accepts any error; tighten it to assert the specific "not-exist"
sentinel so the contract is locked. Replace require.Error(t, err) with an
assertion that the returned error is the sentinel (e.g. require.ErrorIs(t, err,
ErrNotExist) or require.True(t, errors.Is(err, ErrNotExist))) when calling
s.contentForURI("untitled:Untitled-1"); add an import for errors if you use
errors.Is. Ensure you reference the sentinel symbol ErrNotExist (or
fs.ErrNotExist if that is the project sentinel) in the assertion.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
internal/lspserver/diagnostics.gointernal/lspserver/diagnostics_test.gointernal/lspserver/execute_command.gointernal/lspserver/execute_command_test.gointernal/lspserver/server_test.go
…hemes Rename isUntitledURI → isVirtualURI to correctly handle any virtual document scheme (e.g. vscode-notebook-cell:, untitled:) rather than only untitled:. The new implementation checks for any non-file scheme using url.Parse, consistent with uriToPath's existing logic. Also tightens TestContentForURI_UntitledURI_ClosedDocument to assert os.ErrNotExist specifically. Addresses: #192 (comment) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
untitled:URI scheme instead offile:uriToPathnow returns a synthetic cwd-based path for non-file URIs so config discovery and workspace settings matching work correctlycontentForURIgracefully return empty results for closed untitled documents instead of reading from a nonexistent pathisUntitledURIhelper for clean scheme detectionContext
Inspired by oxc-project/oxc#19287. When a user creates a new file in their editor and sets the language to Dockerfile (without saving), the editor assigns an
untitled:URI. Previously the LSP server silently failed becauseuriToPathcouldn't convert this to a valid file path. Now all LSP features (diagnostics, code actions, formatting, fix-all) work for unsaved documents.Closes #168
Test plan
TestURIToPath— verifies untitled and vscode-notebook URIs resolve to absolute synthetic pathsTestIsUntitledURI— scheme detection for various URI formsTestPublishDiagnostics_UntitledURI— push diagnostics dispatched with correct URI and contentTestHandleDiagnostic_UntitledURI_ClosedDocument— pull diagnostics return empty for closed untitled docsTestContentForURI_ReturnsOpenUntitledDocumentContent— open untitled docs return in-memory contentTestContentForURI_UntitledURI_ClosedDocument— closed untitled docs return error (no disk fallback)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests