@@ -6270,69 +6270,43 @@ private static string GetNamespaceToRemove(CompletionContext context, TypeComple
6270
6270
internal static List < CompletionResult > CompleteHelpTopics ( CompletionContext context )
6271
6271
{
6272
6272
var results = new List < CompletionResult > ( ) ;
6273
- var searchPaths = new List < string > ( ) ;
6274
- var currentCulture = CultureInfo . CurrentCulture . Name ;
6275
-
6276
- // Add the user scope path first, since it is searched in order.
6277
- var userHelpRoot = Path . Combine ( HelpUtils . GetUserHomeHelpSearchPath ( ) , currentCulture ) ;
6278
-
6279
- if ( Directory . Exists ( userHelpRoot ) )
6280
- {
6281
- searchPaths . Add ( userHelpRoot ) ;
6282
- }
6283
-
6284
- var dirPath = Path . Combine ( Utils . GetApplicationBase ( Utils . DefaultPowerShellShellID ) , currentCulture ) ;
6285
- searchPaths . Add ( dirPath ) ;
6286
-
6287
- var wordToComplete = context . WordToComplete + "*" ;
6288
- var topicPattern = WildcardPattern . Get ( "about_*.help.txt" , WildcardOptions . IgnoreCase ) ;
6289
- List < string > files = new List < string > ( ) ;
6290
-
6273
+ string userHelpDir = HelpUtils . GetUserHomeHelpSearchPath ( ) ;
6274
+ string appHelpDir = Utils . GetApplicationBase ( Utils . DefaultPowerShellShellID ) ;
6275
+ string currentCulture = CultureInfo . CurrentCulture . Name ;
6276
+
6277
+ //search for help files for the current culture + en-US as fallback
6278
+ var searchPaths = new string [ ]
6279
+ {
6280
+ Path . Combine ( userHelpDir , currentCulture ) ,
6281
+ Path . Combine ( appHelpDir , currentCulture ) ,
6282
+ Path . Combine ( userHelpDir , "en-US" ) ,
6283
+ Path . Combine ( appHelpDir , "en-US" )
6284
+ } . Distinct ( ) ;
6285
+
6286
+ string wordToComplete = context . WordToComplete + "*" ;
6291
6287
try
6292
6288
{
6293
6289
var wildcardPattern = WildcardPattern . Get ( wordToComplete , WildcardOptions . IgnoreCase ) ;
6294
6290
6295
6291
foreach ( var dir in searchPaths )
6296
6292
{
6297
- foreach ( var file in Directory . EnumerateFiles ( dir ) )
6293
+ var currentDir = new DirectoryInfo ( dir ) ;
6294
+ if ( currentDir . Exists )
6298
6295
{
6299
- if ( wildcardPattern . IsMatch ( Path . GetFileName ( file ) ) )
6296
+ foreach ( var file in currentDir . EnumerateFiles ( "about_*.help.txt" ) )
6300
6297
{
6301
- files . Add ( file ) ;
6298
+ if ( wildcardPattern . IsMatch ( file . Name ) )
6299
+ {
6300
+ string topicName = file . Name . Substring ( 0 , file . Name . LastIndexOf ( ".help.txt" ) ) ;
6301
+ results . Add ( new CompletionResult ( topicName ) ) ;
6302
+ }
6302
6303
}
6303
6304
}
6304
6305
}
6305
6306
}
6306
6307
catch ( Exception )
6307
6308
{
6308
6309
}
6309
-
6310
- if ( files != null )
6311
- {
6312
- foreach ( string file in files )
6313
- {
6314
- if ( file == null )
6315
- {
6316
- continue ;
6317
- }
6318
-
6319
- try
6320
- {
6321
- var fileName = Path . GetFileName ( file ) ;
6322
- if ( fileName == null || ! topicPattern . IsMatch ( fileName ) )
6323
- continue ;
6324
-
6325
- // All topic files are ending with ".help.txt"
6326
- var completionText = fileName . Substring ( 0 , fileName . Length - 9 ) ;
6327
- results . Add ( new CompletionResult ( completionText ) ) ;
6328
- }
6329
- catch ( Exception )
6330
- {
6331
- continue ;
6332
- }
6333
- }
6334
- }
6335
-
6336
6310
return results ;
6337
6311
}
6338
6312
0 commit comments