@@ -327,15 +327,15 @@ CompletionResultType.ProviderItem or CompletionResultType.ProviderContainer
327
327
Data = item . Detail ,
328
328
Detail = SupportsMarkdown ? null : item . Detail ,
329
329
} ,
330
- CompletionResultType . ParameterName => TryExtractType ( detail , out string type )
331
- ? item with { Kind = CompletionItemKind . Variable , Detail = type }
330
+ CompletionResultType . ParameterName => TryExtractType ( detail , item . Label , out string type , out string documentation )
331
+ ? item with { Kind = CompletionItemKind . Variable , Detail = type , Documentation = documentation }
332
332
// The comparison operators (-eq, -not, -gt, etc) unfortunately come across as
333
333
// ParameterName types but they don't have a type associated to them, so we can
334
334
// deduce it is an operator.
335
335
: item with { Kind = CompletionItemKind . Operator } ,
336
336
CompletionResultType . ParameterValue => item with { Kind = CompletionItemKind . Value } ,
337
- CompletionResultType . Variable => TryExtractType ( detail , out string type )
338
- ? item with { Kind = CompletionItemKind . Variable , Detail = type }
337
+ CompletionResultType . Variable => TryExtractType ( detail , item . Label , out string type , out string documentation )
338
+ ? item with { Kind = CompletionItemKind . Variable , Detail = type , Documentation = documentation }
339
339
: item with { Kind = CompletionItemKind . Variable } ,
340
340
CompletionResultType . Namespace => item with { Kind = CompletionItemKind . Module } ,
341
341
CompletionResultType . Type => detail . StartsWith ( "Class " , StringComparison . CurrentCulture )
@@ -450,16 +450,41 @@ private static string GetTypeFilterText(string textToBeReplaced, string completi
450
450
/// type names in [] to be consistent with PowerShell syntax and how the debugger displays
451
451
/// type names.
452
452
/// </summary>
453
- /// <param name="toolTipText"></param>
454
- /// <param name="type"></param>
453
+ /// <param name="toolTipText">The tooltip text to parse</param>
454
+ /// <param name="type">The extracted type string, if found</param>
455
+ /// <param name="documentation">The remaining text after the type, if any</param>
456
+ /// <param name="label">The label to check for in the documentation prefix</param>
455
457
/// <returns>Whether or not the type was found.</returns>
456
- private static bool TryExtractType ( string toolTipText , out string type )
458
+ private static bool TryExtractType ( string toolTipText , string label , out string type , out string documentation )
457
459
{
458
460
MatchCollection matches = s_typeRegex . Matches ( toolTipText ) ;
459
461
type = string . Empty ;
462
+ documentation = null ; //We use null instead of String.Empty to indicate no documentation was found.
463
+
460
464
if ( ( matches . Count > 0 ) && ( matches [ 0 ] . Groups . Count > 1 ) )
461
465
{
462
466
type = matches [ 0 ] . Groups [ 1 ] . Value ;
467
+
468
+ // Extract the description as everything after the type
469
+ if ( matches [ 0 ] . Length < toolTipText . Length )
470
+ {
471
+ documentation = toolTipText . Substring ( matches [ 0 ] . Length ) . Trim ( ) ;
472
+
473
+ if ( documentation is not null )
474
+ {
475
+ // If the substring is the same as the label, documentation should remain blank
476
+ if ( documentation . Equals ( label , StringComparison . OrdinalIgnoreCase ) )
477
+ {
478
+ documentation = null ;
479
+ }
480
+ // If the documentation starts with "label - ", remove this prefix
481
+ else if ( documentation . StartsWith ( label + " - " , StringComparison . OrdinalIgnoreCase ) )
482
+ {
483
+ documentation = documentation . Substring ( ( label + " - " ) . Length ) . Trim ( ) ;
484
+ }
485
+ }
486
+ }
487
+
463
488
return true ;
464
489
}
465
490
return false ;
0 commit comments