Skip to content

Commit

Permalink
Plugin doesn't work with if "Only VCS changed text" is selected from …
Browse files Browse the repository at this point in the history
…code-reformat settings (#386)

Summary:
Fixes #228

The code reformat with "Only VCS changed text" falls back to the IDE Kotlin settings due to a missing override in KtfmtCodeStyleManager.java. This is also true of the popular "Save Actions" plugin which reformats with the same command.

This change adds the missing override exactly as it appears in the reference project google/google-java-format at https://github.com/google/google-java-format/blob/d86e930de93f123994fba151a8d289b8035db87b/idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java#L76

Confirmed to fix the issue on Android Studio 2021.1.1 with the manual code-reformat and in the Save Actions plugin.

Pull Request resolved: #386

Reviewed By: strulovich

Differential Revision: D49322592

Pulled By: hick209

fbshipit-source-id: 99d56d428603292ffb6efb6551e7fa619367c0bd
  • Loading branch information
haruka authored and facebook-github-bot committed Sep 18, 2023
1 parent e4f4190 commit 8ad0872
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.ChangedRangesInfo;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.impl.CheckUtil;
import com.intellij.util.IncorrectOperationException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
Expand Down Expand Up @@ -66,6 +69,17 @@ public void reformatText(PsiFile file, Collection<TextRange> ranges)
}
}

@Override
public void reformatTextWithContext(@NotNull PsiFile file, @NotNull ChangedRangesInfo info)
throws IncorrectOperationException {
List<TextRange> ranges = new ArrayList<>();
if (info.insertedRanges != null) {
ranges.addAll(info.insertedRanges);
}
ranges.addAll(info.allChangedRanges);
reformatTextWithContext(file, ranges);
}

@Override
public void reformatTextWithContext(PsiFile file, Collection<TextRange> ranges) {
if (overrideFormatterForFile(file)) {
Expand Down

0 comments on commit 8ad0872

Please sign in to comment.