Fixed IDEA-145069 EditorConfig plugin doesn't handle indent_size option correctly

Use configured tab size if it's not specified explicitly (no tab_width).
This commit is contained in:
Rustam Vishnyakov
2019-03-04 16:04:09 +03:00
parent 9387a6c264
commit b4bc0b541b
8 changed files with 78 additions and 3 deletions
@@ -65,7 +65,7 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
String indentSize, String continuationIndentSize, String tabWidth,
String indentStyle, String filePath) {
boolean changed = false;
final String calculatedIndentSize = calculateIndentSize(tabWidth, indentSize);
final String calculatedIndentSize = calculateIndentSize(tabWidth, indentSize, indentOptions);
final String calculatedContinuationSize = calculateContinuationIndentSize(calculatedIndentSize, continuationIndentSize);
final String calculatedTabWidth = calculateTabWidth(tabWidth, indentSize);
if (!calculatedIndentSize.isEmpty()) {
@@ -102,8 +102,8 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
return changed;
}
private static String calculateIndentSize(final String tabWidth, final String indentSize) {
return indentSize.equals("tab") ? tabWidth : indentSize;
private static String calculateIndentSize(final String tabWidth, final String indentSize, @NotNull final IndentOptions options) {
return indentSize.equals("tab") ? (tabWidth.isEmpty() ? String.valueOf(options.TAB_SIZE) : tabWidth) : indentSize;
}
private static String calculateContinuationIndentSize(final String indentSize, final String continuationIndentSize) {
@@ -0,0 +1,49 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.editorconfig.configmanagement;
import com.intellij.application.options.CodeStyle;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.editorconfig.Utils;
public class EditorConfigStandardSettingsTest extends EditorConfigFileSettingsTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Utils.setFullIntellijSettingsSupportEnabledInTest(false);
}
public void testIndentSizeTab() {
final CommonCodeStyleSettings.IndentOptions projectIndentOptions =
CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).getIndentOptions();
projectIndentOptions.TAB_SIZE = 4;
projectIndentOptions.INDENT_SIZE = 2;
PsiFile javaFile = findPsiFile("source.java");
final CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getIndentOptions(javaFile);
assertTrue(indentOptions.USE_TAB_CHARACTER);
assertEquals("Indent size doesn't match tab size", indentOptions.TAB_SIZE, indentOptions.INDENT_SIZE);
}
public void testIndentStyleTab() {
final CommonCodeStyleSettings.IndentOptions projectIndentOptions =
CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).getIndentOptions();
projectIndentOptions.TAB_SIZE = 4;
projectIndentOptions.INDENT_SIZE = 2;
PsiFile javaFile = findPsiFile("source.java");
final CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getIndentOptions(javaFile);
assertEquals("Indent size doesn't match tab size", indentOptions.TAB_SIZE, indentOptions.INDENT_SIZE);
}
public void testIndentSizeTabWidth() {
PsiFile javaFile = findPsiFile("source.java");
final CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getIndentOptions(javaFile);
assertEquals(3, indentOptions.TAB_SIZE);
assertEquals(3, indentOptions.INDENT_SIZE);
}
@Override
protected String getRelativePath() {
return "/plugins/editorconfig/testData/org/editorconfig/configmanagement/fileSettings";
}
}
@@ -0,0 +1,6 @@
root = true
[*]
indent_style = tab
indent_size = tab
@@ -0,0 +1,6 @@
root = true
[*]
indent_size = tab
tab_width = 3
@@ -0,0 +1,5 @@
root = true
[*]
indent_style = tab