@@ -11,41 +11,42 @@ namespace ScipDotnet;
1111
1212public static class IndexCommandHandler
1313{
14- public static async Task < int > Process ( IHost host , FileInfo ? projects , string output , FileInfo workingDirectory ,
14+ public static async Task < int > Process ( IHost host , List < FileInfo > projects , string output , FileInfo workingDirectory ,
1515 List < string > include , List < string > exclude , bool allowGlobalSymbolDefinitions )
1616 {
1717 var logger = host . Services . GetRequiredService < ILogger < IndexCommandOptions > > ( ) ;
1818 var matcher = new Matcher ( ) ;
1919 matcher . AddIncludePatterns ( include . Count == 0 ? new [ ] { "**" } : include ) ;
2020 matcher . AddExcludePatterns ( exclude ) ;
2121
22- var projectsFile = projects ? . FullName ?? FindSolutionOrProjectFile ( workingDirectory , logger ) ;
23- if ( projectsFile == null )
22+ var projectFiles = projects . Count > 0
23+ ? projects
24+ : FindSolutionOrProjectFile ( workingDirectory , logger ) ;
25+ if ( ! projectFiles . Any ( ) )
2426 {
2527 return 1 ;
2628 }
2729
28- var options = new IndexCommandOptions ( workingDirectory , OutputFile ( workingDirectory , output ) ,
29- new FileInfo ( projectsFile ) , logger , matcher ,
30- allowGlobalSymbolDefinitions ) ;
30+ var options = new IndexCommandOptions (
31+ workingDirectory ,
32+ OutputFile ( workingDirectory , output ) ,
33+ projectFiles ,
34+ logger ,
35+ matcher ,
36+ allowGlobalSymbolDefinitions
37+ ) ;
3138 await ScipIndex ( host , options ) ;
3239 return 0 ;
3340 }
3441
3542 private static FileInfo OutputFile ( FileInfo workingDirectory , string output )
3643 {
37- if ( Path . IsPathRooted ( output ) )
38- {
39- return new FileInfo ( output ) ;
40- }
41-
42- return new FileInfo ( Path . Join ( workingDirectory . FullName , output ) ) ;
44+ return Path . IsPathRooted ( output ) ? new FileInfo ( output ) : new FileInfo ( Path . Join ( workingDirectory . FullName , output ) ) ;
4345 }
4446
4547 private static async Task ScipIndex ( IHost host , IndexCommandOptions options )
4648 {
4749 var stopwatch = Stopwatch . StartNew ( ) ;
48- options . Logger . LogInformation ( "Solution file {SolutionFileFullName}" , options . ProjectsFile . FullName ) ;
4950 var indexer = host . Services . GetRequiredService < ScipIndexer > ( ) ;
5051 var index = new Scip . Index
5152 {
@@ -72,34 +73,26 @@ private static async Task ScipIndex(IHost host, IndexCommandOptions options)
7273
7374 private static string FixThisProblem ( string examplePath )
7475 {
75- return "To fix this problem, pass the path of a solution (.sln) or project (.csproj) file to the `scip-dotnet index` command. " +
76- $ "For example, run: scip-dotnet index { examplePath } ";
76+ return
77+ "To fix this problem, pass the path of a solution (.sln) or project (.csproj) file to the `scip-dotnet index` command. " +
78+ $ "For example, run: scip-dotnet index { examplePath } ";
7779 }
78-
79- private static string ? FindSolutionOrProjectFile ( FileInfo workingDirectory , ILogger < IndexCommandOptions > logger )
80+
81+ private static List < FileInfo > FindSolutionOrProjectFile ( FileInfo workingDirectory , ILogger logger )
8082 {
8183 var paths = Directory . GetFiles ( workingDirectory . FullName ) . Where ( file =>
8284 string . Equals ( Path . GetExtension ( file ) , ".sln" , StringComparison . OrdinalIgnoreCase ) ||
8385 string . Equals ( Path . GetExtension ( file ) , ".csproj" , StringComparison . OrdinalIgnoreCase )
8486 ) . ToList ( ) ;
8587
86- switch ( paths . Count )
88+ if ( paths . Count != 0 )
8789 {
88- case 0 :
89- logger . LogError (
90- "No solution (.sln) or .csproj file detected in the working directory '{WorkingDirectory}'. {FixThis}" ,
91- workingDirectory . FullName , FixThisProblem ( "SOLUTION_FILE" ) ) ;
92- return null ;
93- case 1 :
94- return paths . First ( ) ;
90+ return paths . Select ( path => new FileInfo ( path ) ) . ToList ( ) ;
9591 }
9692
97- var relativePaths = paths . Select ( path => Path . GetRelativePath ( workingDirectory . FullName , path ) ) . ToList ( ) ;
9893 logger . LogError (
99- "Ambiguous solution files: {Join}. {FixThis}" ,
100- String . Join ( ", " , relativePaths ) ,
101- FixThisProblem ( relativePaths . First ( ) ) ) ;
102- return null ;
103-
94+ "No solution (.sln) or .csproj file detected in the working directory '{WorkingDirectory}'. {FixThis}" ,
95+ workingDirectory . FullName , FixThisProblem ( "SOLUTION_FILE" ) ) ;
96+ return new List < FileInfo > ( ) ;
10497 }
10598}
0 commit comments