Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing field completion in nested with closure #803

Closed
mauromol opened this issue Jan 31, 2019 · 6 comments
Closed

Missing field completion in nested with closure #803

mauromol opened this issue Jan 31, 2019 · 6 comments
Assignees
Milestone

Comments

@mauromol
Copy link

Consider this:

package test48

class Test48 {
	String foobar
	
	void doSomething() {
		new Object().with {
			new Object().with { 
				foo|
			}
		}
	}
}

Invoke code assist at "|": foobar is not proposed. Please note it is if you are outside the inner with closure body.

@eric-milles
Copy link
Member

Within StatementAndExpressionCompletionProcessor.generateProposals(IProgressMonitor) there is this stuff. At the moment, only one level of enclosure is handled:

            isStatic = requestor.isStatic;
            context.lhsType = requestor.lhsType;
            completionType = getCompletionType(completionNode, context, requestor);

            int closureStrategy = -1;
            if (isPrimary && requestor.currentScope.getEnclosingClosure() != null) {
                closureStrategy = requestor.currentScope.getEnclosingClosureResolveStrategy();
            }

            List<IProposalCreator> creators = chooseProposalCreators(context);
            // if completionType is delegate, use instance (non-static) semantics
            boolean isStatic1 = (isStatic && closureStrategy < Closure.OWNER_FIRST);
            proposalCreatorLoop(groovyProposals, creators, requestor, context, options, completionType, isStatic1, isPrimary);

            ...

            // within a closure, include content assist for the enclosing type (aka "owner")
            if (closureStrategy >= Closure.OWNER_FIRST) {
                ClassNode enclosingType = requestor.currentScope.getOwner();
                if (enclosingType != null && !enclosingType.equals(completionType)) {
                    List<IGroovyProposal> ownerProposals = new ArrayList<>(); // keep proposals separate
                    proposalCreatorLoop(ownerProposals, creators, requestor, context, options, enclosingType, isStatic, isPrimary);

                    // if "delegate" and/or "owner" qualifiers are required, add them now
                    setClosureQualifiers(groovyProposals, ownerProposals, closureStrategy);

                    groovyProposals.addAll(ownerProposals);
                }
            }

@eric-milles
Copy link
Member

eric-milles commented Feb 4, 2019

Ready to test.

Probably doesn't handle same-named proposals too well in this situation. For example, if the declaring class and each delegate for "with" had a property "foobar", you would see 3 proposals but the qualifiers needed to disambiguate won't get inserted correctly.

@mauromol
Copy link
Author

Hi Eric, sorry for the delay, I verified this works well in 3.3.0.xx-201902091728-e1812, thank you! 👍

@mauromol
Copy link
Author

Hi Eric, sorry, I found another example which I think is equivalent to this that doesn't work yet:

package test49

import java.util.zip.ZipOutputStream

class Test49 {
	String foobar
	
	void doSomething() {
		def tmpFile = File.createTempFile('export', '.zip')
		def records = []
		tmpFile.withOutputStream { tmpOut ->
			def zipOs = new ZipOutputStream(tmpOut)
			zipOs.comment = 'foo'
			zipOs.withStream { zip ->
				foo|
			}
		}
	}
}

Completion of foobar at "|" is not proposed...

eric-milles added a commit that referenced this issue Feb 11, 2019
@eric-milles
Copy link
Member

Ready to re-test

@mauromol
Copy link
Author

Hi Eric, I confirm that with 3.3.0.xx-201902111952-e1812 the new use case works as well. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants