@@ -59,6 +59,8 @@ type CustomErrorInfo =
5959type PreprocessResults =
6060 {
6161 OriginalLines : string [];
62+ HelpLines : string [];
63+ FsiOutputLines : string [];
6264 NuGetLines : string [];
6365 FilteredLines : string [];
6466 Packages : NuGetPackage [];
@@ -87,24 +89,6 @@ type CustomInstallCommand() =
8789 let semanticVersion = SemanticVersion( version)
8890 packageManager.LocalRepository.FindPackage( packageId, semanticVersion)
8991
90- module NuGetManagerInternals =
91-
92- /// Separates a list of lines between into two partitions, the first list are the directive lines, second list is the other lines
93- let partitionLines ( directive ) ( lines : string []) =
94- lines
95- |> Seq.mapi ( fun ( idx ) ( line ) -> ( idx, line))
96- |> Seq.toList
97- |> List.partition ( fun ( idx , line ) -> line.StartsWith( directive))
98-
99- /// Separates a list of lines between into two partitions, the first list are the directive lines, second list is the other lines
100- let partitionSource ( directive ) ( source : string ) =
101- let delimiters = [| " \r\n " ; " \n " ; " \r " ;|]
102- partitionLines directive ( source.Split( delimiters, StringSplitOptions.None))
103-
104- /// Parses a directive line. Example: #N "Deedle"
105- let parseDirectiveLine ( prefix : string ) ( line : string ) =
106- line.Substring( prefix.Length + 1 ) .Trim() .Trim( '"' )
107-
10892/// The NuGetManager class contains methods for downloading nuget packages and such
10993type NuGetManager ( executingDirectory : string ) =
11094
@@ -231,7 +215,7 @@ type NuGetManager (executingDirectory : string) =
231215 /// prerelease should be used or not.
232216 member this.ParseNugetLine ( line : string ) =
233217
234- let contents = NuGetManagerInternals .parseDirectiveLine " #N" line
218+ let contents = DirectivePreprocessor .parseDirectiveLine " #N" line
235219 if contents.Contains( " /" ) then
236220 let splits = contents.Split([| '/' |])
237221 if splits.Length > 2 then
@@ -246,7 +230,15 @@ type NuGetManager (executingDirectory : string) =
246230
247231 // split the source code into lines, then get the nuget lines
248232 let lines = source.Split( '\n' )
249- let ( nugetLines , otherLines ) = NuGetManagerInternals.partitionLines " #N" lines
233+ let linesSplit = DirectivePreprocessor.partitionLines lines
234+
235+ let orEmpty key = let opt = Map.tryFind key linesSplit
236+ if opt.IsSome then opt.Value else Seq.empty
237+
238+ let helpLines = DirectivePreprocessor.Line.HelpDirective |> orEmpty
239+ let fsiOutputLines = DirectivePreprocessor.Line.FSIOutputDirective |> orEmpty
240+ let nugetLines = DirectivePreprocessor.Line.NugetDirective |> orEmpty
241+ let otherLines = DirectivePreprocessor.Line.Other |> orEmpty
250242
251243 // parse the nuget lines and then download the packages
252244 let nugetPackages =
@@ -258,14 +250,17 @@ type NuGetManager (executingDirectory : string) =
258250 // gather errors
259251 let errors =
260252 nugetPackages
261- |> Seq.filter ( fun ( idx , package ) -> String.IsNullOrEmpty( package.Error) = false )
253+ |> Seq.filter ( fun ( _ , package ) -> String.IsNullOrEmpty( package.Error) = false )
262254 |> Seq.map ( fun ( idx , package ) -> CustomErrorInfo.From( " " , idx, 0 , idx, lines.[ idx]. Length, package.Error, " Error" , " preprocess" ))
263255 |> Seq.toArray
264256
265257 {
266258 OriginalLines = lines;
267- NuGetLines = nugetLines |> Seq.map( fun ( idx , line ) -> line) |> Seq.toArray;
268- FilteredLines = otherLines |> Seq.map( fun ( idx , line ) -> line) |> Seq.toArray;
269- Packages = nugetPackages |> Seq.map( fun ( idx , package ) -> package) |> Seq.toArray;
259+ HelpLines = helpLines |> Seq.map( fun ( _ , line ) -> line) |> Seq.toArray;
260+ FsiOutputLines = fsiOutputLines |> Seq.map( fun ( _ , line ) -> line) |> Seq.toArray;
261+ NuGetLines = nugetLines |> Seq.map( fun ( _ , line ) -> line) |> Seq.toArray;
262+
263+ FilteredLines = otherLines |> Seq.map( fun ( _ , line ) -> line) |> Seq.toArray;
264+ Packages = nugetPackages |> Seq.map( fun ( _ , package ) -> package) |> Seq.toArray;
270265 Errors = errors;
271266 }
0 commit comments