mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
+3
-3
@@ -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) {
|
||||
|
||||
+49
@@ -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";
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
|
||||
indent_style = tab
|
||||
indent_size = tab
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
|
||||
indent_size = tab
|
||||
tab_width = 3
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
|
||||
indent_style = tab
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user