1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
+ using System ;
4
5
using System . Collections . Generic ;
6
+ using System . Management . Automation ;
5
7
using System . Threading ;
6
8
using System . Threading . Tasks ;
7
9
using Microsoft . Extensions . Logging ;
8
10
using Microsoft . PowerShell . EditorServices . Services ;
11
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell ;
12
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Execution ;
9
13
using Microsoft . PowerShell . EditorServices . Services . Symbols ;
10
14
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
11
15
using Microsoft . PowerShell . EditorServices . Utility ;
@@ -18,15 +22,18 @@ namespace Microsoft.PowerShell.EditorServices.Handlers
18
22
internal class PsesHoverHandler : HoverHandlerBase
19
23
{
20
24
private readonly ILogger _logger ;
25
+ private readonly IInternalPowerShellExecutionService _executionService ;
21
26
private readonly SymbolsService _symbolsService ;
22
27
private readonly WorkspaceService _workspaceService ;
23
28
24
29
public PsesHoverHandler (
25
30
ILoggerFactory factory ,
31
+ IInternalPowerShellExecutionService executionService ,
26
32
SymbolsService symbolsService ,
27
33
WorkspaceService workspaceService )
28
34
{
29
35
_logger = factory . CreateLogger < PsesHoverHandler > ( ) ;
36
+ _executionService = executionService ;
30
37
_symbolsService = symbolsService ;
31
38
_workspaceService = workspaceService ;
32
39
}
@@ -63,6 +70,21 @@ await _symbolsService.FindSymbolDetailsAtLocationAsync(
63
70
new MarkedString ( "PowerShell" , symbolDetails . SymbolReference . Name )
64
71
} ;
65
72
73
+ // If we're looking at a variable, try to get its value.
74
+ if ( symbolDetails . SymbolReference . Type == SymbolType . Variable )
75
+ {
76
+ PSCommand command = new PSCommand ( ) . AddScript ( $ "[System.Diagnostics.DebuggerHidden()]param() { symbolDetails . SymbolReference . Name } ") ;
77
+ IReadOnlyList < PSObject > results = await _executionService . ExecutePSCommandAsync < PSObject > (
78
+ command ,
79
+ cancellationToken ,
80
+ new PowerShellExecutionOptions { ThrowOnError = false } ) . ConfigureAwait ( false ) ;
81
+
82
+ if ( results != null )
83
+ {
84
+ symbolInfo . Add ( new MarkedString ( "PowerShell" , string . Join ( Environment . NewLine , results ) ) ) ;
85
+ }
86
+ }
87
+
66
88
if ( ! string . IsNullOrEmpty ( symbolDetails . Documentation ) )
67
89
{
68
90
symbolInfo . Add ( new MarkedString ( "markdown" , symbolDetails . Documentation ) ) ;
0 commit comments