|
23 | 23 | import com.intellij.formatting.service.AsyncDocumentFormattingService; |
24 | 24 | import com.intellij.formatting.service.AsyncFormattingRequest; |
25 | 25 | import com.intellij.ide.highlighter.JavaFileType; |
| 26 | +import com.intellij.openapi.diagnostic.Logger; |
26 | 27 | import com.intellij.openapi.project.Project; |
27 | 28 | import com.intellij.openapi.util.NlsSafe; |
28 | 29 | import com.intellij.openapi.util.TextRange; |
|
35 | 36 | import java.util.List; |
36 | 37 | import java.util.Optional; |
37 | 38 | import java.util.Set; |
| 39 | +import java.util.stream.Collectors; |
38 | 40 | import org.jetbrains.annotations.NotNull; |
39 | 41 |
|
40 | 42 | class PalantirJavaFormatFormattingService extends AsyncDocumentFormattingService { |
| 43 | + private static final Logger logger = Logger.getInstance(PalantirJavaFormatFormattingService.class); |
41 | 44 | private final FormatterProvider formatterProvider = new FormatterProvider(); |
42 | 45 |
|
43 | 46 | @Override |
@@ -89,9 +92,26 @@ public void run() { |
89 | 92 | } |
90 | 93 |
|
91 | 94 | try { |
92 | | - String formattedText = applyReplacements( |
93 | | - request.getDocumentText(), |
94 | | - formatterService.get().getFormatReplacements(request.getDocumentText(), toRanges(request))); |
| 95 | + if (logger.isDebugEnabled()) { |
| 96 | + logger.debug(String.format( |
| 97 | + "Received request to format file=%s, length=%s with ranges=%s", |
| 98 | + Optional.ofNullable(request.getIOFile()) |
| 99 | + .map(file -> file.toPath().toString()) |
| 100 | + .orElse("null"), |
| 101 | + request.getDocumentText().length(), |
| 102 | + request.getFormattingRanges())); |
| 103 | + } |
| 104 | + List<Replacement> replacements = |
| 105 | + formatterService.get().getFormatReplacements(request.getDocumentText(), toRanges(request)); |
| 106 | + if (logger.isDebugEnabled()) { |
| 107 | + logger.debug(String.format( |
| 108 | + "Applying %s replacements with ranges=%s", |
| 109 | + replacements.size(), |
| 110 | + replacements.stream() |
| 111 | + .map(Replacement::getReplaceRange) |
| 112 | + .collect(Collectors.toSet()))); |
| 113 | + } |
| 114 | + String formattedText = applyReplacements(request.getDocumentText(), replacements); |
95 | 115 | request.onTextReady(formattedText); |
96 | 116 | } catch (FormatterException e) { |
97 | 117 | request.onError( |
|
0 commit comments