Skip to content

Commit

Permalink
Use GetSubTextFromRange instead of extension GetContentAt (fsprojects…
Browse files Browse the repository at this point in the history
…#3029)

* Use GetSubTextFromRange instead of extension GetContentAt

* Add comment.
  • Loading branch information
nojaf authored Jan 2, 2024
1 parent a999b77 commit 79e8355
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ open Fantomas.FCS.Text.Range
open Fantomas.FCS.Syntax
open Fantomas.FCS.SyntaxTrivia
open Fantomas.FCS.Xml
open Fantomas.Core.ISourceTextExtensions
open Fantomas.Core.RangePatterns
open Fantomas.Core.SyntaxOak
open Microsoft.FSharp.Core
Expand All @@ -19,7 +18,7 @@ type CreationAide =
member x.TextFromSource fallback range =
match x.SourceText with
| None -> fallback ()
| Some sourceText -> sourceText.GetContentAt range
| Some sourceText -> sourceText.GetSubTextFromRange range

let stn text range = SingleTextNode(text, range)

Expand Down
2 changes: 0 additions & 2 deletions src/Fantomas.Core/Fantomas.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="ISourceTextExtensions.fsi" />
<Compile Include="ISourceTextExtensions.fs" />
<Compile Include="RangeHelpers.fsi" />
<Compile Include="RangeHelpers.fs" />
<Compile Include="Utils.fsi" />
Expand Down
24 changes: 0 additions & 24 deletions src/Fantomas.Core/ISourceTextExtensions.fs

This file was deleted.

7 changes: 0 additions & 7 deletions src/Fantomas.Core/ISourceTextExtensions.fsi

This file was deleted.

3 changes: 1 addition & 2 deletions src/Fantomas.Core/Selection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

open Fantomas.FCS.Text
open Fantomas.Core.SyntaxOak
open Fantomas.Core.ISourceTextExtensions

let correctSelection (fileIndex: int) (sourceText: ISourceText) (selection: range) =
let lines =
Expand Down Expand Up @@ -428,7 +427,7 @@ let formatSelection
match rangeOfSelection with
| None ->
raise (FormatException("No suitable AST node could be extracted from formatted selection."))
| Some m -> source.GetContentAt m
| Some m -> source.GetSubTextFromRange m

return formattedSelection.TrimEnd([| '\r'; '\n' |]), selection
}
7 changes: 3 additions & 4 deletions src/Fantomas.Core/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open System
open Fantomas.FCS.Syntax
open Fantomas.FCS.SyntaxTrivia
open Fantomas.FCS.Text
open Fantomas.Core.ISourceTextExtensions
open Fantomas.Core.SyntaxOak

type CommentTrivia with
Expand All @@ -23,7 +22,7 @@ let internal collectTriviaFromCodeComments
|> List.filter (fun ct -> RangeHelpers.rangeContainsRange codeRange ct.Range)
|> List.map (function
| CommentTrivia.BlockComment r ->
let content = source.GetContentAt r
let content = source.GetSubTextFromRange r
let startLine = source.GetLineString(r.StartLine - 1)
let endLine = source.GetLineString(r.EndLine - 1)

Expand All @@ -40,7 +39,7 @@ let internal collectTriviaFromCodeComments

TriviaNode(content, r)
| CommentTrivia.LineComment r ->
let content = source.GetContentAt r
let content = source.GetSubTextFromRange r
let index = r.StartLine - 1
let line = source.GetLineString index

Expand Down Expand Up @@ -146,7 +145,7 @@ let internal collectTriviaFromDirectives
|> List.filter (fun cdt -> RangeHelpers.rangeContainsRange codeRange cdt.Range)
|> List.map (fun cdt ->
let m = cdt.Range
let text = (source.GetContentAt m).TrimEnd()
let text = (source.GetSubTextFromRange m).TrimEnd()
let content = Directive text
TriviaNode(content, m))

Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.FCS/Fantomas.FCS.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);57;</NoWarn> <!-- Experimental -->
<NoWarn>$(NoWarn);1204</NoWarn> <!-- This construct is for use in the FSharp.Core library and should not be used directly -->
<NoWarn>$(NoWarn);1178</NoWarn> <!-- FS1178 does not support structural equality -->
<DefineConstants>$(DefineConstants);COMPILER;FSHARPCORE_USE_PACKAGE</DefineConstants>
<FsYaccOutputFolder>generated\$(TargetFramework)\</FsYaccOutputFolder>
<FsLexOutputFolder>generated\$(TargetFramework)\</FsLexOutputFolder>
Expand Down

0 comments on commit 79e8355

Please sign in to comment.