Skip to content

Add FileContext.GetText(IFileRange) overload#2306

Open
andyleejordan wants to merge 1 commit into
mainfrom
andyleejordan/add-filecontext-gettext-ifilerange
Open

Add FileContext.GetText(IFileRange) overload#2306
andyleejordan wants to merge 1 commit into
mainfrom
andyleejordan/add-filecontext-gettext-ifilerange

Conversation

@andyleejordan

Copy link
Copy Markdown
Member

Fixes #1496.

EditorContext.SelectedRange is typed as IFileRange, but FileContext.GetText/GetTextLines only accepted the concrete FileRange class. 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 a FileRange isn't reachable when that type isn't loaded.

This widens both parameters from FileRange to IFileRange. The bodies already route through the ToBufferRange() extension on IFileRange, so nothing else changes and existing FileRange callers keep working.

Adds focused regression tests covering GetText/GetTextLines with a SelectedRange and with a hand-built FileRange.

`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>
@andyleejordan andyleejordan marked this pull request as ready for review June 16, 2026 00:16
Copilot AI review requested due to automatic review settings June 16, 2026 00:16
@andyleejordan andyleejordan enabled auto-merge (squash) June 16, 2026 00:17
@andyleejordan

Copy link
Copy Markdown
Member Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.GetText and FileContext.GetTextLines from FileRange to IFileRange.
  • Add a new test class FileContextTests with three focused regression tests covering GetText/GetTextLines with both SelectedRange (the interface path) and a hand-constructed FileRange (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.

@andyleejordan

Copy link
Copy Markdown
Member Author

@SeeminglyScience @JustinGrote this is definitely worth landing, it was a dumb type mismatch, easily fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-API Issue-Enhancement A feature request (enhancement).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$Context.CurrentFile.GetText not compatible with $Context.SelectedRange

2 participants