Skip to content

Commit

Permalink
Fix xml indentation with indent_size != 1
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed Jun 17, 2018
1 parent ae66a10 commit f9fd53f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@ public void testIndentStyleTab() throws Exception {
assertThat(context.fileContents(fileName), equalTo("\t"));
}

@Test
public void testIndentStyleTabWithSize() throws Exception {
context.editorConfig(
"root = true",
"[*]",
"indent_style = tab",
"indent_size = 2"
);
context.editFile(fileName, "\t");
assertThat(context.fileContents(fileName), equalTo("\t"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.editorconfig.core.ConfigProperty;
import org.eclipse.editorconfig.core.ConfigPropertyType;
import org.eclipse.editorconfig.core.ConfigPropertyVisitor;
import org.eclipse.editorconfig.core.EditorFileConfig;
import org.eclipse.editorconfig.core.EndOfLineOption;
Expand Down Expand Up @@ -51,13 +52,17 @@ public void visitIndentStyle(final ConfigProperty<IndentStyleOption> property) {
@Override
public void visitIndentSize(final ConfigProperty<Integer> property) {
final String indentSizeString = property.getValue().toString();
setPreference("org.eclipse.wst.xml.core", "indentationSize", indentSizeString);
setPreference("org.eclipse.jdt.core", "org.eclipse.jdt.core.formatter.indentation.size", indentSizeString);
// this represents the number of tabs, not their width
setPreference("org.eclipse.wst.xml.core", "indentationSize",
config.getConfigProperty(ConfigPropertyType.INDENT_STYLE.getName()).getValue().equals(IndentStyleOption.SPACE)
? indentSizeString
: "1");
}

@Override
public void visitTabWidth(final ConfigProperty<Integer> property) {
final String tabWidth = property.getValue().toString();
// xml editor will follow this
setPreference("org.eclipse.ui.editors", "tabWidth", tabWidth);
setPreference("org.eclipse.jdt.core", "org.eclipse.jdt.core.formatter.tabulation.size", tabWidth);
setPreference("org.eclipse.ant.ui", "formatter_tab_size", tabWidth);
Expand Down

0 comments on commit f9fd53f

Please sign in to comment.