Skip to content

Commit

Permalink
#1789 respect language server capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgen Vidolob committed Jul 27, 2016
1 parent b6eea6f commit 965c474
Show file tree
Hide file tree
Showing 19 changed files with 403 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
*******************************************************************************/
package org.eclipse.che.dto.generator;

import com.google.common.base.Preconditions;
import com.google.common.primitives.Primitives;

import org.eclipse.che.dto.server.JsonSerializable;
import org.eclipse.che.dto.shared.DelegateRule;
import org.eclipse.che.dto.shared.DTOImpl;
import org.eclipse.che.dto.shared.DelegateRule;
import org.eclipse.che.dto.shared.DelegateTo;
import org.eclipse.che.dto.shared.JsonArray;
import org.eclipse.che.dto.shared.JsonStringMap;
import org.eclipse.che.dto.shared.SerializationIndex;

import com.google.common.base.Preconditions;
import com.google.common.primitives.Primitives;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -493,6 +493,14 @@ private void emitDeserializeFieldForMethod(Method getter, StringBuilder builder)
emitDeserializerImpl(expandedTypes, 0, builder, fieldNameIn, fieldNameOut, baseIndentation);
builder.append(" dto.").append(getSetterName(fieldName)).append("(").append(fieldNameOut).append(");\n");
builder.append(" }\n");
Type type = expandedTypes.get(0);

Class<?> aClass = getRawClass(type);
if(Boolean.class.equals(aClass)){
builder.append(" else {\n");
builder.append(" dto.").append(getSetterName(fieldName)).append("(").append("false").append(");\n");
builder.append(" }\n");
}
}

