Skip to content

Commit 4173fe8

Browse files
mgreenegitCopilot
andcommitted
Address review: keep interface-compatible signature; cover explicit false 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>
1 parent 972a828 commit 4173fe8

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/PowerShellEditorServices/Services/TextDocument/Handlers/RenameHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class PrepareRenameHandler
2020
RenameService renameService
2121
) : IPrepareRenameHandler
2222
{
23-
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability? capability, ClientCapabilities clientCapabilities) => capability?.PrepareSupport == true ? new() { PrepareProvider = true } : new();
23+
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) => capability?.PrepareSupport == true ? new() { PrepareProvider = true } : new();
2424

2525
public async Task<RangeOrPlaceholderRange?> Handle(PrepareRenameParams request, CancellationToken cancellationToken)
2626
=> await renameService.PrepareRenameSymbol(request, cancellationToken).ConfigureAwait(false);
@@ -34,9 +34,9 @@ RenameService renameService
3434
) : IRenameHandler
3535
{
3636
// RenameOptions may only be specified if the client states that it supports prepareSupport in its initial initialize request.
37-
// Passes a null capability when the client omits textDocument.rename from its advertised capabilities (e.g. a completion-only client).
38-
// Use the null-conditional operator so we don't throw NullReferenceException during initialize.
39-
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability? capability, ClientCapabilities clientCapabilities) => capability?.PrepareSupport == true ? new() { PrepareProvider = true } : new();
37+
// The framework passes a null capability when the client omits textDocument.rename from its advertised capabilities (e.g. a completion-only client).
38+
// The parameter keeps the interface's non-nullable signature; the null-conditional operator avoids a NullReferenceException during initialize.
39+
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) => capability?.PrepareSupport == true ? new() { PrepareProvider = true } : new();
4040

4141
public async Task<WorkspaceEdit?> Handle(RenameParams request, CancellationToken cancellationToken)
4242
=> await renameService.RenameSymbol(request, cancellationToken).ConfigureAwait(false);

test/PowerShellEditorServices.Test/Refactoring/RenameHandlerTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@ public enum RegistrationHandlerKind
134134
PrepareRename
135135
}
136136

137-
// A null prepareSupport represents the client omitting the capability entirely (framework hands us null).
137+
// prepareSupport has three distinct inputs: null = client omitted the capability entirely (framework hands us null),
138+
// true = client supports prepareRename, false = client explicitly does not. Only true should enable PrepareProvider.
138139
public static TheoryData<RegistrationHandlerKind, bool?, bool> RegistrationOptionsTestCases() => new()
139140
{
140141
{ RegistrationHandlerKind.Rename, null, false },
142+
{ RegistrationHandlerKind.Rename, false, false },
141143
{ RegistrationHandlerKind.Rename, true, true },
142144
{ RegistrationHandlerKind.PrepareRename, null, false },
145+
{ RegistrationHandlerKind.PrepareRename, false, false },
143146
{ RegistrationHandlerKind.PrepareRename, true, true }
144147
};
145148

0 commit comments

Comments
 (0)