Skip to content

Commit

Permalink
Fixes #2728: Respect user settings when sending formatting options to…
Browse files Browse the repository at this point in the history
… LS (#2735)

* Fixes #2728: Respect user settings when sending formatting options to LS

Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>

* Remove spaces in empty line
  • Loading branch information
kaloyan-raev authored and Vitalii Parfonov committed Nov 8, 2016
1 parent 376b233 commit abc2238
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -176,11 +176,15 @@ private void applyEdits(List<TextEditDTO> 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);

Expand Down

0 comments on commit abc2238

Please sign in to comment.