GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix #2297: guard PrepareRenameHandler against null rename capability by manderse21 · Pull Request #2299 · PowerShell/PowerShellEditorServices

Conversation

@manderse21

@manderse21 Mike Andersen (manderse21) commented Jun 10, 2026

Copy link
Copy Markdown

Drafted PR -- PSES PrepareRename/Rename null RenameCapability guard (#2297)

Status: PR-READY, NOT SUBMITTED. The fix branch is pushed to Mike's fork:

  • Fork branch: manderse21/PowerShellEditorServices @ fix/2297-prepare-rename-null-capability
  • Base: PowerShell/PowerShellEditorServices @ main (which is v4.6.0, commit d2112c21)
  • Commit: Fix #2297: guard null RenameCapability in rename handlers

Opening the PR (fork branch -> upstream main) is Mike's explicit action. Nothing
has been submitted, commented, or posted upstream.


PR title

Fix #2297: guard null RenameCapability in rename handlers

PR body (draft)

Summary

PrepareRenameHandler and RenameHandler both read capability.PrepareSupport in
GetRegistrationOptions. The language-server framework passes a null
RenameCapability when the client's initialize omits textDocument.rename, so the
dereference throws a NullReferenceException during capability registration. The
exception leaves the initialize request unanswered, so the handshake hangs for
any client that legitimately omits the optional rename capability (#2297).

The rename provider is new in v4.6.0 (#2292), so this affects v4.6.0.

Fix

Guard both handlers with a property pattern, so an absent capability is treated as
"no prepare support" instead of dereferenced:

// before
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities)
    => capability.PrepareSupport ? new() { PrepareProvider = true } : new();

// after
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities)
    => capability is { PrepareSupport: true } ? new() { PrepareProvider = true } : new();

Tests

Adds a regression test to each handler's test class asserting
GetRegistrationOptions(null, ...) does not throw and reports no prepare provider.

Validation (performed locally before submission)

  • dotnet build -c Release is clean (the Release configuration's documentation/analyzer
    gate passes).
  • The rename test category is green: 102 tests including the two new regression tests
    (Category=PrepareRename|Category=RenameHandlerFunction, net8.0 Release).
  • Adversarial control: reverting only the guard makes both new tests fail with the
    exact NRE -- RenameHandler.GetRegistrationOptions (RenameHandler.cs:37) and
    PrepareRenameHandler.GetRegistrationOptions (RenameHandler.cs:23) -- and they pass
    again with the guard restored, confirming the tests guard the regression and the fix
    is the cause.
  • End-to-end: an initialize that omits rename, sent over -Stdio, never returns
    an initialize response against a stock v4.6.0 bundle (hang reproduced); the same
    probe against a bundle in which only Microsoft.PowerShell.EditorServices.dll is
    rebuilt from this branch returns the initialize response and completes the handshake.
  • The full PowerShellEditorServices.Test unit project runs 315/320 green on net8.0
    Release. The 5 failures are pre-existing environment dependencies unrelated to this
    change -- CanLoadPSReadLine, CanLoadPSScriptAnalyzerAsync, and three PSSA-dependent
    tests (parse-error / script-marker / built-in command help) -- which need PSReadLine and
    PSScriptAnalyzer provisioned (this local sandbox does not install them; the project's CI
    does). No rename test fails.

Closes #2297.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@manderse21
Fix #2297: guard null RenameCapability in rename handlers
7bbde49
The rename provider added in v4.6.0 (#2292) reads capability.PrepareSupport in GetRegistrationOptions on both PrepareRenameHandler and RenameHandler. The LSP framework passes a null RenameCapability when the client's initialize omits textDocument.rename, so the dereference throws a NullReferenceException during capability registration. The exception leaves the initialize request unanswered and the handshake hangs for any client that legitimately omits the optional rename capability.

Guard both handlers with a property pattern (capability is { PrepareSupport: true }) so an absent capability is treated as no prepare support rather than dereferenced. Add regression tests asserting GetRegistrationOptions tolerates a null capability.
Copilot AI review requested due to automatic review settings June 10, 2026 12:25
Copilot AI reviewed Jun 10, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression guard for omitted textDocument.rename capabilities during LSP initialize so GetRegistrationOptions no longer throws (and hangs the handshake) when RenameCapability is null.

Changes:

  • Harden GetRegistrationOptions in both rename handlers to tolerate null RenameCapability.
  • Add regression tests covering the omitted rename capability scenario for both handlers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/PowerShellEditorServices.Test/Refactoring/RenameHandlerTests.cs Adds regression test ensuring registration options don’t throw when rename capability is omitted.
test/PowerShellEditorServices.Test/Refactoring/PrepareRenameHandlerTests.cs Adds regression test ensuring prepare-rename registration options don’t throw when rename capability is omitted.
src/PowerShellEditorServices/Services/TextDocument/Handlers/RenameHandler.cs Guards against null RenameCapability when computing registration options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/PowerShellEditorServices/Services/TextDocument/Handlers/RenameHandler.cs
// request; treat that as "no prepare support" instead of dereferencing it. Dereferencing
// the null capability threw a NullReferenceException that hung the initialize handshake.
// Fixes PowerShell/PowerShellEditorServices#2297.
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) => capability is { PrepareSupport: true } ? new() { PrepareProvider = true } : new();
Comment thread src/PowerShellEditorServices/Services/TextDocument/Handlers/RenameHandler.cs
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) => capability.PrepareSupport ? new() { PrepareProvider = true } : new();
// A null capability means the client omitted textDocument.rename; guard it rather than
// dereferencing (the NRE hung initialize). Fixes PowerShell/PowerShellEditorServices#2297.
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) => capability is { PrepareSupport: true } ? new() { PrepareProvider = true } : new();
Comment thread test/PowerShellEditorServices.Test/Refactoring/PrepareRenameHandlerTests.cs
Comment on lines +116 to +124
[Fact]
public void GetRegistrationOptionsToleratesOmittedRenameCapability()
{
// Regression for PowerShell/PowerShellEditorServices#2297: when the client's
// initialize omits textDocument.rename, the framework passes a null
// RenameCapability. GetRegistrationOptions must not dereference it -- the
// NullReferenceException hung the initialize handshake. A null capability means
// the client has no prepare support.
RenameRegistrationOptions options = testHandler.GetRegistrationOptions(null!, new());
@manderse21 Mike Andersen (manderse21) mentioned this pull request Jun 10, 2026
NullReferenceException in OnInitialize on Linux when the initialize request includes workspaceFolders (v4.6.0) #2300
Closed
@JustinGrote

Justin Grote (JustinGrote) commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your submission! We are going to go with #2296 as the approach is more clear and tested.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JustinGrote Justin Grote (JustinGrote) closed this Jun 11, 2026
Copilot AI mentioned this pull request Jun 15, 2026
Fix NullReferenceException in OnInitialize when initialize includes workspaceFolders #2305
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

PrepareRename throws NullReferenceException when an LSP client omits the rename capability (v4.6.0)

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@manderse21 @JustinGrote
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.