use of org.erlide.ui.internal.information.ErlangBrowserInformationControlInput in project erlide_eclipse by erlang.
the class ErlTextHover method internalGetHoverInfo.
private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
if (editor == null) {
return null;
}
final StringBuffer result = new StringBuffer();
OpenResult element = null;
// TODO our model is too coarse, here we need access to expressions
final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
final int offset = hoverRegion.getOffset();
final int length = hoverRegion.getLength();
final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
if (!debuggerVar.isEmpty()) {
result.append(debuggerVar);
}
final IErlProject erlProject = editor.getProject();
String docPath = "";
String anchor = "";
try {
if (erlProject == null) {
return null;
}
final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
if (backend == null) {
return null;
}
final IErlModel model = ErlangEngine.getInstance().getModel();
final String externalModulesString = erlProject.getProperties().getExternalModules();
final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
if (Util.isOk(t)) {
element = new OpenResult(t.elementAt(2));
final String docStr = Util.stringValue(t.elementAt(1));
result.append(docStr);
if (t.arity() > 4) {
docPath = Util.stringValue(t.elementAt(3));
anchor = Util.stringValue(t.elementAt(4));
}
} else {
element = new OpenResult(t);
final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
if (found instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) found;
final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
if (comment.isEmpty()) {
return null;
}
result.append(comment);
} else if (found instanceof IErlPreprocessorDef) {
final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
result.append(preprocessorDef.getExtra());
}
}
} catch (final Exception e) {
ErlLogger.warn(e);
return null;
}
final String strResult = HoverUtil.getHTML(result);
return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
use of org.erlide.ui.internal.information.ErlangBrowserInformationControlInput in project erlide_eclipse by erlang.
the class AbstractInfoView method computeAndSetInput.
/**
* Determines all necessary details and delegates the computation into a
* background thread.
*
* @param part
* the workbench part
*/
void computeAndSetInput(final IWorkbenchPart part) {
final int currentCount = ++fComputeCount;
final ISelectionProvider provider = part.getSite().getSelectionProvider();
if (provider == null) {
return;
}
final ISelection selection = provider.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
final Thread thread = new // $NON-NLS-1$
Thread(// $NON-NLS-1$
"Info view input computer") {
@Override
public void run() {
if (currentCount != fComputeCount) {
return;
}
// final IErlElement je= findSelectedJavaElement(part,
// selection);
final Object info = getInfoForSelection(part, selection);
if (info == null || info instanceof ErlangBrowserInformationControlInput && ((ErlangBrowserInformationControlInput) info).getHtml().isEmpty()) {
return;
}
final Shell shell = getSite().getShell();
if (shell.isDisposed()) {
return;
}
final Display display = shell.getDisplay();
if (display.isDisposed()) {
return;
}
display.asyncExec(new Runnable() {
/*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
if (fComputeCount != currentCount || getViewSite().getShell().isDisposed()) {
return;
}
fCurrentViewInfo = info;
doSetInfo(info);
}
});
}
};
thread.setDaemon(true);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
Aggregations