/** Trigger content assist on choice positions */ private void triggerContentAssist() { if (fFramePosition instanceof ProposalPosition) { ProposalPosition pp = (ProposalPosition) fFramePosition; ICompletionProposal[] choices = pp.getChoices(); if (choices != null && choices.length > 0) { fAssistant.setCompletions(choices); fAssistant.showPossibleCompletions(); return; } } fAssistant.setCompletions(new ICompletionProposal[0]); fAssistant.hidePossibleCompletions(); }
private void goToLinkedMode(ITextViewer viewer, int offset, IDocument doc, int exitPos, int iPar, List<Integer> offsetsAndLens) throws BadLocationException { if (!goToLinkedMode) { return; } if (offsetsAndLens.size() > 0) { LinkedModeModel model = new LinkedModeModel(); for (int i = 0; i < offsetsAndLens.size(); i++) { Integer offs = offsetsAndLens.get(i); i++; Integer len = offsetsAndLens.get(i); if (i == 1) { firstParameterLen = len; } int location = offset + iPar + offs + 1; LinkedPositionGroup group = new LinkedPositionGroup(); ProposalPosition proposalPosition = new ProposalPosition(doc, location, len, 0, new ICompletionProposal[0]); group.addPosition(proposalPosition); model.addGroup(group); } model.forceInstall(); final LinkedModeUI ui = new EditorLinkedModeUI(model, viewer); ui.setDoContextInfo(true); //set it to request the ctx info from the completion processor ui.setExitPosition(viewer, exitPos, 0, Integer.MAX_VALUE); Runnable r = new Runnable() { @Override public void run() { ui.enter(); } }; RunInUiThread.async(r); } }
@Override public void apply(IDocument document) { try { //default apply int lineOfOffset = document.getLineOfOffset(fReplacementOffset); document.replace(fReplacementOffset, fReplacementLength, fReplacementString); if (SharedCorePlugin.inTestMode()) { return; } int lineOffset = document.getLineOffset(lineOfOffset); int lineLength = document.getLineLength(lineOfOffset); String lineDelimiter = document.getLineDelimiter(lineOfOffset); int lineDelimiterLen = lineDelimiter != null ? lineDelimiter.length() : 0; ISourceViewer viewer = sourceViewer; LinkedModeModel model = new LinkedModeModel(); LinkedPositionGroup group = new LinkedPositionGroup(); //the len-3 is because of the end of the string: " = " because the replacement string is //something like "xxx = " ProposalPosition proposalPosition = new ProposalPosition(document, fReplacementOffset, fReplacementString.length() - 3, 0, new ICompletionProposal[0]); group.addPosition(proposalPosition); model.addGroup(group); model.forceInstall(); final LinkedModeUI ui = new EditorLinkedModeUI(model, viewer); ui.setExitPosition(viewer, lineOffset + lineLength - lineDelimiterLen, 0, Integer.MAX_VALUE); Runnable r = new Runnable() { @Override public void run() { ui.enter(); } }; RunInUiThread.async(r); } catch (Throwable x) { // ignore Log.log(x); } }