/* * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) */ @Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer = quickAssistContext.getSourceViewer(); int documentOffset = quickAssistContext.getOffset(); int length = viewer != null ? viewer.getSelectedRange().y : -1; TextInvocationContext context = new TextInvocationContext(viewer, documentOffset, length); IAnnotationModel model = viewer.getAnnotationModel(); if (model == null) return fgNoSuggestionsProposal; List<ICompletionProposal> proposals = computeProposals(context, model); if (proposals.isEmpty()) return fgNoSuggestionsProposal; return proposals.toArray(new ICompletionProposal[proposals.size()]); }
@Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer = quickAssistContext.getSourceViewer(); int documentOffset = quickAssistContext.getOffset(); IEditorPart part = fAssistant.getEditor(); CompilationUnit cu = DartUI.getWorkingCopyManager().getWorkingCopy(part.getEditorInput()); IAnnotationModel model = DartUI.getDocumentProvider().getAnnotationModel(part.getEditorInput()); AssistContext context = null; if (cu != null) { int length = viewer != null ? viewer.getSelectedRange().y : 0; context = new AssistContext(cu, viewer, part, documentOffset, length); } Annotation[] annotations = fAssistant.getAnnotationsAtOffset(); fErrorMessage = null; ICompletionProposal[] res = null; if (model != null && context != null && annotations != null) { List<IDartCompletionProposal> proposals = Lists.newArrayList(); IStatus status = collectProposals( context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals); res = proposals.toArray(new ICompletionProposal[proposals.size()]); if (!status.isOK()) { fErrorMessage = status.getMessage(); DartToolsPlugin.log(status); } } if (res == null || res.length == 0) { return new ICompletionProposal[] { new ChangeCorrectionProposal( CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), 0, null) }; //$NON-NLS-1$ } if (res.length > 1) { Arrays.sort(res, new CompletionProposalComparator()); } return res; }
private List<ICompletionProposal> computeProposals( IQuickAssistInvocationContext context, IAnnotationModel model) { int offset = context.getOffset(); ArrayList<SpellingProblem> annotationList = new ArrayList<>(); Iterator<Annotation> iter = model.getAnnotationIterator(); while (iter.hasNext()) { Annotation annotation = iter.next(); if (canFix(annotation)) { Position pos = model.getPosition(annotation); if (isAtPosition(offset, pos)) { collectSpellingProblems(annotation, annotationList); } } } SpellingProblem[] spellingProblems = annotationList.toArray(new SpellingProblem[annotationList.size()]); return computeProposals(context, spellingProblems); }
@Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext invocationContext) { IAnnotationModel amodel = invocationContext.getSourceViewer().getAnnotationModel(); IDocument doc = invocationContext.getSourceViewer().getDocument(); int offset = invocationContext.getOffset(); Iterator<?> it = amodel.getAnnotationIterator(); TreeSet<ICompletionProposal> proposalSet = new TreeSet<>( new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { if (o1 instanceof ICompletionProposal && o2 instanceof ICompletionProposal) { ICompletionProposal proposal1 = (ICompletionProposal) o1; ICompletionProposal proposal2 = (ICompletionProposal) o2; return proposal1 .getDisplayString() .compareToIgnoreCase(proposal2.getDisplayString()); } return 0; } }); while (it.hasNext()) { Object key = it.next(); if (!(key instanceof SimpleMarkerAnnotation)) { if (key instanceof SpellingAnnotation) { SpellingAnnotation annotation = (SpellingAnnotation) key; if (amodel.getPosition(annotation).overlapsWith(offset, 1)) { ICompletionProposal[] proposals = annotation.getSpellingProblem().getProposals(); for (ICompletionProposal proposal : proposals) { proposalSet.add(proposal); } } } continue; } SimpleMarkerAnnotation annotation = (SimpleMarkerAnnotation) key; populateDataModelForAnnotation(annotation); IMarker marker = annotation.getMarker(); IMarkerResolution[] mapping = fResMap.get(marker); if (mapping != null) { Position pos = amodel.getPosition(annotation); try { int line = doc.getLineOfOffset(pos.getOffset()); int start = pos.getOffset(); String delim = doc.getLineDelimiter(line); int delimLength = delim != null ? delim.length() : 0; int end = doc.getLineLength(line) + start - delimLength; if (offset >= start && offset <= end) { for (IMarkerResolution markerResolution : mapping) { PDECompletionProposal proposal = new PDECompletionProposal(markerResolution, pos, marker); if (!proposalSet.contains(proposal)) { proposalSet.add(proposal); } } } } catch (BadLocationException e) { } } } return proposalSet.toArray(new ICompletionProposal[proposalSet.size()]); }