mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[AutoDetectIndent] added registry flag to switch between formatter-based and document-based detector
This commit is contained in:
+19
-6
@@ -19,6 +19,7 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
@@ -38,12 +39,14 @@ public class IndentOptionsDetectorImpl implements IndentOptionsDetector {
|
||||
private final Project myProject;
|
||||
private final Document myDocument;
|
||||
private final Language myLanguage;
|
||||
private final boolean myUseFormatterBasedLineIndentBuilder;
|
||||
|
||||
public IndentOptionsDetectorImpl(@NotNull PsiFile file) {
|
||||
myFile = file;
|
||||
myLanguage = file.getLanguage();
|
||||
myProject = file.getProject();
|
||||
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myFile);
|
||||
myUseFormatterBasedLineIndentBuilder = Registry.is("editor.detect.indent.by.formatter");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,17 +54,27 @@ public class IndentOptionsDetectorImpl implements IndentOptionsDetector {
|
||||
public IndentOptions getIndentOptions() {
|
||||
IndentOptions indentOptions = (IndentOptions)CodeStyleSettingsManager.getSettings(myProject).getIndentOptions(myFile.getFileType()).clone();
|
||||
|
||||
if (myDocument != null) {
|
||||
List<LineIndentInfo> linesInfo = new FormatterBasedLineIndentInfoBuilder(myFile).build();
|
||||
if (linesInfo != null) {
|
||||
IndentUsageStatistics stats = new IndentUsageStatisticsImpl(linesInfo);
|
||||
adjustIndentOptions(indentOptions, stats);
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
List<LineIndentInfo> linesInfo = calcLineIndentInfo();
|
||||
long end = System.currentTimeMillis();
|
||||
LOG.info("Formatter-based: " + myUseFormatterBasedLineIndentBuilder + ". Line info building time: " + (end - start));
|
||||
|
||||
if (linesInfo != null) {
|
||||
IndentUsageStatistics stats = new IndentUsageStatisticsImpl(linesInfo);
|
||||
adjustIndentOptions(indentOptions, stats);
|
||||
}
|
||||
|
||||
return indentOptions;
|
||||
}
|
||||
|
||||
private List<LineIndentInfo> calcLineIndentInfo() {
|
||||
if (myDocument == null) return null;
|
||||
if (myUseFormatterBasedLineIndentBuilder) {
|
||||
return new FormatterBasedLineIndentInfoBuilder(myFile).build();
|
||||
}
|
||||
return new LineIndentInfoBuilder(myDocument.getCharsSequence(), myLanguage).build();
|
||||
}
|
||||
|
||||
private void adjustIndentOptions(@NotNull IndentOptions indentOptions, @NotNull IndentUsageStatistics stats) {
|
||||
int linesWithTabs = stats.getTotalLinesWithLeadingTabs();
|
||||
int linesWithWhiteSpaceIndent = stats.getTotalLinesWithLeadingSpaces();
|
||||
|
||||
@@ -608,3 +608,5 @@ tfs.set.connection.timeout=false
|
||||
ide.mac.yosemite.laf=false
|
||||
ide.mac.yosemite.laf.restartRequired=true
|
||||
ide.mac.yosemite.laf.description=Replaces Aqua LaF to enhanced IntelliJ LaF
|
||||
|
||||
editor.detect.indent.by.formatter=false
|
||||
Reference in New Issue
Block a user