@@ -929,11 +929,21 @@ private static int getRightOffsetOfPart(Document document, int offset) {
929929 }
930930
931931 public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit ) {
932- applyWorkspaceEdit (edit , null );
932+ applyWorkspaceEdit (edit , false );
933+ }
934+
935+ public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit , boolean saveDocument ) {
936+ applyWorkspaceEdit (edit , null , saveDocument );
933937 }
934938
935939 public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit ,
936940 @ Nullable String label ) {
941+ applyWorkspaceEdit (edit , label , false );
942+ }
943+
944+ public static void applyWorkspaceEdit (@ NotNull WorkspaceEdit edit ,
945+ @ Nullable String label ,
946+ boolean saveDocument ) {
937947 if (edit .getDocumentChanges () != null ) {
938948 for (Either <TextDocumentEdit , ResourceOperation > change : edit .getDocumentChanges ()) {
939949 if (change .isLeft ()) {
@@ -942,13 +952,13 @@ public static void applyWorkspaceEdit(@NotNull WorkspaceEdit edit,
942952 if (file != null ) {
943953 Document document = getDocument (file );
944954 if (document != null ) {
945- applyEdits (null , document , textDocumentEdit .getEdits (), false );
955+ applyEdits (null , document , textDocumentEdit .getEdits (), saveDocument );
946956 }
947957 }
948958 } else if (change .isRight ()) {
949959 ResourceOperation resourceOperation = change .getRight ();
950960 if (resourceOperation instanceof CreateFile createFile ) {
951- applyCreateFile (createFile );
961+ applyCreateFile (createFile , saveDocument );
952962 } else if (resourceOperation instanceof DeleteFile deleteFile ) {
953963 applyDeleteFile (deleteFile );
954964 } else if (resourceOperation instanceof RenameFile renameFile ) {
@@ -970,21 +980,21 @@ public static void applyWorkspaceEdit(@NotNull WorkspaceEdit edit,
970980 if (file != null ) {
971981 Document document = getDocument (file );
972982 if (document != null ) {
973- applyEdits (null , document , change .getValue (), false );
983+ applyEdits (null , document , change .getValue (), saveDocument );
974984 }
975985 }
976986 }
977987 }
978988 }
979989
980- private static void applyCreateFile (CreateFile createFile ) {
990+ private static void applyCreateFile (CreateFile createFile , boolean saveDocument ) {
981991 VirtualFile targetFile = findResourceFor (createFile .getUri ());
982992 if (targetFile != null && createFile .getOptions () != null ) {
983993 if (!createFile .getOptions ().getIgnoreIfExists ()) {
984994 Document document = getDocument (targetFile );
985995 if (document != null ) {
986996 TextEdit textEdit = new TextEdit (new Range (toPosition (0 , document ), toPosition (document .getTextLength (), document )), "" );
987- applyEdits (null , document , Collections .singletonList (textEdit ), false );
997+ applyEdits (null , document , Collections .singletonList (textEdit ), saveDocument );
988998 }
989999 }
9901000 } else {
0 commit comments