Skip to content

Commit

Permalink
Fix for #786: set primary node true for script content assist location
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 5, 2019
1 parent 4cf58a3 commit 09cf1da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -502,10 +502,10 @@ final class DSLContentAssistTests extends CompletionTestSuite {
def foo(@DelegatesTo(Integer) Closure cl) {
}
foo {
// here
#
}
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, contents.indexOf('/'))
ICompletionProposal[] proposals = createProposalsAtOffset(contents.replace('#', ''), contents.indexOf('#'))
// should see proposals from String, not Integer
proposalExists(proposals, 'substring', 2)
proposalExists(proposals, 'bytes', 1)
Expand Down Expand Up @@ -548,17 +548,40 @@ final class DSLContentAssistTests extends CompletionTestSuite {
def foo(Closure block) {
}
foo {
// here
#
something
}
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, contents.indexOf('/'))
ICompletionProposal[] proposals = createProposalsAtOffset(contents.replace('#', ''), contents.indexOf('#'))
// should see proposals from String
proposalExists(proposals, 'bytes', 1)
proposalExists(proposals, 'capitalize', 1)
proposalExists(proposals, 'toUpperCase()', 1)
}

@Test // https://github.com/groovy/groovy-eclipse/issues/786
void testStatementPosition4() {
createDsld '''\
contribute(isScript() & isThisType()) {
property name: 'xyz'
}
'''.stripIndent()

String contents = '''\
|/*
| * blah blah blah
| */
|
|import java.util.regex.Pattern
|
|def abc = 123
|
|#
|'''.stripMargin()
ICompletionProposal[] proposals = createProposalsAtOffset(contents.replace('#', ''), contents.indexOf('#'))
proposalExists(proposals, 'xyz', 1)
}

@Test
void testTrailingClosure1() {
setJavaPreference(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, 'false')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,7 +72,8 @@ public List<IGroovyProposal> getStatementAndExpressionProposals(ContentAssistCon

GroovyDSLDContext pattern = new GroovyDSLDContext(context.unit, info.module, info.resolver);
pattern.setCurrentScope(context.currentScope);
pattern.setPrimaryNode(context.location == ContentAssistLocation.STATEMENT || (context.location == ContentAssistLocation.METHOD_CONTEXT && context.currentScope.isPrimaryNode()));
pattern.setPrimaryNode(context.location == ContentAssistLocation.SCRIPT || context.location == ContentAssistLocation.STATEMENT ||
(context.location == ContentAssistLocation.METHOD_CONTEXT && context.currentScope.isPrimaryNode()));
pattern.setStatic(isStatic);
pattern.setTargetType(completionType);

Expand Down

0 comments on commit 09cf1da

Please sign in to comment.