use of org.erlide.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.
the class DialyzerUtils method doDialyze.
public static void doDialyze(final IProgressMonitor monitor, final Set<IErlModule> modules, final Set<IErlProject> projects, final IBackend backend) throws InvocationTargetException, DialyzerErrorException {
if (backend == null) {
ErlLogger.warn("Trying to dialyze with null backend");
return;
}
try {
for (final IErlModule module : modules) {
DialyzerMarkerUtils.removeDialyzerMarkersFor(module.getResource());
}
// TODO handle preferences from multiple projects
final DialyzerPreferences prefs = DialyzerPreferences.get(null);
final Collection<String> pltPaths = prefs.getPltPaths();
// prefs.getFromSource();
final boolean fromSource = false;
// prefs.getNoCheckPLT();
final boolean noCheckPLT = true;
final List<String> files = Lists.newArrayList();
final List<IPath> includeDirs = Lists.newArrayList();
final List<String> names = Lists.newArrayList();
DialyzerUtils.collectFilesAndIncludeDirs(modules, projects, files, names, includeDirs, fromSource);
if (names.isEmpty()) {
return;
}
final String fileNames = names.size() + " modules [" + DialyzerUtils.getFileNames(names) + "]";
monitor.subTask(fileNames);
ErlLogger.trace("dialyzer", "run %s", fileNames);
final IOtpRpc b = backend.getOtpRpc();
final RpcFuture future = ErlideDialyze.dialyze(b, files, pltPaths, includeDirs, fromSource, noCheckPLT);
while (!future.isDone()) {
// check cancellation
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
// check backend down
if (!backend.isRunning()) {
throw new BackendException("Dialyzer: backend " + backend.getName() + " is down");
}
OtpErlangObject r = null;
try {
r = future.checkedGet(500, TimeUnit.MILLISECONDS);
} catch (final TimeoutException e) {
} catch (final RpcTimeoutException e) {
}
if (r != null) {
DialyzerUtils.processResult(b, r);
}
}
} catch (final RpcException e) {
throw new InvocationTargetException(e);
} catch (final BackendException e) {
throw new InvocationTargetException(e);
}
}
use of org.erlide.runtime.rpc.IOtpRpc 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.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.
the class Activator method initWrangler.
/**
* Loads the necessary *.ebin files to the Erlang node for the plug-in.
*
* @throws CoreException
* detailed exception about the loading process errors
*/
private void initWrangler() throws CoreException {
final IOtpRpc mb = getBackend();
RpcResult res = mb.call_noexception("wrangler_refacs", "init_eclipse", "", new Object[0]);
ErlLogger.debug("Wrangler app started:\n" + res);
res = mb.call_noexception("wrangler_error_logger", "init", "x", new OtpErlangList());
ErlLogger.debug("Error logger started:" + res);
}
use of org.erlide.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.
the class HandleEdocLinksLocationListener method changing.
@Override
public void changing(final LocationEvent event) {
ErlangBrowserInformationControlInput input = null;
if (control != null) {
input = control.getInput();
} else if (edocView != null) {
input = edocView.getInput();
}
if (input != null) {
final AbstractErlangEditor editor = input.getEditor();
String moduleName = "";
final Object inputElement = input.getInputElement();
if (inputElement instanceof OpenResult) {
final OpenResult or = (OpenResult) inputElement;
moduleName = or.getName();
}
final ErlangFunctionCall functionCall = HoverUtil.eventToErlangFunctionCall(moduleName, event);
if (functionCall != null) {
final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(editor.getModule());
if (project == null) {
return;
}
final IOtpRpc backend = BackendCore.getBuildBackend(project);
final OtpErlangTuple otpDoc = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, functionCall);
if (Util.isOk(otpDoc)) {
final String docStr = Util.stringValue(otpDoc.elementAt(1));
final StringBuffer result = new StringBuffer(docStr);
String docPath = "";
String anchor = "";
if (otpDoc.arity() > 4) {
docPath = Util.stringValue(otpDoc.elementAt(3));
anchor = Util.stringValue(otpDoc.elementAt(4));
}
if (result.length() > 0) {
final String html = HoverUtil.getHTML(result);
final Object element = new OpenResult(otpDoc.elementAt(2));
input = new ErlangBrowserInformationControlInput(input, editor, element, html, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
}
}
}
if (input != null) {
if (control != null) {
if (control.hasDelayedInputChangeListener()) {
control.notifyDelayedInputChange(input);
} else {
control.setInput(input);
}
} else if (edocView != null) {
edocView.setInfo(input);
}
}
}
use of org.erlide.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.
the class ProcessHelper method getProcsOnTracedNodes.
/**
* Returns list of processes on all traced nodes.
*
* @return list of processes
*/
public static TracedProcess[] getProcsOnTracedNodes() {
try {
final IOtpRpc backend = TraceBackend.getInstance().getBackend(true).getOtpRpc();
final List<OtpErlangAtom> nodeAtoms = new ArrayList<>();
for (final Object o : TraceBackend.getInstance().getTracedNodesArray()) {
final TracedNode tracedNode = (TracedNode) o;
if (tracedNode.isEnabled()) {
nodeAtoms.add(new OtpErlangAtom(tracedNode.getNodeName()));
}
}
final OtpErlangList nodesList = new OtpErlangList(nodeAtoms.toArray(new OtpErlangAtom[nodeAtoms.size()]));
final OtpErlangList procList = (OtpErlangList) backend.call(ProcessHelper.MODULE_NAME, ProcessHelper.FUNCTION_NAME, "x", nodesList);
final TracedProcess[] processes = new TracedProcess[procList.arity()];
for (int i = 0; i < procList.arity(); i++) {
final OtpErlangTuple tuple = (OtpErlangTuple) procList.elementAt(i);
processes[i] = new TracedProcess(tuple);
}
return processes;
} catch (final RpcException e) {
ErlLogger.error(e);
}
return null;
}
Aggregations