-
Notifications
You must be signed in to change notification settings - Fork 822
Add GetSubTextFromRange to ISourceText #15979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
41140d3
Add GetSubTextFromRange to ISourceText
nojaf 5af4329
Add unit test for inconsistent line endings.
nojaf 3fc6743
Add capacity to StringBuilder.
nojaf cf68714
Use a for loop
nojaf 048524c
Cover zero range and invalid range
nojaf ab8ae4c
Add exception to xml doc.
nojaf 9ba16da
Add GetSubTextFromRange to test implementation.
nojaf 1b8e306
Add dummy GetSubTextFromRange for FSharp.Editor.
nojaf 11a4d1b
Merge branch 'main' into text-by-range
nojaf 11b1934
Remove capacity and list.
nojaf 7afe111
Add additional implementations.
nojaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module FSharp.Compiler.Service.Tests.SourceTextTests | ||
|
||
open System | ||
open FSharp.Compiler.Text | ||
open NUnit.Framework | ||
|
||
[<Test>] | ||
let ``Select text from a single line via the range`` () = | ||
let sourceText = SourceText.ofString """ | ||
let a = 2 | ||
""" | ||
let m = Range.mkRange "Sample.fs" (Position.mkPos 2 4) (Position.mkPos 2 5) | ||
let v = sourceText.GetSubTextFromRange m | ||
Assert.AreEqual("a", v) | ||
|
||
[<Test>] | ||
let ``Select text from multiple lines via the range`` () = | ||
let sourceText = SourceText.ofString """ | ||
let a b c = | ||
// comment | ||
2 | ||
""" | ||
let m = Range.mkRange "Sample.fs" (Position.mkPos 2 4) (Position.mkPos 4 5) | ||
let v = sourceText.GetSubTextFromRange m | ||
let sanitized = v.Replace("\r", "") | ||
Assert.AreEqual("a b c =\n // comment\n 2", sanitized) | ||
|
||
[<Test>] | ||
let ``Inconsistent return carriage return correct text`` () = | ||
let sourceText = SourceText.ofString "let a =\r\n // foo\n 43" | ||
let m = Range.mkRange "Sample.fs" (Position.mkPos 1 4) (Position.mkPos 3 6) | ||
let v = sourceText.GetSubTextFromRange m | ||
let sanitized = v.Replace("\r", "") | ||
Assert.AreEqual("a =\n // foo\n 43", sanitized) | ||
|
||
[<Test>] | ||
let ``Zero range should return empty string`` () = | ||
let sourceText = SourceText.ofString "a" | ||
let v = sourceText.GetSubTextFromRange Range.Zero | ||
Assert.AreEqual(String.Empty, v) | ||
|
||
[<Test>] | ||
let ``Invalid range should throw argument exception`` () = | ||
let sourceText = SourceText.ofString "a" | ||
let mInvalid = Range.mkRange "Sample.fs" (Position.mkPos 3 6) (Position.mkPos 1 4) | ||
Assert.Throws<ArgumentException>(fun () -> sourceText.GetSubTextFromRange mInvalid |> ignore) | ||
|> ignore |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.