@@ -916,11 +916,21 @@ private static int getRightOffsetOfPart(Document document, int offset) {
916916 }
917917
918918 public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit ) {
919- applyWorkspaceEdit (edit , null );
919+ applyWorkspaceEdit (edit , false );
920+ }
921+
922+ public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit , boolean saveDocument ) {
923+ applyWorkspaceEdit (edit , null , saveDocument );
920924 }
921925
922926 public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit ,
923927 @ Nullable String label ) {
928+ applyWorkspaceEdit (edit , label , false );
929+ }
930+
931+ public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit ,
932+ @ Nullable String label ,
933+ boolean saveDocument ) {
924934 if (edit .getDocumentChanges () != null ) {
925935 for (Either <TextDocumentEdit , ResourceOperation > change : edit .getDocumentChanges ()) {
926936 if (change .isLeft ()) {
@@ -929,13 +939,13 @@ public static void applyWorkspaceEdit(@NotNull WorkspaceEdit edit,
929939 if (file != null ) {
930940 Document document = getDocument (file );
931941 if (document != null ) {
932- applyEdits (null , document , textDocumentEdit .getEdits (), false );
942+ applyEdits (null , document , textDocumentEdit .getEdits (), saveDocument );
933943 }
934944 }
935945 } else if (change .isRight ()) {
936946 ResourceOperation resourceOperation = change .getRight ();
937947 if (resourceOperation instanceof CreateFile createFile ) {
938- applyCreateFile (createFile );
948+ applyCreateFile (createFile , saveDocument );
939949 } else if (resourceOperation instanceof DeleteFile deleteFile ) {
940950 applyDeleteFile (deleteFile );
941951 } else if (resourceOperation instanceof RenameFile renameFile ) {
@@ -957,21 +967,21 @@ public static void applyWorkspaceEdit(@NotNull WorkspaceEdit edit,
957967 if (file != null ) {
958968 Document document = getDocument (file );
959969 if (document != null ) {
960- applyEdits (null , document , change .getValue (), false );
970+ applyEdits (null , document , change .getValue (), saveDocument );
961971 }
962972 }
963973 }
964974 }
965975 }
966976
967- private static void applyCreateFile (CreateFile createFile ) {
977+ private static void applyCreateFile (CreateFile createFile , boolean saveDocument ) {
968978 VirtualFile targetFile = findResourceFor (createFile .getUri ());
969979 if (targetFile != null && createFile .getOptions () != null ) {
970980 if (!createFile .getOptions ().getIgnoreIfExists ()) {
971981 Document document = getDocument (targetFile );
972982 if (document != null ) {
973983 TextEdit textEdit = new TextEdit (new Range (toPosition (0 , document ), toPosition (document .getTextLength (), document )), "" );
974- applyEdits (null , document , Collections .singletonList (textEdit ), false );
984+ applyEdits (null , document , Collections .singletonList (textEdit ), saveDocument );
975985 }
976986 }
977987 } else {
0 commit comments