@@ -7,6 +7,7 @@ open System
77open System.IO
88open System.Collections .Concurrent
99open System.Collections .Generic
10+ open System.Text
1011open Microsoft.FSharp .Core .Printf
1112open Internal.Utilities .Library
1213open Internal.Utilities .Library .Extras .Bits
@@ -261,6 +262,9 @@ module FileIndex =
261262 let startupFileName = " startup"
262263 let commandLineArgsFileName = " commandLineArgs"
263264
265+ let mutable testSources : ConcurrentDictionary < string , string > =
266+ ConcurrentDictionary()
267+
264268[<RequireQualifiedAccess>]
265269module internal LineDirectives =
266270
@@ -329,6 +333,9 @@ type Range(code1: int64, code2: int64) =
329333
330334 member m.FileName = fileOfFileIndex m.FileIndex
331335
336+ member internal m.ShortFileName =
337+ Path.GetFileName( fileOfFileIndex m.FileIndex) |> nonNull
338+
332339 member m.ApplyLineDirectives () =
333340 match LineDirectives.store.TryFind m.FileIndex with
334341 | None -> m
@@ -376,32 +383,42 @@ type Range(code1: int64, code2: int64) =
376383 member _.Code2 = code2
377384
378385 member m.DebugCode =
379- let name = m.FileName
386+ let getRangeSubstring ( m : range ) ( stream : Stream ) =
387+ let endCol = m.EndColumn - 1
388+ let startCol = m.StartColumn - 1
389+
390+ stream.ReadLines()
391+ |> Seq.skip ( m.StartLine - 1 )
392+ |> Seq.take ( m.EndLine - m.StartLine + 1 )
393+ |> String.concat " \n "
394+ |> fun s -> s.Substring( startCol + 1 , s.LastIndexOf( " \n " , StringComparison.Ordinal) + 1 - startCol + endCol)
395+
396+ match testSources.TryGetValue( m.FileName) with
397+ | true , source ->
398+ use stream = new MemoryStream( Encoding.UTF8.GetBytes( source + " \n " ))
399+ getRangeSubstring m stream
400+ | _ ->
380401
381- if
382- name = unknownFileName
383- || name = startupFileName
384- || name = commandLineArgsFileName
385- then
386- name
387- else
402+ let name = m.FileName
388403
389- try
390- let endCol = m.EndColumn - 1
391- let startCol = m.StartColumn - 1
404+ if
405+ name = unknownFileName
406+ || name = startupFileName
407+ || name = commandLineArgsFileName
408+ then
409+ name
410+ else
392411
393- if FileSystem.IsInvalidPathShim m.FileName then
394- " path invalid: " + m.FileName
395- elif not ( FileSystem.FileExistsShim m.FileName) then
396- " nonexistent file: " + m.FileName
397- else
398- FileSystem.OpenFileForReadShim( m.FileName) .ReadLines()
399- |> Seq.skip ( m.StartLine - 1 )
400- |> Seq.take ( m.EndLine - m.StartLine + 1 )
401- |> String.concat " \n "
402- |> fun s -> s.Substring( startCol + 1 , s.LastIndexOf( " \n " , StringComparison.Ordinal) + 1 - startCol + endCol)
403- with e ->
404- e.ToString()
412+ try
413+ if FileSystem.IsInvalidPathShim m.FileName then
414+ " path invalid: " + m.FileName
415+ elif not ( FileSystem.FileExistsShim m.FileName) then
416+ " nonexistent file: " + m.FileName
417+ else
418+ use stream = FileSystem.OpenFileForReadShim( m.FileName)
419+ getRangeSubstring m stream
420+ with e ->
421+ e.ToString()
405422
406423 member _.Equals ( m2 : range ) =
407424 let code2 = code2 &&& ~~~( debugPointKindMask ||| isSyntheticMask)
@@ -613,3 +630,6 @@ module Range =
613630 | None -> mkRange file ( mkPos 1 0 ) ( mkPos 1 80 )
614631 with _ ->
615632 mkRange file ( mkPos 1 0 ) ( mkPos 1 80 )
633+
634+ let internal setTestSource path ( source : string ) =
635+ testSources.GetOrAdd( path, source) |> ignore
0 commit comments