Skip to content

Commit

Permalink
Fix compatibility with no names, no parens and argument guessing modes
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 13, 2018
1 parent f93125e commit 74a7736
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,13 @@ abstract class CompletionTestSuite extends GroovyEclipseTestSuite {
* and the target cursor position after after quitting parameter linked mode.
*/
protected void applyProposalAndCheckCursor(ICompletionProposal proposal, String expected,
int expectedSelectionOffset, int expectedSelectionLength = 0, int expectedCursorPosition = expectedSelectionOffset) {

int expectedSelectionOffset, int expectedSelectionLength = 0, int expectedCursorPosition = expectedSelectionOffset) {
applyProposalAndCheck(proposal, expected)

JavaContentAssistInvocationContext context = proposal.@fInvocationContext

assertEquals("Unexpected selection range offset", expectedSelectionOffset, proposal.getSelection(context.document).x);
assertEquals("Unexpected selection range length", expectedSelectionLength, proposal.getSelection(context.document).y);
assertEquals("Unexpected cursor position", expectedCursorPosition, proposal.replacementOffset + proposal.computeCursorPosition());
assertEquals('selection range offset', expectedSelectionOffset, proposal.getSelection(context.document).x)
assertEquals('selection range length', expectedSelectionLength, proposal.getSelection(context.document).y)
assertEquals('cursor position', expectedCursorPosition, proposal.replacementOffset + proposal.cursorPosition)
}

protected void checkReplacementRegexp(ICompletionProposal[] proposals, String expectedReplacement, int expectedCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ final class GroovyLikeCompletionTests extends CompletionTestSuite {
addGroovySource(SCRIPTCONTENTS, nextUnitName())

String contents = 'new Foo().method2'
String expected = 'new Foo().method2(arg, { it })'
String expected = 'new Foo().method2(arg, { })'
checkProposalApplicationNonType(contents, expected, contents.length(), 'method2')
}

Expand Down Expand Up @@ -208,7 +208,7 @@ final class GroovyLikeCompletionTests extends CompletionTestSuite {
addGroovySource(SCRIPTCONTENTS, nextUnitName())

String contents = 'new Foo().method3'
String expected = 'new Foo().method3(arg, { it }) { }'
String expected = 'new Foo().method3(arg, { }) { }'
checkProposalApplicationNonType(contents, expected, contents.length(), 'method3')
}

Expand All @@ -218,7 +218,7 @@ final class GroovyLikeCompletionTests extends CompletionTestSuite {
addGroovySource(SCRIPTCONTENTS, nextUnitName())

String contents = 'new Foo().method3'
String expected = 'new Foo().method3(arg, { it }, { it })'
String expected = 'new Foo().method3(arg, { }, { })'
checkProposalApplicationNonType(contents, expected, contents.length(), 'method3')
}

Expand Down Expand Up @@ -334,7 +334,7 @@ final class GroovyLikeCompletionTests extends CompletionTestSuite {
void testNamedArguments3() {
groovyPrefs.setValue(GroovyContentAssist.NAMED_ARGUMENTS, true)

checkUniqueProposal((SCRIPTCONTENTS - ~/\s*$/) + '.', 'new Foo().', 'method3', 'method3(arg: arg, c1: { it }) { }')
checkUniqueProposal((SCRIPTCONTENTS - ~/\s*$/) + '.', 'new Foo().', 'method3', 'method3(arg: arg, c1: { }) { }')
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,29 @@ final class GuessingCompletionTests extends CompletionTestSuite {
// parameters is not based on actual source location. Need a way to map
// from variable name to local variable declaration in
// GroovyExtendedCompletionContext.computeVisibleElements(String)
String contents = '''\
Closure yyy
def zzz = { -> }
def xxx(Closure c, int i) { }
xxx
'''.stripIndent()
String[][] expectedChoices = [
['zzz', 'yyy', '{ }'] as String[],
['0'] as String[]
]
checkProposalChoices(contents, 'xxx', 'xxx({ }, 0)', expectedChoices)
}

@Test
void testParamGuessing4a() {
String contents = '''\
Closure yyy
def zzz = { -> }
def xxx(Closure c) { }
xxx
'''.stripIndent()
String[][] expectedChoices = [
['zzz', 'yyy', '{ }'] as String[]
['{ }'] as String[]
]
checkProposalChoices(contents, 'xxx', 'xxx { }', expectedChoices)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ final class TriggerCharacterCompletionTests extends CompletionTestSuite {
if (isEnabled(FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER)) {
closure << ' '
}
if (proposal.toString().contains('Closure')) {
if (!isEnabled(GroovyContentAssist.CLOSURE_NOPARENS)) {
closure << 'it'
}
} else {
if (!proposal.toString().contains('Closure')) {
closure << 'o1'
if (isEnabled(FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ARRAY_INITIALIZER)) {
closure << ' '
Expand Down
Loading

0 comments on commit 74a7736

Please sign in to comment.