Enhance RenameHandler to handle null capabilities gracefully and add tests for registration options#2296
Open
mgreenegit wants to merge 3 commits into
Open
Enhance RenameHandler to handle null capabilities gracefully and add tests for registration options#2296mgreenegit wants to merge 3 commits into
mgreenegit wants to merge 3 commits into
Conversation
…tests for registration options
…ests for registration options
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens rename/prepare-rename LSP registration against clients that omit textDocument.rename capabilities, preventing null dereferences during server initialization, and adds tests to validate the registration behavior.
Changes:
- Make
GetRegistrationOptionsnull-safe whenRenameCapabilityis omitted by the client. - Add unit tests covering rename vs prepare-rename handlers’ registration options based on
PrepareSupport.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/PowerShellEditorServices.Test/Refactoring/RenameHandlerTests.cs | Adds theory-driven coverage for registration options when RenameCapability is null or present. |
| src/PowerShellEditorServices/Services/TextDocument/Handlers/RenameHandler.cs | Handles null RenameCapability safely via null-conditional checks to avoid initialization crashes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…alse capability
- Revert GetRegistrationOptions parameter to the non-nullable RenameCapability
declared by IPrepareRenameHandler/IRenameHandler, and rely on the
null-conditional check (capability?.PrepareSupport == true) for the runtime
case where the framework passes a null capability. This matches the OmniSharp
interface signature exactly, avoiding any nullable-annotation mismatch
(e.g. CS8765) while remaining null-safe during initialize.
- Add explicit { false, false } theory cases for both handler kinds so the
three distinct PrepareSupport inputs (omitted/null, true, false) are all
covered and a regression that treats false as enabled would be caught.
Verified: src and test projects build with 0 warnings under #nullable enable;
all 6 GetRegistrationOptionsReflectsPrepareSupport cases pass on net462 and net8.0.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This was discovered and recommended by Copilot while working on a separate effort. Human review and discretion requested.
Microsoft.PowerShell.EditorServices.Handlers.PrepareRenameHandler.GetRegistrationOptions(line 23) and
RenameHandler.GetRegistrationOptions(line 39)dereferenced
capability.PrepareSupportwithout null-checkingcapability. The OmniSharp framework passes a nullRenameCapabilityto these methods when the client's
initializerequest doesn'tadvertise anything under
textDocument.rename, causing PSES to throwNullReferenceExceptionduringinitialize.This blocks every minimal LSP client that doesn't speak rename — for
example a completion-only client, or any client that opts in only to
the capabilities it actually consumes.
Fix
Two parts, applied identically to both handlers:
RenameCapability?) so the signaturematches the real OmniSharp runtime contract.
nullcapability is treatedthe same as "PrepareSupport not advertised".
Test
A single parameterized
xUnit[Theory],GetRegistrationOptionsReflectsPrepareSupport, intest/PowerShellEditorServices.Test/Refactoring/RenameHandlerTests.cscovers both handlers and both capability states.
Reviewer FAQ
Filed by — see commit history. Co-authored-by Copilot.