@@ -193,10 +193,10 @@ public static object HandleCommand(JObject @params)
193193 namespaceName
194194 ) ;
195195 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." ) ;
197197 return ReadScript ( fullPath , relativePath ) ;
198198 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." ) ;
200200 return UpdateScript ( fullPath , relativePath , name , contents ) ;
201201 case "delete" :
202202 return DeleteScript ( fullPath , relativePath ) ;
@@ -356,11 +356,11 @@ string namespaceName
356356 var uri = $ "unity://path/{ relativePath } ";
357357 var ok = Response . Success (
358358 $ "Script '{ name } .cs' created successfully at '{ relativePath } '.",
359- new { uri , scheduledRefresh = true }
359+ new { uri , scheduledRefresh = false }
360360 ) ;
361361
362- // Schedule heavy work AFTER replying
363- ManageScriptRefreshHelpers . ScheduleScriptRefresh ( relativePath ) ;
362+ ManageScriptRefreshHelpers . ImportAndRequestCompile ( relativePath ) ;
363+
364364 return ok ;
365365 }
366366 catch ( Exception e )
@@ -650,7 +650,7 @@ private static object ApplyTextEdits(
650650 spans = spans . OrderByDescending ( t => t . start ) . ToList ( ) ;
651651 for ( int i = 1 ; i < spans . Count ; i ++ )
652652 {
653- if ( spans [ i ] . end > spans [ i - 1 ] . start )
653+ if ( spans [ i ] . end > spans [ i - 1 ] . start )
654654 {
655655 var conflict = new [ ] { new { startA = spans [ i ] . start , endA = spans [ i ] . end , startB = spans [ i - 1 ] . start , endB = spans [ i - 1 ] . end } } ;
656656 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(
763763 string . Equals ( refreshModeFromCaller , "sync" , StringComparison . OrdinalIgnoreCase ) ;
764764 if ( immediate )
765765 {
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+ ) ;
772771#if UNITY_EDITOR
773- UnityEditor . Compilation . CompilationPipeline . RequestScriptCompilation ( ) ;
772+ UnityEditor . Compilation . CompilationPipeline . RequestScriptCompilation ( ) ;
774773#endif
775- } ;
776774 }
777775 else
778776 {
777+ McpLog . Info ( $ "[ManageScript] ApplyTextEdits: debounced refresh scheduled for '{ relativePath } '") ;
779778 ManageScriptRefreshHelpers . ScheduleScriptRefresh ( relativePath ) ;
780779 }
781780
@@ -786,7 +785,8 @@ private static object ApplyTextEdits(
786785 uri = $ "unity://path/{ relativePath } ",
787786 path = relativePath ,
788787 editsApplied = spans . Count ,
789- sha256 = newSha
788+ sha256 = newSha ,
789+ scheduledRefresh = ! immediate
790790 }
791791 ) ;
792792 }
@@ -1326,7 +1326,7 @@ private static object EditScript(
13261326 if ( ordered [ i ] . start + ordered [ i ] . length > ordered [ i - 1 ] . start )
13271327 {
13281328 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." } ) ;
13301330 }
13311331 }
13321332 return Response . Error ( "overlap" , new { status = "overlap" } ) ;
@@ -1421,17 +1421,8 @@ private static object EditScript(
14211421
14221422 if ( immediate )
14231423 {
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 ) ;
14351426 }
14361427 else
14371428 {
@@ -2620,5 +2611,15 @@ public static void ScheduleScriptRefresh(string relPath)
26202611 {
26212612 RefreshDebounce . Schedule ( relPath , TimeSpan . FromMilliseconds ( 200 ) ) ;
26222613 }
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+ }
26232624}
26242625
0 commit comments