Add FileContext.GetText(IFileRange) overload#2306
Conversation
`EditorContext.SelectedRange` is typed as `IFileRange` (it's actually a `BufferFileRange`), but `FileContext.GetText` and `GetTextLines` only accepted the concrete `FileRange` class. That meant the obvious script `$Context.CurrentFile.GetText($Context.SelectedRange)` failed overload resolution with "Cannot find an overload for GetText and the argument count: 1", and the documented workaround of constructing a `FileRange` isn't even reachable when that type isn't loaded. Widen both parameters from `FileRange` to `IFileRange`. The bodies already route through the `ToBufferRange()` extension defined on `IFileRange`, so nothing else changes, and `FileRange` callers keep working since it implements the interface. Adds focused regression tests covering `GetText`/`GetTextLines` with a `SelectedRange` and with a hand-built `FileRange`. Fixes #1496. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Software development really has changed. When this was first opened I said to the effect of "too busy to debug this, sorry" in #1496 (comment) but today it just got automatically fixed when I threw GitHub Copilot across the repo to solve issues it thinks it could handle. And yes, this was an easy fix that was a typing problem (using a concrete type instead of the interface) and it's confirmed with a correct regression test. |
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #1496 where $Context.CurrentFile.GetText($Context.SelectedRange) failed in PowerShell because GetText/GetTextLines only accepted the concrete FileRange class, while EditorContext.SelectedRange is typed as IFileRange (backed by the internal BufferFileRange struct). The fix widens both method parameters from FileRange to IFileRange, which is fully compatible since the method bodies already call ToBufferRange() — an extension method defined on IFileRange.
Changes:
- Widen the parameter type of
FileContext.GetTextandFileContext.GetTextLinesfromFileRangetoIFileRange. - Add a new test class
FileContextTestswith three focused regression tests coveringGetText/GetTextLineswith bothSelectedRange(the interface path) and a hand-constructedFileRange(the concrete class path).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/PowerShellEditorServices/Extensions/FileContext.cs |
Widen GetText and GetTextLines parameter types from FileRange to IFileRange |
test/PowerShellEditorServices.Test/Extensions/FileContextTests.cs |
New test class with 3 tests verifying GetText/GetTextLines work with IFileRange |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@SeeminglyScience @JustinGrote this is definitely worth landing, it was a dumb type mismatch, easily fixed. |
Fixes #1496.
EditorContext.SelectedRangeis typed asIFileRange, butFileContext.GetText/GetTextLinesonly accepted the concreteFileRangeclass. So the natural$Context.CurrentFile.GetText($Context.SelectedRange)failed overload resolution ("Cannot find an overload for GetText and the argument count: 1"), and the documented workaround of constructing aFileRangeisn't reachable when that type isn't loaded.This widens both parameters from
FileRangetoIFileRange. The bodies already route through theToBufferRange()extension onIFileRange, so nothing else changes and existingFileRangecallers keep working.Adds focused regression tests covering
GetText/GetTextLineswith aSelectedRangeand with a hand-builtFileRange.