Search in sources :

Example 76 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter 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 77 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class FindDefinitionAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    TextEditor textEditor = ((TextEditor) activeEditor);
    TextDocumentPositionParamsDTO paramsDTO = dtoBuildHelper.createTDPP(textEditor.getDocument(), textEditor.getCursorPosition());
    final Promise<List<LocationDTO>> promise = client.definition(paramsDTO);
    promise.then(new Operation<List<LocationDTO>>() {

        @Override
        public void apply(List<LocationDTO> arg) throws OperationException {
            if (arg.size() == 1) {
                presenter.onLocationSelected(arg.get(0));
            } else {
                presenter.openLocation(promise);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            presenter.showError(arg);
        }
    });
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Operation(org.eclipse.che.api.promises.client.Operation) LocationDTO(org.eclipse.che.api.languageserver.shared.lsapi.LocationDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 78 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class FindReferencesAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    //TODO replace this
    if (!(activeEditor instanceof TextEditor)) {
        return;
    }
    TextEditor textEditor = ((TextEditor) activeEditor);
    String path = activeEditor.getEditorInput().getFile().getLocation().toString();
    ReferenceParamsDTO paramsDTO = dtoFactory.createDto(ReferenceParamsDTO.class);
    PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
    positionDTO.setLine(textEditor.getCursorPosition().getLine());
    positionDTO.setCharacter(textEditor.getCursorPosition().getCharacter());
    TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifierDTO.setUri(path);
    ReferenceContextDTO contextDTO = dtoFactory.createDto(ReferenceContextDTO.class);
    contextDTO.setIncludeDeclaration(true);
    paramsDTO.setUri(path);
    paramsDTO.setPosition(positionDTO);
    paramsDTO.setTextDocument(identifierDTO);
    paramsDTO.setContext(contextDTO);
    Promise<List<LocationDTO>> promise = client.references(paramsDTO);
    presenter.openLocation(promise);
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) ReferenceContextDTO(org.eclipse.che.api.languageserver.shared.lsapi.ReferenceContextDTO) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) ReferenceParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.ReferenceParamsDTO) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 79 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class RunClassTestAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    final Project project = appContext.getRootProject();
    EditorPartPresenter editorPart = editorAgent.getActiveEditor();
    final VirtualFile file = editorPart.getEditorInput().getFile();
    String fqn = JavaUtil.resolveFQN(file);
    Map<String, String> parameters = new HashMap<>();
    parameters.put("fqn", fqn);
    parameters.put("runClass", "true");
    parameters.put("updateClasspath", "true");
    Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
    testResultPromise.then(new Operation<TestResult>() {

        @Override
        public void apply(TestResult result) throws OperationException {
            notification.setStatus(SUCCESS);
            if (result.isSuccess()) {
                notification.setTitle("Test runner executed successfully");
                notification.setContent("All tests are passed");
            } else {
                notification.setTitle("Test runner executed successfully with test failures.");
                notification.setContent(result.getFailureCount() + " test(s) failed.\n");
            }
            presenter.handleResponse(result);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError exception) throws OperationException {
            final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
            notification.setContent(errorMessage);
            notification.setStatus(FAIL);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) HashMap(java.util.HashMap) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) TestResult(org.eclipse.che.api.testing.shared.TestResult) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)79 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)21 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)19 OperationException (org.eclipse.che.api.promises.client.OperationException)13 Project (org.eclipse.che.ide.api.resources.Project)13 Resource (org.eclipse.che.ide.api.resources.Resource)11 Test (org.junit.Test)10 Operation (org.eclipse.che.api.promises.client.Operation)9 Path (org.eclipse.che.ide.resource.Path)8 File (org.eclipse.che.ide.api.resources.File)7 Scheduler (com.google.gwt.core.client.Scheduler)6 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)6 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)6 Optional (com.google.common.base.Optional)5 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 HandlesTextOperations (org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 JsonObject (elemental.json.JsonObject)3