From abc2238244082e974d39cfdec1f8ad9f18a5cf4d Mon Sep 17 00:00:00 2001 From: Kaloyan Raev Date: Tue, 8 Nov 2016 17:34:21 +0200 Subject: [PATCH] Fixes #2728: Respect user settings when sending formatting options to LS (#2735) * Fixes #2728: Respect user settings when sending formatting options to LS Signed-off-by: Kaloyan Raev * Remove spaces in empty line --- .../LanguageServerEditorConfiguration.java | 1 - .../ide/editor/LanguageServerFormatter.java | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerEditorConfiguration.java b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerEditorConfiguration.java index 1098e42df5f..68668543718 100644 --- a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerEditorConfiguration.java +++ b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerEditorConfiguration.java @@ -57,7 +57,6 @@ public LanguageServerEditorConfiguration(LanguageServerCodeassistProcessorFactor (serverCapabilities.isDocumentRangeFormattingProvider() != null && serverCapabilities.isDocumentRangeFormattingProvider()) || serverCapabilities.getDocumentOnTypeFormattingProvider() != null) { this.formatter = formatterFactory.create(serverCapabilities); - formatter.setTabWidth(getTabWidth()); } this.serverCapabilities = serverCapabilities; this.annotationModel = annotationModelFactory.get(docPositionMapProvider.get()); diff --git a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerFormatter.java b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerFormatter.java index 07d9d393d64..b40612d4bcc 100644 --- a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerFormatter.java +++ b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/LanguageServerFormatter.java @@ -38,6 +38,8 @@ import org.eclipse.che.ide.api.editor.texteditor.UndoableEditor; import org.eclipse.che.ide.api.notification.NotificationManager; import org.eclipse.che.ide.dto.DtoFactory; +import org.eclipse.che.ide.editor.preferences.editorproperties.EditorProperties; +import org.eclipse.che.ide.editor.preferences.editorproperties.EditorPropertiesManager; import org.eclipse.che.ide.util.loging.Log; import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient; @@ -53,22 +55,20 @@ public class LanguageServerFormatter implements ContentFormatter { private final DtoFactory dtoFactory; private final NotificationManager manager; private final ServerCapabilities capabilities; - private int tabWidth; + private final EditorPropertiesManager editorPropertiesManager; private TextEditor editor; @Inject public LanguageServerFormatter(TextDocumentServiceClient client, DtoFactory dtoFactory, NotificationManager manager, - @Assisted ServerCapabilities capabilities) { + @Assisted ServerCapabilities capabilities, + EditorPropertiesManager editorPropertiesManager) { this.client = client; this.dtoFactory = dtoFactory; this.manager = manager; this.capabilities = capabilities; - } - - public void setTabWidth(int tabWidth) { - this.tabWidth = tabWidth; + this.editorPropertiesManager = editorPropertiesManager; } @Override @@ -176,11 +176,15 @@ private void applyEdits(List edits, Document document) { private FormattingOptionsDTO getFormattingOptions() { FormattingOptionsDTO options = dtoFactory.createDto(FormattingOptionsDTO.class); - options.setInsertSpaces(true); - options.setTabSize(tabWidth); + options.setInsertSpaces(Boolean.parseBoolean(getEditorProperty(EditorProperties.EXPAND_TAB))); + options.setTabSize(Integer.parseInt(getEditorProperty(EditorProperties.TAB_SIZE))); return options; } + private String getEditorProperty(EditorProperties property) { + return editorPropertiesManager.getEditorProperties().get(property.toString()).toString(); + } + private void formatRange(TextRange selectedRange, Document document) { DocumentRangeFormattingParamsDTO params = dtoFactory.createDto(DocumentRangeFormattingParamsDTO.class);