use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.
the class ErlProjectTest method findFunctionInExternalFilesTest.
@Test
public void findFunctionInExternalFilesTest() throws Exception {
// given
// a module with calls to the lists module
final IErlProject project = ErlProjectTest.projects[0];
final IErlModule moduleE = ErlideTestUtils.createModule(project, "e.erl", "-module(e).\n-export([f/0]).\nf() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
final ScannerService scanner = moduleE.getScanner();
try {
moduleE.open(null);
// when
// looking for lists:reverse/2 and lists:reverse/1
final IErlModel model = ErlangEngine.getInstance().getModel();
final OpenResult res = ErlangEngine.getInstance().getOpenService().open(moduleE.getScannerName(), 49, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(moduleE), project.getProperties().getExternalModules(), model.getPathVars());
final IErlFunction function = ErlangEngine.getInstance().getModelFindService().findFunction(model, project, moduleE, res.getName(), res.getPath(), res.getFunction(), IErlElementLocator.Scope.PROJECT_ONLY);
assertNotNull(function);
final IErlElement module = model.findModuleFromProject(project, function.getModuleName(), res.getPath(), IErlElementLocator.Scope.PROJECT_ONLY);
// then
// the function should be returned and the module, in External Files
assertNotNull(module);
assertEquals(function.getParent(), module);
assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(function), project);
} finally {
scanner.dispose();
}
}
use of org.erlide.engine.services.search.OpenResult 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.engine.services.search.OpenResult in project erlide_eclipse by erlang.
the class ErlideOpen method open.
@Override
@SuppressWarnings("boxing")
public OpenResult open(final String scannerName, final int offset, final List<OtpErlangObject> imports, final String externalModules, final OtpErlangList pathVars) throws RpcException {
// ErlLogger.debug("open offset " + offset);
final Collection<IPath> extra = SourcePathUtils.getExtraSourcePaths();
final OtpErlangObject res = ideBackend.call(ErlideOpen.ERLIDE_OPEN, "open", "aix", scannerName, offset, mkContext(externalModules, null, pathVars, extra, imports));
return new OpenResult(res);
}
use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.
the class FindAction method run.
/*
* Method declared on SelectionChangedAction.
*/
@Override
public void run(final ITextSelection selection) {
try {
final IErlModule module = fEditor.getModule();
if (module == null) {
return;
}
final ISelection sel = getSelection();
final ITextSelection textSel = (ITextSelection) sel;
final int offset = textSel.getOffset();
final OpenResult res = ErlangEngine.getInstance().getOpenService().open(module.getScannerName(), offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), "", ErlangEngine.getInstance().getModel().getPathVars());
ErlLogger.debug("find " + res);
final ErlangSearchPattern ref = SearchUtil.getSearchPatternFromOpenResultAndLimitTo(module, offset, res, getLimitTo(), true);
if (ref != null) {
SearchUtil.runQuery(ref, getScope(), getScopeDescription(), getShell());
}
} catch (final Exception e) {
handleException(e);
}
}
use of org.erlide.engine.services.search.OpenResult 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);
}
}
}
Aggregations