@@ -193,10 +193,10 @@ public static object HandleCommand(JObject @params)
193
193
namespaceName
194
194
) ;
195
195
case "read" :
196
- Debug . LogWarning ( "manage_script.read is deprecated; prefer resources/read. Serving read for backward compatibility." ) ;
196
+ McpLog . Warn ( "manage_script.read is deprecated; prefer resources/read. Serving read for backward compatibility." ) ;
197
197
return ReadScript ( fullPath , relativePath ) ;
198
198
case "update" :
199
- Debug . LogWarning ( "manage_script.update is deprecated; prefer apply_text_edits. Serving update for backward compatibility." ) ;
199
+ McpLog . Warn ( "manage_script.update is deprecated; prefer apply_text_edits. Serving update for backward compatibility." ) ;
200
200
return UpdateScript ( fullPath , relativePath , name , contents ) ;
201
201
case "delete" :
202
202
return DeleteScript ( fullPath , relativePath ) ;
@@ -356,11 +356,11 @@ string namespaceName
356
356
var uri = $ "unity://path/{ relativePath } ";
357
357
var ok = Response . Success (
358
358
$ "Script '{ name } .cs' created successfully at '{ relativePath } '.",
359
- new { uri , scheduledRefresh = true }
359
+ new { uri , scheduledRefresh = false }
360
360
) ;
361
361
362
- // Schedule heavy work AFTER replying
363
- ManageScriptRefreshHelpers . ScheduleScriptRefresh ( relativePath ) ;
362
+ ManageScriptRefreshHelpers . ImportAndRequestCompile ( relativePath ) ;
363
+
364
364
return ok ;
365
365
}
366
366
catch ( Exception e )
@@ -650,7 +650,7 @@ private static object ApplyTextEdits(
650
650
spans = spans . OrderByDescending ( t => t . start ) . ToList ( ) ;
651
651
for ( int i = 1 ; i < spans . Count ; i ++ )
652
652
{
653
- if ( spans [ i ] . end > spans [ i - 1 ] . start )
653
+ if ( spans [ i ] . end > spans [ i - 1 ] . start )
654
654
{
655
655
var conflict = new [ ] { new { startA = spans [ i ] . start , endA = spans [ i ] . end , startB = spans [ i - 1 ] . start , endB = spans [ i - 1 ] . end } } ;
656
656
return Response . Error ( "overlap" , new { status = "overlap" , conflicts = conflict , hint = "Sort ranges descending by start and compute from the same snapshot." } ) ;
@@ -763,19 +763,18 @@ private static object ApplyTextEdits(
763
763
string . Equals ( refreshModeFromCaller , "sync" , StringComparison . OrdinalIgnoreCase ) ;
764
764
if ( immediate )
765
765
{
766
- EditorApplication . delayCall += ( ) =>
767
- {
768
- AssetDatabase . ImportAsset (
769
- relativePath ,
770
- ImportAssetOptions . ForceSynchronousImport | ImportAssetOptions . ForceUpdate
771
- ) ;
766
+ McpLog . Info ( $ "[ManageScript] ApplyTextEdits: immediate refresh for '{ relativePath } '") ;
767
+ AssetDatabase . ImportAsset (
768
+ relativePath ,
769
+ ImportAssetOptions . ForceSynchronousImport | ImportAssetOptions . ForceUpdate
770
+ ) ;
772
771
#if UNITY_EDITOR
773
- UnityEditor . Compilation . CompilationPipeline . RequestScriptCompilation ( ) ;
772
+ UnityEditor . Compilation . CompilationPipeline . RequestScriptCompilation ( ) ;
774
773
#endif
775
- } ;
776
774
}
777
775
else
778
776
{
777
+ McpLog . Info ( $ "[ManageScript] ApplyTextEdits: debounced refresh scheduled for '{ relativePath } '") ;
779
778
ManageScriptRefreshHelpers . ScheduleScriptRefresh ( relativePath ) ;
780
779
}
781
780
@@ -786,7 +785,8 @@ private static object ApplyTextEdits(
786
785
uri = $ "unity://path/{ relativePath } ",
787
786
path = relativePath ,
788
787
editsApplied = spans . Count ,
789
- sha256 = newSha
788
+ sha256 = newSha ,
789
+ scheduledRefresh = ! immediate
790
790
}
791
791
) ;
792
792
}
@@ -1326,7 +1326,7 @@ private static object EditScript(
1326
1326
if ( ordered [ i ] . start + ordered [ i ] . length > ordered [ i - 1 ] . start )
1327
1327
{
1328
1328
var conflict = new [ ] { new { startA = ordered [ i ] . start , endA = ordered [ i ] . start + ordered [ i ] . length , startB = ordered [ i - 1 ] . start , endB = ordered [ i - 1 ] . start + ordered [ i - 1 ] . length } } ;
1329
- return Response . Error ( "overlap" , new { status = "overlap" , conflicts = conflict , hint = "Apply in descending order against the same precondition snapshot." } ) ;
1329
+ return Response . Error ( "overlap" , new { status = "overlap" , conflicts = conflict , hint = "Sort ranges descending by start and compute from the same snapshot." } ) ;
1330
1330
}
1331
1331
}
1332
1332
return Response . Error ( "overlap" , new { status = "overlap" } ) ;
@@ -1421,17 +1421,8 @@ private static object EditScript(
1421
1421
1422
1422
if ( immediate )
1423
1423
{
1424
- // Force on main thread
1425
- EditorApplication . delayCall += ( ) =>
1426
- {
1427
- AssetDatabase . ImportAsset (
1428
- relativePath ,
1429
- ImportAssetOptions . ForceSynchronousImport | ImportAssetOptions . ForceUpdate
1430
- ) ;
1431
- #if UNITY_EDITOR
1432
- UnityEditor . Compilation . CompilationPipeline . RequestScriptCompilation ( ) ;
1433
- #endif
1434
- } ;
1424
+ McpLog . Info ( $ "[ManageScript] EditScript: immediate refresh for '{ relativePath } '", always : false ) ;
1425
+ ManageScriptRefreshHelpers . ImportAndRequestCompile ( relativePath ) ;
1435
1426
}
1436
1427
else
1437
1428
{
@@ -2620,5 +2611,15 @@ public static void ScheduleScriptRefresh(string relPath)
2620
2611
{
2621
2612
RefreshDebounce . Schedule ( relPath , TimeSpan . FromMilliseconds ( 200 ) ) ;
2622
2613
}
2614
+
2615
+ public static void ImportAndRequestCompile ( string relPath , bool synchronous = true )
2616
+ {
2617
+ var opts = ImportAssetOptions . ForceUpdate ;
2618
+ if ( synchronous ) opts |= ImportAssetOptions . ForceSynchronousImport ;
2619
+ AssetDatabase . ImportAsset ( relPath , opts ) ;
2620
+ #if UNITY_EDITOR
2621
+ UnityEditor . Compilation . CompilationPipeline . RequestScriptCompilation ( ) ;
2622
+ #endif
2623
+ }
2623
2624
}
2624
2625
0 commit comments