Search in sources :

Example 1 with ErlangBrowserInformationControlInput

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));
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Point(org.eclipse.swt.graphics.Point) DebugException(org.eclipse.debug.core.DebugException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) ErlangBrowserInformationControlInput(org.erlide.ui.internal.information.ErlangBrowserInformationControlInput) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OpenUtils(org.erlide.ui.actions.OpenUtils) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 2 with ErlangBrowserInformationControlInput

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();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ErlangBrowserInformationControlInput(org.erlide.ui.internal.information.ErlangBrowserInformationControlInput) ISelection(org.eclipse.jface.viewers.ISelection) Display(org.eclipse.swt.widgets.Display)

Aggregations

ErlangBrowserInformationControlInput (org.erlide.ui.internal.information.ErlangBrowserInformationControlInput)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 DebugException (org.eclipse.debug.core.DebugException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 Point (org.eclipse.swt.graphics.Point)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)1 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlProject (org.erlide.engine.model.root.IErlProject)1 OpenResult (org.erlide.engine.services.search.OpenResult)1 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)1 OpenUtils (org.erlide.ui.actions.OpenUtils)1