forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpReplEngine.cs
More file actions
52 lines (47 loc) · 1.86 KB
/
CSharpReplEngine.cs
File metadata and controls
52 lines (47 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Scripting;
using ScriptCs.Contracts;
namespace ScriptCs.Engine.Roslyn
{
public class CSharpReplEngine : CSharpScriptEngine, IReplEngine
{
public CSharpReplEngine(IScriptHostFactory scriptHostFactory, ILogProvider logProvider)
: base(scriptHostFactory, logProvider)
{
}
public ICollection<string> GetLocalVariables(ScriptPackSession scriptPackSession)
{
return this.GetLocalVariables(SessionKey, scriptPackSession);
}
protected override ScriptResult Execute(string code, object globals, SessionState<ScriptState> sessionState)
{
if (string.IsNullOrWhiteSpace(FileName) && !IsCompleteSubmission(code))
return ScriptResult.Incomplete;
if (sessionState.Session != null)
{
try
{
Log.Debug("Starting subsequent REPL execution");
var result = sessionState.Session.ContinueWithAsync(code, ScriptOptions).GetAwaiter().GetResult();
Log.Debug("Finished subsequent REPL execution");
sessionState.Session = result;
return new ScriptResult(returnValue: result.ReturnValue);
}
catch (AggregateException ex)
{
return new ScriptResult(executionException: ex.InnerException);
}
catch (CompilationErrorException ex)
{
return new ScriptResult(compilationException: ex);
}
catch (Exception ex)
{
return new ScriptResult(executionException: ex);
}
}
return base.Execute(code, globals, sessionState);
}
}
}