private void findRefs( final IErlModule theModule, final ITextSelection aSelection, final boolean hasChanged) { final IBackend ideBackend = BackendCore.getBackendManager().getIdeBackend(); fRefs = null; if (fCanceled) { return; } try { final int offset = aSelection.getOffset(); final OpenResult res = ErlideOpen.open( ideBackend.getRpcSite(), theModule, offset, ModelUtils.getImportsAsList(theModule), "", ErlModelManager.getErlangModel().getPathVars()); final ErlangSearchPattern pattern = SearchUtil.getSearchPatternFromOpenResultAndLimitTo( theModule, offset, res, LimitTo.ALL_OCCURRENCES, false); if (fCanceled) { return; } if (pattern != null) { final ErlSearchScope scope = new ErlSearchScope(); scope.addModule(theModule); final List<ModuleLineFunctionArityRef> findRefs = Lists.newArrayList(); // TODO: run in background? for large files, this can take // seconds final OtpErlangObject refs = ErlideSearchServer.findRefs( ideBackend.getRpcSite(), pattern, scope, erlangEditor.getStateDir(), true); if (refs != null) { SearchUtil.addSearchResult(findRefs, refs); fRefs = erlangEditor.markOccurencesHandler.getErlangRefs(theModule, findRefs); } } } catch (final RpcTimeoutException e) { if (!ideBackend.isStopped()) { ErlLogger.warn(e); } } catch (final RpcException e) { ErlLogger.debug(e); } catch (final ErlModelException e) { ErlLogger.debug(e); } catch (final OtpErlangRangeException e) { ErlLogger.debug(e); } if (fRefs == null) { if (!erlangEditor.markOccurencesHandler.fStickyOccurrenceAnnotations) { erlangEditor.markOccurencesHandler.removeOccurrenceAnnotations(); } else if (hasChanged) { erlangEditor.markOccurencesHandler.removeOccurrenceAnnotations(); } } }
@Override public void launch(final ISelection selection, final String mode) { ErlLogger.debug("** Launch:: " + selection.toString()); if (selection.isEmpty()) { return; } if (!(selection instanceof IStructuredSelection)) { return; } final Set<IErlProject> projects = Sets.newHashSet(); final IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (final Object element : structuredSelection.toArray()) { if (!(element instanceof IResource)) { return; } final IErlElement erlElement = ErlModelManager.getErlangModel().findElement((IResource) element); final IErlProject project = ModelUtils.getProject(erlElement); if (project != null) { projects.add(project); } } if (projects.isEmpty()) { return; } projects.addAll(getDependentProjects(projects)); final List<IErlProject> projectList = Lists.newArrayList(projects); Collections.sort( projectList, new Comparator<IErlProject>() { @Override public int compare(final IErlProject o1, final IErlProject o2) { return o1.getName().compareTo(o2.getName()); } }); try { doLaunch(mode, projectList); } catch (final CoreException e) { final IWorkbench workbench = PlatformUI.getWorkbench(); final Shell shell = workbench.getActiveWorkbenchWindow().getShell(); MessageDialog.openError(shell, "Error", e.getStatus().getMessage()); } }
@Override public void launch(final IEditorPart editor, final String mode) { ErlLogger.debug("** Launch :: " + editor.getTitle()); if (editor instanceof ErlangEditor) { final ErlangEditor erlangEditor = (ErlangEditor) editor; final IErlModule module = erlangEditor.getModule(); if (module != null) { final IErlProject project = ModelUtils.getProject(module); if (project != null) { try { doLaunch(mode, Lists.newArrayList(project)); } catch (final CoreException e) { final IWorkbench workbench = PlatformUI.getWorkbench(); final Shell shell = workbench.getActiveWorkbenchWindow().getShell(); MessageDialog.openError(shell, "Error", e.getStatus().getMessage()); } } } } }