File tree 4 files changed +96
-0
lines changed
src/PowerShellEditorServices.Engine
Services/PowerShellContext/Handlers
test/PowerShellEditorServices.Test.E2E
4 files changed +96
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,7 @@ public async Task StartAsync()
116
116
. WithHandler < DefinitionHandler > ( )
117
117
. WithHandler < TemplateHandlers > ( )
118
118
. WithHandler < GetCommentHelpHandler > ( )
119
+ . WithHandler < EvaluateHandler > ( )
119
120
. OnInitialize (
120
121
async ( languageServer , request ) =>
121
122
{
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Threading ;
3
+ using System . Threading . Tasks ;
4
+ using Microsoft . Extensions . Logging ;
5
+ using Microsoft . PowerShell . EditorServices ;
6
+
7
+ namespace PowerShellEditorServices . Engine . Services . Handlers
8
+ {
9
+ public class EvaluateHandler : IEvaluateHandler
10
+ {
11
+ private readonly ILogger _logger ;
12
+ private readonly PowerShellContextService _powerShellContextService ;
13
+
14
+ public EvaluateHandler ( ILoggerFactory factory , PowerShellContextService powerShellContextService )
15
+ {
16
+ _logger = factory . CreateLogger < EvaluateHandler > ( ) ;
17
+ _powerShellContextService = powerShellContextService ;
18
+ }
19
+
20
+ public async Task < EvaluateResponseBody > Handle ( EvaluateRequestArguments request , CancellationToken cancellationToken )
21
+ {
22
+ await _powerShellContextService . ExecuteScriptStringAsync (
23
+ request . Expression ,
24
+ writeInputToHost : true ,
25
+ writeOutputToHost : true ,
26
+ addToHistory : true ) ;
27
+
28
+ return new EvaluateResponseBody
29
+ {
30
+ Result = "" ,
31
+ VariablesReference = 0
32
+ } ;
33
+ }
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ using OmniSharp . Extensions . Embedded . MediatR ;
2
+ using OmniSharp . Extensions . JsonRpc ;
3
+
4
+ namespace PowerShellEditorServices . Engine . Services . Handlers
5
+ {
6
+ [ Serial , Method ( "evaluate" ) ]
7
+ public interface IEvaluateHandler : IJsonRpcRequestHandler < EvaluateRequestArguments , EvaluateResponseBody > { }
8
+
9
+ public class EvaluateRequestArguments : IRequest < EvaluateResponseBody >
10
+ {
11
+ /// <summary>
12
+ /// The expression to evaluate.
13
+ /// </summary>
14
+ public string Expression { get ; set ; }
15
+
16
+ /// <summary>
17
+ /// The context in which the evaluate request is run. Possible
18
+ /// values are 'watch' if evaluate is run in a watch or 'repl'
19
+ /// if run from the REPL console.
20
+ /// </summary>
21
+ public string Context { get ; set ; }
22
+
23
+ /// <summary>
24
+ /// Evaluate the expression in the context of this stack frame.
25
+ /// If not specified, the top most frame is used.
26
+ /// </summary>
27
+ public int FrameId { get ; set ; }
28
+ }
29
+
30
+ public class EvaluateResponseBody
31
+ {
32
+ /// <summary>
33
+ /// The evaluation result.
34
+ /// </summary>
35
+ public string Result { get ; set ; }
36
+
37
+ /// <summary>
38
+ /// If variablesReference is > 0, the evaluate result is
39
+ /// structured and its children can be retrieved by passing
40
+ /// variablesReference to the VariablesRequest
41
+ /// </summary>
42
+ public int VariablesReference { get ; set ; }
43
+ }
44
+ }
Original file line number Diff line number Diff line change @@ -781,5 +781,21 @@ await LanguageClient.SendRequest<CommentHelpRequestResult>(
781
781
Assert . NotEmpty ( commentHelpRequestResult . Content ) ;
782
782
Assert . Contains ( "myParam" , commentHelpRequestResult . Content [ 7 ] ) ;
783
783
}
784
+
785
+ [ Fact ]
786
+ public async Task CanSendEvaluateRequest ( )
787
+ {
788
+ EvaluateResponseBody evaluateResponseBody =
789
+ await LanguageClient . SendRequest < EvaluateResponseBody > (
790
+ "evaluate" ,
791
+ new EvaluateRequestArguments
792
+ {
793
+ Expression = "Get-ChildItem"
794
+ } ) ;
795
+
796
+ // These always gets returned so this test really just makes sure we get _any_ response.
797
+ Assert . Equal ( "" , evaluateResponseBody . Result ) ;
798
+ Assert . Equal ( 0 , evaluateResponseBody . VariablesReference ) ;
799
+ }
784
800
}
785
801
}
You can’t perform that action at this time.
0 commit comments