netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

[VSCode extension] Typing dot autocompletes in unintuitive ways

Open anthonyvdotbe opened this issue 3 years ago • 6 comments

Apache NetBeans version

Apache NetBeans 16

What happened

Consider the following code:

class Bar {

    static void bar() {
        class Foo { static void foo() {} }
        // cursor here
    }
}

Now type Foo. At this point NetBeans provides suggestions:

image

Then type a dot. Now NetBeans autocompletes Foo. to ForLoopTree. and gives suggestions for it.

What I expected to happen, is for NetBeans to just add the dot, and give suggestions for the class Foo defined in the line above:

image

In other words: when what's before the dot is valid in the current context, typing a dot should never (unless there's sensible exceptions I'm missing) autocomplete. When I want to autocomplete to a type, I can easily press Tab or Enter to autocomplete first, and then type the dot.

How to reproduce

As described in What happened.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

openjdk full version "20-ea+22-1594"

Apache NetBeans packaging

Apache VSNetBeans for VSCode

Anything else

No response

Are you willing to submit a pull request?

Yes

Code of Conduct

Yes

anthonyvdotbe avatar Dec 21 '22 12:12 anthonyvdotbe

FWIW, I think the real issue here is that the code completion does not include Foo, rather than the action done on pressing the dot. I think I have a fair idea on why is that. Much less an idea on how to fix, yet.

lahodaj avatar Mar 19 '25 18:03 lahodaj

Hard disagree. In this case the dependency is missing because of an editor thing, but it could easily be misconfiguration. The dot causing an autofill is surprising behavior every time it happens

bowbahdoe avatar Jun 08 '25 16:06 bowbahdoe

FWIW, there is: https://github.com/apache/netbeans/pull/8515

At the same time, I guess I don't quite understand why having typed System.er, invoking code completion, selecting err in the code completion and pressing . should lead to System.er. rather than System.err.. But as long as there's a setting that would allow me to have the behavior that makes more sense to me (i.e. System.err.), there can also be the other behavior.

lahodaj avatar Jun 12 '25 07:06 lahodaj

I bumped into this last night actually. I was helping someone understand their end of semester "translate this python program into Java" assignment starting with the anonymous main class version since.

void main() {
    String accountNumber = IO.readln("Enter the account number ");
    IO.println("Account number " + accountNumber);
}

is pretty directly explainable as a parallel to

account_number = input("Enter the account number ")
println(f"Account number {account_number}")

But even though the extension was fine to enable the preview feature that allows void main() it didn't know about the IO class for whatever reason.

Every time I typed IO. it would turn into IOError. I needed to first write .readln then use the arrows to get to the left of the . and type IO again.

invoking code completion, selecting err in the code completion and pressing . should lead to System.er.

I think what you are missing is that there is no "selecting err in the code completion" step. All the actions you took were the same as if you never looked at the completion.

bowbahdoe avatar Jun 12 '25 14:06 bowbahdoe

Isn't this what Jan already mentioned above? That sometimes the obvious completion (the class Foo in my OP, the class IO in your example) is missing from the list?

anthonyvdotbe avatar Jun 12 '25 14:06 anthonyvdotbe

Right - but i'm saying that it being missing from the list is a situation to be accounted for. It can happen if you just forget to declare a dependency, its not always something fixable by making the plugin be better about having the class in the list.

When this scenario that is common happens, the experience is jarring

bowbahdoe avatar Jun 12 '25 19:06 bowbahdoe

Another example:

I already have:

import java.util.concurrent.StructuredTaskScope.Subtask.State;

and subtask is of type StructuredTaskScope.Subtask<T>. Yet when I type the dot, I get Thread.State.

Image

anthonyvdotbe avatar Aug 07 '25 14:08 anthonyvdotbe