Search in sources :

Example 16 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.

the class HoverProvider method computeHover.

@Override
public JsPromise<OrionHoverOverlay> computeHover(OrionHoverContextOverlay context) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
        return null;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
        return null;
    }
    LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
    if (configuration.getServerCapabilities().isHoverProvider() == null || !configuration.getServerCapabilities().isHoverProvider()) {
        return null;
    }
    Document document = editor.getDocument();
    TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getOffset());
    Promise<HoverDTO> promise = client.hover(paramsDTO);
    Promise<OrionHoverOverlay> then = promise.then(new Function<HoverDTO, OrionHoverOverlay>() {

        @Override
        public OrionHoverOverlay apply(HoverDTO arg) throws FunctionException {
            OrionHoverOverlay hover = OrionHoverOverlay.create();
            hover.setType("markdown");
            String content = renderContent(arg);
            //do not show hover with only white spaces
            if (StringUtils.isNullOrWhitespace(content)) {
                return null;
            }
            hover.setContent(content);
            return hover;
        }

        private String renderContent(HoverDTO hover) {
            List<String> contents = new ArrayList<String>();
            for (MarkedStringDTO dto : hover.getContents()) {
                String lang = dto.getLanguage();
                if (lang == null || MarkedString.PLAIN_STRING.equals(lang)) {
                    // plain markdown text
                    contents.add(dto.getValue());
                } else {
                    // markdown code block
                    contents.add("```" + lang + "\n" + dto.getValue() + "\n```");
                }
            }
            return Joiner.on("\n\n").join(contents);
        }
    });
    return (JsPromise<OrionHoverOverlay>) then;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) HoverDTO(org.eclipse.che.api.languageserver.shared.lsapi.HoverDTO) MarkedString(io.typefox.lsapi.MarkedString) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Document(org.eclipse.che.ide.api.editor.document.Document) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) MarkedStringDTO(org.eclipse.che.api.languageserver.shared.lsapi.MarkedStringDTO) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OrionHoverOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionHoverOverlay)

Example 17 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.

the class OrionEditorPresenter method initializeEditor.

@Override
protected void initializeEditor(final EditorAgent.OpenEditorCallback callback) {
    QuickAssistProcessor processor = configuration.getQuickAssistProcessor();
    if (quickAssistantFactory != null && processor != null) {
        quickAssistant = quickAssistantFactory.createQuickAssistant(this);
        quickAssistant.setQuickAssistProcessor(processor);
    }
    editorInit = new OrionEditorInit(configuration, this.codeAssistantFactory, this.quickAssistant, this);
    Promise<Void> initializerPromise = editorModule.getInitializerPromise();
    initializerPromise.catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            displayErrorPanel(constant.editorInitErrorMessage());
            callback.onInitializationFailed();
        }
    }).thenPromise(new Function<Void, Promise<String>>() {

        @Override
        public Promise<String> apply(Void arg) throws FunctionException {
            return documentStorage.getDocument(input.getFile());
        }
    }).then(new Operation<String>() {

        @Override
        public void apply(String content) throws OperationException {
            createEditor(content);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            displayErrorPanel(constant.editorFileErrorMessage());
            callback.onInitializationFailed();
        }
    });
}
Also used : FunctionException(org.eclipse.che.api.promises.client.FunctionException) QuickAssistProcessor(org.eclipse.che.ide.api.editor.quickfix.QuickAssistProcessor) Operation(org.eclipse.che.api.promises.client.Operation) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 18 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.

the class ClasspathMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        return promises.resolve("");
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!JavaUtil.isJavaProject(project.get())) {
        return promises.resolve("");
    }
    final String projectPath = project.get().getLocation().toString();
    return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {

        @Override
        public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
            classpathResolver.resolveClasspathEntries(arg);
            Set<String> libs = classpathResolver.getLibs();
            StringBuilder classpath = new StringBuilder();
            for (String lib : libs) {
                classpath.append(lib).append(':');
            }
            for (ClasspathEntryDto container : classpathResolver.getContainers()) {
                if (!JRE_CONTAINER.equals(container.getPath())) {
                    addLibsFromContainer(container, classpath);
                }
            }
            if (classpath.toString().isEmpty()) {
                classpath.append(appContext.getProjectsRoot().toString()).append(projectPath).append(':');
            }
            return classpath.toString();
        }
    });
}
Also used : Set(java.util.Set) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List)

Example 19 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.

the class SourcepathMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        return promises.resolve("");
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!JavaUtil.isJavaProject(project.get())) {
        return promises.resolve("");
    }
    final String projectPath = project.get().getLocation().toString();
    return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {

        @Override
        public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
            classpathResolver.resolveClasspathEntries(arg);
            Set<String> sources = classpathResolver.getSources();
            StringBuilder classpath = new StringBuilder();
            for (String source : sources) {
                classpath.append(source.substring(projectPath.length() + 1)).append(':');
            }
            if (classpath.toString().isEmpty()) {
                classpath.append(appContext.getProjectsRoot().toString()).append(projectPath);
            }
            return classpath.toString();
        }
    });
}
Also used : Set(java.util.Set) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List)

Example 20 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.

the class MovePresenter method prepareMovingChanges.

private Promise<ChangeCreationResult> prepareMovingChanges(final RefactoringSession session) {
    MoveSettings moveSettings = dtoFactory.createDto(MoveSettings.class);
    moveSettings.setSessionId(refactoringSessionId);
    moveSettings.setUpdateReferences(view.isUpdateReferences());
    moveSettings.setUpdateQualifiedNames(view.isUpdateQualifiedNames());
    if (moveSettings.isUpdateQualifiedNames()) {
        moveSettings.setFilePatterns(view.getFilePatterns());
    }
    return refactorService.setMoveSettings(moveSettings).thenPromise(new Function<Void, Promise<ChangeCreationResult>>() {

        @Override
        public Promise<ChangeCreationResult> apply(Void arg) throws FunctionException {
            return refactorService.createChange(session);
        }
    });
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) FunctionException(org.eclipse.che.api.promises.client.FunctionException) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)

Aggregations

FunctionException (org.eclipse.che.api.promises.client.FunctionException)24 Promise (org.eclipse.che.api.promises.client.Promise)15 Resource (org.eclipse.che.ide.api.resources.Resource)12 Function (org.eclipse.che.api.promises.client.Function)11 Optional (com.google.common.base.Optional)9 Project (org.eclipse.che.ide.api.resources.Project)8 List (java.util.List)7 PromiseError (org.eclipse.che.api.promises.client.PromiseError)7 Path (org.eclipse.che.ide.resource.Path)6 Operation (org.eclipse.che.api.promises.client.Operation)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 ArrayList (java.util.ArrayList)4 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4 MutableProjectConfig (org.eclipse.che.ide.api.project.MutableProjectConfig)4 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)3 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 Set (java.util.Set)2