groovy-eclipse icon indicating copy to clipboard operation
groovy-eclipse copied to clipboard

Cannot easily type an Enum range when "Enable auto activation" for code assist is enabled

Open mauromol opened this issue 7 years ago • 10 comments

Another case similar to #676.

Consider this enumeration:

package test33;

public enum MyEnum {
  FOO, BAR;
}

And assume you want to type this:

package test33

class Test33 {

	void foo() {
		(MyEnum.FOO..MyEnum.BAR).each {
			
		}
	}
}

When you start to type (MyEnum.FOO. and then you hit the second dot, this is what gets inserted: (MyEnum.FOO.BAR..

I see two problems here:

  • in general, having code assist propose BAR when you are at MyEnum.FOO. doesn't make sense to me (this happens even outside the range context)
  • I still think . as a triggering character should simply be disabled whenever preceded by another dot, as discussed in #676.

mauromol avatar Aug 29 '18 10:08 mauromol

I disable . as a trigger if completion expression ends with dot and contains no other dot. In this instance, you have an additional dot in the expression; . trigger exists to be able to add part of a path expression and immediately go to completion proposals for the next path segment.

You can type Esc to disable proposals at any time.

eric-milles avatar Aug 29 '18 15:08 eric-milles

I see, but AFAIK there's no possibility in a path expression to have .., so I'm still convinced that there's no practical case in which treating . as a triggering character when it's preceded by another . is useful. Please correct me if I'm wrong. Do you have any example of the contrary?

mauromol avatar Aug 29 '18 15:08 mauromol

The problem of using Esc here and in #699 is that you realise you had to press Esc when it's too late and the editor has already inserted the wrong thing for you. Unless you have a very strong memory and you know in advance whenever you have to press Esc...

mauromol avatar Aug 29 '18 15:08 mauromol

Type foo. and get completions for bar, etc. Then type . to get foo.bar. and get proposals for baz, etc.

It's difficult to balance/predict the desire to type a range vs. type a path expression. If you use auto-activation, cancelling out of it should be part of your habits in Groovy. There are so many variations.

eric-milles avatar Aug 29 '18 16:08 eric-milles

But I meant "when it's IMMEDIATELY preceded by another .". That is, if you try to type .. (by typing . and then pressing the dot key again), the second dot key press should NOT trigger the completion. This would solve this issue and any similar one I think.

mauromol avatar Aug 29 '18 17:08 mauromol

That is the same scenario as I mentioned for completing foo.bar.baz. You don't need to type anything but .. starting from foo.

I get it; your intent is to type a range. But what I am saying is another user has the intent of typing a path sequence for the exact same keystrokes.

eric-milles avatar Aug 29 '18 17:08 eric-milles

Ok, I got it, you're talking about the very lucky case in which the first proposal is always correct and you can type foo.bar.baz by just typing dot several times... Hmmm... I must think about this some more...

mauromol avatar Aug 29 '18 17:08 mauromol

I was wondering how the vararg method declaration is handled. I mean, if you want to type:

void doSomething(String... args) {
}

When you type "String...":

  • you don't get any meaningful code assist suggestion after the first "." (there are basic proposals like "abstract", "def", "final"): IMHO all (or at least most) of these suggestions are wrong, in any case when you type the second "dot" no selection from this list is made (i.e.: the dot is not considered a trigger character), so you get "String.." correctly, with no interference
  • no hint is given after you have typed the second dot
  • suggestions appear again after you have typed the third dot

Is this case handled in a special way? Can this inspire how to fix the range case?

mauromol avatar Sep 03 '18 08:09 mauromol

When completing a vararg type, the completion context is usually "method" or if your're seeing modifier keywords, it's "class body". The keywords and types proposals use a different set of triggers. https://github.com/groovy/groovy-eclipse/blob/master/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/ProposalUtils.java#L58

eric-milles avatar Sep 03 '18 12:09 eric-milles

When you have def m(String..) {}, current parser recovery creates a property named "def". This is designed for the case where you are starting to type something in between class members. There is no recovery for a malformed parameter list at the moment.

eric-milles avatar Sep 03 '18 13:09 eric-milles