12
12
using UnityExplorer . UI . Panels ;
13
13
using UnityExplorer . UI . Widgets . AutoComplete ;
14
14
using System . Reflection ;
15
+ using Mono . CSharp ;
15
16
16
17
namespace UnityExplorer . UI . CSConsole
17
18
{
@@ -150,15 +151,16 @@ public static void Evaluate(string input, bool supressLog = false)
150
151
151
152
try
152
153
{
153
- // Try to "Compile" the code (tries to interpret it as REPL)
154
- var evaluation = Evaluator . Compile ( input ) ;
155
- if ( evaluation != null )
154
+ // Compile the code. If it returned a CompiledMethod, it is REPL.
155
+ CompiledMethod repl = Evaluator . Compile ( input ) ;
156
+
157
+ if ( repl != null )
156
158
{
157
159
// Valid REPL, we have a delegate to the evaluation.
158
160
try
159
161
{
160
162
object ret = null ;
161
- evaluation . Invoke ( ref ret ) ;
163
+ repl . Invoke ( ref ret ) ;
162
164
var result = ret ? . ToString ( ) ;
163
165
if ( ! string . IsNullOrEmpty ( result ) )
164
166
ExplorerCore . Log ( $ "Invoked REPL, result: { ret } ") ;
@@ -172,9 +174,7 @@ public static void Evaluate(string input, bool supressLog = false)
172
174
}
173
175
else
174
176
{
175
- // The input was not recognized as an evaluation. Compile the code.
176
-
177
- Evaluator . Run ( input ) ;
177
+ // The compiled code was not REPL, so it was a using directive or it defined classes.
178
178
179
179
string output = ScriptEvaluator . _textWriter . ToString ( ) ;
180
180
var outputSplit = output . Split ( '\n ' ) ;
@@ -233,6 +233,12 @@ private static void OnInputChanged(string value)
233
233
if ( EnableSuggestions && AutoCompleteModal . CheckEnter ( Completer ) )
234
234
OnAutocompleteEnter ( ) ;
235
235
236
+ if ( ! settingCaretCoroutine )
237
+ {
238
+ if ( EnableAutoIndent )
239
+ DoAutoIndent ( ) ;
240
+ }
241
+
236
242
var inStringOrComment = HighlightVisibleInput ( ) ;
237
243
238
244
if ( ! settingCaretCoroutine )
@@ -244,9 +250,6 @@ private static void OnInputChanged(string value)
244
250
else
245
251
Completer . CheckAutocompletes ( ) ;
246
252
}
247
-
248
- if ( EnableAutoIndent )
249
- DoAutoIndent ( ) ;
250
253
}
251
254
252
255
UpdateCaret ( out _ ) ;
@@ -261,16 +264,16 @@ public static void Update()
261
264
262
265
UpdateCaret ( out bool caretMoved ) ;
263
266
264
- if ( ! settingCaretCoroutine && EnableSuggestions && AutoCompleteModal . CheckEscape ( Completer ) )
267
+ if ( ! settingCaretCoroutine && EnableSuggestions )
265
268
{
266
- OnAutocompleteEscaped ( ) ;
267
- return ;
268
- }
269
+ if ( AutoCompleteModal . CheckEscape ( Completer ) )
270
+ {
271
+ OnAutocompleteEscaped ( ) ;
272
+ return ;
273
+ }
269
274
270
- if ( ! settingCaretCoroutine && EnableSuggestions && caretMoved )
271
- {
272
- AutoCompleteModal . Instance . ReleaseOwnership ( Completer ) ;
273
- //Completer.CheckAutocompletes();
275
+ if ( caretMoved )
276
+ AutoCompleteModal . Instance . ReleaseOwnership ( Completer ) ;
274
277
}
275
278
276
279
if ( EnableCtrlRShortcut
0 commit comments