private void emitDeserializeFieldForMethodCompact(Method method, final StringBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor;

import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.api.resources.VirtualFile;

/**
* Extension interface for {@link EditorProvider}
* Add ability to create editor asynchronously.
* {@link EditorAgent} should use this interface to crate editor instance
*
* @author Evgen Vidolob
*/
public interface AsyncEditorProvider {

/**
* Create promise for creating new editor instance.
*
* @param file
* the file for which editor should crated
* @return
* promise
*
*/
Promise<EditorPartPresenter> createEditor(VirtualFile file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.editor.AsyncEditorProvider;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.editor.EditorOpenedEvent;
Expand Down Expand Up @@ -167,31 +171,49 @@ private void doOpen(final VirtualFile file, final OpenEditorCallback callback) {
workspaceAgent.setActivePart(openedEditor, EDITING);
callback.onEditorActivated(openedEditor);
} else {
FileType fileType = fileTypeRegistry.getFileTypeByFile(file);
final FileType fileType = fileTypeRegistry.getFileTypeByFile(file);
EditorProvider editorProvider = editorRegistry.getEditor(fileType);
if (editorProvider instanceof AsyncEditorProvider) {
AsyncEditorProvider provider = (AsyncEditorProvider)editorProvider;
Promise<EditorPartPresenter> promise = provider.createEditor(file);
if (promise != null) {
promise.then(new Operation<EditorPartPresenter>() {
@Override
public void apply(EditorPartPresenter arg) throws OperationException {
initEditor(file, callback, fileType, arg);
}
});
return;
}
}
final EditorPartPresenter editor = editorProvider.getEditor();

editor.init(new EditorInputImpl(fileType, file), callback);
editor.addCloseHandler(this);
initEditor(file, callback, fileType, editor);
}
}

workspaceAgent.openPart(editor, EDITING);
openedEditors.add(editor);
private void initEditor(final VirtualFile file, final OpenEditorCallback callback, FileType fileType,
final EditorPartPresenter editor) {
editor.init(new EditorInputImpl(fileType, file), callback);
editor.addCloseHandler(this);

workspaceAgent.setActivePart(editor);
editor.addPropertyListener(new PropertyListener() {
@Override
public void propertyChanged(PartPresenter source, int propId) {
if (propId == EditorPartPresenter.PROP_INPUT) {
if (editor instanceof HasReadOnlyProperty) {
((HasReadOnlyProperty)editor).setReadOnly(file.isReadOnly());
}
workspaceAgent.openPart(editor, EDITING);
openedEditors.add(editor);

callback.onEditorOpened(editor);
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
workspaceAgent.setActivePart(editor);
editor.addPropertyListener(new PropertyListener() {
@Override
public void propertyChanged(PartPresenter source, int propId) {
if (propId == EditorPartPresenter.PROP_INPUT) {
if (editor instanceof HasReadOnlyProperty) {
((HasReadOnlyProperty)editor).setReadOnly(file.isReadOnly());
}

callback.onEditorOpened(editor);
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
}
});
}
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.ide.editor;

import io.typefox.lsapi.ServerCapabilities;

import org.eclipse.che.plugin.languageserver.ide.editor.codeassist.LanguageServerCodeAssistProcessor;

/**
* @author Evgen Vidolob
*/
public interface LanguageServerCodeassistProcessorFactory {

LanguageServerCodeAssistProcessor create(ServerCapabilities capabilities);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.eclipse.che.plugin.languageserver.ide.editor;

import io.typefox.lsapi.ServerCapabilities;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;

import org.eclipse.che.ide.api.editor.annotation.AnnotationModel;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor;
Expand All @@ -11,29 +14,35 @@
import org.eclipse.che.ide.api.editor.partition.DocumentPositionMap;
import org.eclipse.che.ide.api.editor.reconciler.Reconciler;
import org.eclipse.che.ide.api.editor.reconciler.ReconcilerWithAutoSave;
import org.eclipse.che.plugin.languageserver.ide.editor.codeassist.LanguageServerCodeAssistProcessor;

import java.util.HashMap;
import java.util.Map;

public class LanguageServerEditorConfiguration extends DefaultTextEditorConfiguration {

public static final int INITIAL_DOCUMENT_VERSION = 0;

private final LanguageServerCodeAssistProcessor codeAssistProcessor;
private final LanguageServerFormatter formatter;
private final AnnotationModel annotationModel;
private final ReconcilerWithAutoSave reconciler;

private final ServerCapabilities serverCapabilities;
private final AnnotationModel annotationModel;
private final ReconcilerWithAutoSave reconciler;
private final LanguageServerCodeassistProcessorFactory codeAssistProcessorFactory;

private LanguageServerFormatter formatter;

@Inject
public LanguageServerEditorConfiguration(final LanguageServerCodeAssistProcessor codeAssistProcessor,
public LanguageServerEditorConfiguration(final LanguageServerCodeassistProcessorFactory codeAssistProcessor,
final Provider<DocumentPositionMap> docPositionMapProvider,
final LanguageServerAnnotationModelFactory annotationModelFactory,
final Provider<LanguageServerReconcileStrategy> reconcileStrategyProvider,
final LanguageServerFormatter formatter) {
this.codeAssistProcessor = codeAssistProcessor;
this.formatter = formatter;
formatter.setTabWidth(getTabWidth());
final LanguageServerFormatterFactory formatterFactory,
@Assisted ServerCapabilities serverCapabilities) {
codeAssistProcessorFactory = codeAssistProcessor;
if (serverCapabilities.isDocumentFormattingProvider() || serverCapabilities.isDocumentRangeFormattingProvider() ||
serverCapabilities.getDocumentOnTypeFormattingProvider() != null) {
this.formatter = formatterFactory.create(serverCapabilities);
formatter.setTabWidth(getTabWidth());
}
this.serverCapabilities = serverCapabilities;
this.annotationModel = annotationModelFactory.get(docPositionMapProvider.get());

this.reconciler = new ReconcilerWithAutoSave(DocumentPartitioner.DEFAULT_CONTENT_TYPE, getPartitioner());
Expand All @@ -42,16 +51,20 @@ public LanguageServerEditorConfiguration(final LanguageServerCodeAssistProcessor

@Override
public Map<String, CodeAssistProcessor> getContentAssistantProcessors() {
Map<String, CodeAssistProcessor> map = new HashMap<>();
map.put(DocumentPartitioner.DEFAULT_CONTENT_TYPE, codeAssistProcessor);
return map;
if (serverCapabilities.getCompletionProvider() != null) {
Map<String, CodeAssistProcessor> map = new HashMap<>();
map.put(DocumentPartitioner.DEFAULT_CONTENT_TYPE, codeAssistProcessorFactory.create(serverCapabilities));
return map;
}

return null;
}

@Override
public AnnotationModel getAnnotationModel() {
return annotationModel;
}

@Override
public Reconciler getReconciler() {
return reconciler;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.ide.editor;

import io.typefox.lsapi.ServerCapabilities;

/**
* @author Evgen Vidolob
*/
public interface LanguageServerEditorConfigurationFactory {

LanguageServerEditorConfiguration build(ServerCapabilities capabilities);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package org.eclipse.che.plugin.languageserver.ide.editor;

import com.google.inject.Provider;
import io.typefox.lsapi.InitializeResult;

import org.eclipse.che.api.promises.client.Function;
import org.eclipse.che.api.promises.client.FunctionException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.js.Promises;
import org.eclipse.che.ide.api.editor.AsyncEditorProvider;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.EditorProvider;
import org.eclipse.che.ide.api.editor.defaulteditor.AbstractTextEditorProvider;
import org.eclipse.che.ide.api.editor.defaulteditor.EditorBuilder;
import org.eclipse.che.ide.api.editor.editorconfig.AutoSaveTextEditorConfiguration;
import org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
import org.eclipse.che.ide.ui.loaders.request.MessageLoader;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.plugin.languageserver.ide.registry.LanguageServerRegistry;

import javax.inject.Inject;

public class LanguageServerEditorProvider extends AbstractTextEditorProvider {
public class LanguageServerEditorProvider implements AsyncEditorProvider, EditorProvider {

private Provider<LanguageServerEditorConfiguration> editorConfigurationProvider;
private LanguageServerEditorConfigurationFactory editorConfigurationFactory;
private final LanguageServerRegistry registry;
private final LoaderFactory loaderFactory;

@Inject
public LanguageServerEditorProvider(final Provider<LanguageServerEditorConfiguration> editorConfigurationProvider) {
this.editorConfigurationProvider = editorConfigurationProvider;
public LanguageServerEditorProvider(LanguageServerEditorConfigurationFactory editorConfigurationFactory,
LanguageServerRegistry registry,
LoaderFactory loaderFactory) {
this.editorConfigurationFactory = editorConfigurationFactory;
this.registry = registry;
this.loaderFactory = loaderFactory;
}

@Override
Expand All @@ -26,8 +48,45 @@ public String getDescription() {
return "Code Editor";
}


@com.google.inject.Inject
private EditorBuilder editorBuilder;


@Override
protected TextEditorConfiguration getEditorConfiguration() {
return editorConfigurationProvider.get();
public TextEditor getEditor() {
return createEditor(new AutoSaveTextEditorConfiguration());
}

private TextEditor createEditor(TextEditorConfiguration configuration) {
if (editorBuilder == null) {
Log.debug(AbstractTextEditorProvider.class, "No builder registered for default editor type - giving up.");
return null;
}

final TextEditor editor = editorBuilder.buildEditor();
editor.initialize(configuration);
return editor;
}

@Override
public Promise<EditorPartPresenter> createEditor(VirtualFile file) {
if (file instanceof File) {
File resource = (File)file;

Promise<InitializeResult> promise =
registry.getOrInitializeServer(resource.getRelatedProject().get().getPath(), resource.getExtension(), resource.getPath());
final MessageLoader loader = loaderFactory.newLoader("Initializing Language Server for " + resource.getExtension());
loader.show();
return promise.thenPromise(new Function<InitializeResult, Promise<EditorPartPresenter>>() {
@Override
public Promise<EditorPartPresenter> apply(InitializeResult arg) throws FunctionException {
loader.hide();
return Promises.<EditorPartPresenter>resolve(createEditor(editorConfigurationFactory.build(arg.getCapabilities())));
}
});

}
return null;
}
}
Loading

0 comments on commit 965c474

Please sign in to comment.