From 166dc00943808d99182110087e7f6e70194b982a Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Mon, 5 Feb 2018 11:56:14 -0600 Subject: [PATCH] Fix for issue #410: linking mode for completion w/o argument insertion - fixes '{' trigger w/o argument insertion: "new T({|)" -> "new T() {|" --- .../GroovyJavaMethodCompletionProposal.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/completions/GroovyJavaMethodCompletionProposal.java b/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/completions/GroovyJavaMethodCompletionProposal.java index 26c2a6dd8b..59429185b9 100644 --- a/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/completions/GroovyJavaMethodCompletionProposal.java +++ b/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/completions/GroovyJavaMethodCompletionProposal.java @@ -126,12 +126,16 @@ public void apply(IDocument document, char trigger, int offset) { super.apply(document, trigger, offset); - if (getContextInformationPosition() > 0) { + if (fContextInformationPosition > 0) { // change offset from relative to absolute - setContextInformationPosition(getContextInformationPosition() + getReplacementOffset()); - } - if (fPositions != null && !fPositions.isEmpty()) { - fSelectedRegion = new Region(fPositions.get(0).getOffset(), fPositions.get(0).getLength()); + setContextInformationPosition(getReplacementOffset() + fContextInformationPosition); + + // coordinate editor selection with context display and linking mode + if (fPositions == null || fPositions.isEmpty()) { + fSelectedRegion = new Region(fContextInformationPosition, 0); + } else { + fSelectedRegion = new Region(fPositions.get(0).getOffset(), fPositions.get(0).getLength()); + } } } catch (Exception e) { GroovyContentAssist.logError(e); @@ -220,8 +224,7 @@ protected String computeReplacementString() { buffer.append(SPACE); } - setCursorPosition(buffer.length()); // position cursor inside parentheses - setContextInformationPosition(getCursorPosition()); + setContextInformationPosition(buffer.length()); if (!fPreferences.bCommandChaining) buffer.append(RPAREN); @@ -258,7 +261,7 @@ protected String computeReplacementString() { setContextInformationPosition(buffer.length()); - // now add the parameters; named parameters go first + // add the parameters; named parameters precede positional parameters char[][] namedParameterNames = ((GroovyCompletionProposal) fProposal).getNamedParameterNames(); char[][] regularParameterNames = ((GroovyCompletionProposal) fProposal).getRegularParameterNames(); int namedCount = namedParameterNames.length, totalCount = regularParameterNames.length + namedCount; @@ -436,30 +439,31 @@ public Point getSelection(IDocument document) { return super.getSelection(document); } - @Override - protected boolean needsLinkedMode() { - return (fPositions != null); - } - @Override protected void setUpLinkedMode(IDocument document, char closingCharacter) { if (getTextViewer() != null) { try { int baseOffset = getReplacementOffset(); LinkedModeModel model = new LinkedModeModel(); - for (int i = 0; i < fPositions.size(); i += 1) { - Position position = fPositions.get(i); - // change offset from relative to absolute - position.setOffset(baseOffset + position.getOffset()); + if (fPositions == null) { LinkedPositionGroup group = new LinkedPositionGroup(); - if (fProposals.size() <= i || fProposals.get(i).length < 2) { - group.addPosition(new LinkedPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP)); - } else { - ensurePositionCategoryInstalled(document, model); - document.addPosition(fPositionCategory, position); - group.addPosition(new ProposalPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP, fProposals.get(i))); - } + group.addPosition(new LinkedPosition(document, baseOffset + fContextInformationPosition, 0)); model.addGroup(group); + } else { + for (int i = 0, n = fPositions.size(); i < n; i += 1) { + Position position = fPositions.get(i); + // change offset from relative to absolute + position.setOffset(baseOffset + position.getOffset()); + LinkedPositionGroup group = new LinkedPositionGroup(); + if (fProposals.size() <= i || fProposals.get(i).length <= 1) { + group.addPosition(new LinkedPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP)); + } else { + ensurePositionCategoryInstalled(document, model); + document.addPosition(fPositionCategory, position); + group.addPosition(new ProposalPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP, fProposals.get(i))); + } + model.addGroup(group); + } } JavaEditor editor = getJavaEditor(); if (editor != null) {