@@ -327,15 +327,15 @@ CompletionResultType.ProviderItem or CompletionResultType.ProviderContainer
327327 Data = item . Detail ,
328328 Detail = SupportsMarkdown ? null : item . Detail ,
329329 } ,
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 }
332332 // The comparison operators (-eq, -not, -gt, etc) unfortunately come across as
333333 // ParameterName types but they don't have a type associated to them, so we can
334334 // deduce it is an operator.
335335 : item with { Kind = CompletionItemKind . Operator } ,
336336 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 }
339339 : item with { Kind = CompletionItemKind . Variable } ,
340340 CompletionResultType . Namespace => item with { Kind = CompletionItemKind . Module } ,
341341 CompletionResultType . Type => detail . StartsWith ( "Class " , StringComparison . CurrentCulture )
@@ -450,16 +450,41 @@ private static string GetTypeFilterText(string textToBeReplaced, string completi
450450 /// type names in [] to be consistent with PowerShell syntax and how the debugger displays
451451 /// type names.
452452 /// </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>
455457 /// <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 )
457459 {
458460 MatchCollection matches = s_typeRegex . Matches ( toolTipText ) ;
459461 type = string . Empty ;
462+ documentation = null ; //We use null instead of String.Empty to indicate no documentation was found.
463+
460464 if ( ( matches . Count > 0 ) && ( matches [ 0 ] . Groups . Count > 1 ) )
461465 {
462466 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+
463488 return true ;
464489 }
465490 return false ;
0 commit comments