Skip to content

Commit

Permalink
Fix for #690: range expression as supporting node, defer to outer expr
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 21, 2018
1 parent 51cd09e commit 1c306ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,17 @@ final class FieldCompletionTests extends CompletionTestSuite {

@Test
void testRangeExpressionCompletion1() {
String contents = '''\
(0..1).
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, getLastIndexOf(contents, '.'))
proposalExists(proposals, 'to : Comparable', 1)
proposalExists(proposals, 'from : Comparable', 1)
proposalExists(proposals, 'reverse : boolean', 1)
}

@Test
void testRangeExpressionCompletion2() {
setJavaPreference(PreferenceConstants.CODEASSIST_AUTOACTIVATION, 'true')
String contents = '''\
def range = 0.
Expand All @@ -663,7 +674,7 @@ final class FieldCompletionTests extends CompletionTestSuite {
}

@Test
void testRangeExpressionCompletion2() {
void testRangeExpressionCompletion3() {
setJavaPreference(PreferenceConstants.CODEASSIST_AUTOACTIVATION, 'true')
String contents = '''\
def other = 0.b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,21 @@ final class MethodCompletionTests extends CompletionTestSuite {

@Test
void testRangeExpressionCompletion1() {
String contents = '''\
(0..1).
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, getLastIndexOf(contents, '.'))
proposalExists(proposals, 'getTo', 1)
proposalExists(proposals, 'getFrom', 1)
proposalExists(proposals, 'isReverse', 1)
proposalExists(proposals, 'containsWithinBounds', 1)
// and some proposals from java.util.List as well
proposalExists(proposals, 'iterator', 1)
proposalExists(proposals, 'listIterator', 2)
}

@Test
void testRangeExpressionCompletion2() {
setJavaPreference(PreferenceConstants.CODEASSIST_AUTOACTIVATION, 'true')
String contents = '''\
def range = 0.
Expand All @@ -705,7 +720,7 @@ final class MethodCompletionTests extends CompletionTestSuite {
}

@Test
void testRangeExpressionCompletion2() {
void testRangeExpressionCompletion3() {
setJavaPreference(PreferenceConstants.CODEASSIST_AUTOACTIVATION, 'true')
String contents = '''\
def other = 0.h
Expand All @@ -723,7 +738,7 @@ final class MethodCompletionTests extends CompletionTestSuite {
}

@Test
void testRangeExpressionCompletion3() {
void testRangeExpressionCompletion4() {
setJavaPreference(PreferenceConstants.CODEASSIST_AUTOACTIVATION, 'true')
String contents = '''\
def other = 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,15 @@ public void visitPropertyExpression(PropertyExpression expression) {

@Override
public void visitRangeExpression(RangeExpression expression) {
if (!check(expression)) {
return;
}

super.visitRangeExpression(expression);

if (completionOffset <= expression.getFrom().getEnd() || completionOffset >= expression.getTo().getStart()) {
createContext(expression, blockStack.getLast(), ContentAssistLocation.STATEMENT);
if (completionOffset > expression.getStart() && completionOffset <= expression.getEnd()) {
if (completionOffset <= expression.getFrom().getEnd() || completionOffset >= expression.getTo().getStart()) {
createContext(expression, blockStack.getLast(), ContentAssistLocation.STATEMENT);
}
// no completions within the operator
throw new VisitCompleteException();
}
// no completions within the operator
throw new VisitCompleteException();
}

@Override
Expand Down

0 comments on commit 1c306ad

Please sign in to comment.