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;
}
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);
}
});
}
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);
}
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);
}
});
}
Aggregations