Unwanted autocomplete when accessing list element by index with square brackets

Issue #1223 resolved
Alexander Johannes created an issue

We are making highly use of the language feature accessing list elements by index in square brackets:

List<String> l = new List<String>{'foo'};

if (l[0] == 'foo') {}

When you type l[0], the system will always open the autocomplete window suggesting unrelated things. This is highly annoying because you are forced to hit escape to dismiss the unwanted dialog. The best thing would be to avoid showing any completion at all once a number has been typed into the brackets.

Comments (13)

  1. Alexander Johannes reporter

    @RoseSilverSoftware, is this project still alive? It is higly unusual, that a bug with this severity does not even get acknowledged.

  2. Scott Wells repo owner

    Hi, Alexander. Yes, this project is still very much alive with new releases just about every week. I'm currently very focused on metadata management-related work. I will be turning to code completion-related bugs and enhancements in the near future, though, at which point this will be worked. Please keep an eye on it for activity shortly.

  3. Scott Wells repo owner

    It's been a long time coming, but I just dropped a fix for this for inclusion in the next build. Sorry it took so long! It had slipped off my radar until I ran across it again while scrubbing the issue tracker a bit.

  4. Alexander Johannes reporter
    • changed status to open

    The issue has not been resolved. I tested my example in the anonymous apex window and still get the same annoying autocoplete window. 2.0.9.8 has been installed.

  5. Scott Wells repo owner

    Alexander, I'm unable to reproduce this any longer:

    Issue_1223.png

    Can you please describe exactly what you're doing that reproduces it?

  6. Scott Wells repo owner

    Thanks, Alexander. That makes it very simple to reproduce. There's something about being inside a conditional expression (and perhaps other expressions) that changes the completion context. I'll take care of it for the next build.

  7. Scott Wells repo owner

    Okay, I figured it out.

    More than you probably want to know, but the core of the issue is that in Apex, identifier names cannot start with numerics, but the way that the IDE handles code completion is to inject a dummy identifier at the point of insertion when completion is request. As a result, after you type 0, auto-completion tries to parse a dummy document with 0<dummyIdentifier>, and parsing fails. As a result, due to the parse error at the caret during completion, parser recovery rules kick in which may take you up to some other higher level in the parse tree.

    I fixed this by adding a specific recovery rule for the array index operator to stop at the closing bracket, and I had to update a few of the other completion rules for identifiers so they don't offer completions immediately following an integer literal.

    It's very possible (likely?) that I've missed a few corner cases with this latest fix, but I think it should cover 95+% of the situations where this might occur. Once I deliver the new fix--unless it's just broken--I think we'll handle those corner cases on a one-off basis.

    I'll try to get a new build out tomorrow.

  8. Scott Wells repo owner

    Okay, I just posted 2.0.9.9 which should be a much more complete fix for this. Please let me know what issues you find with it, if any.

  9. Alexander Johannes reporter

    Thanks for investing your time on this! A quick test showed that the issue has been resolved. I will open a new issue, if we encounter similar issues. Keep up the good work!

  10. Log in to comment