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