Custom Label detection not working in Apex

Issue #2035 resolved
Ilin Argirov created an issue

It seems that Label detection does not work for me in Apex.

I’m getting a “Cannot resolve symbol ‘Label'” error whenever I try to use a label in my apex code. Please refer to the screenshot attached.

So far, I have tried invalidating caches (full) and restarting, then re-generating the Offline Symbol Table.

I am using WebStorm 2021.3.1 and IC 2.2.0.3.

I notice in the issues, that the Label feature works for many others. Is there anything else I can do to make it work for me as well?

Thanks!

Comments (19)

  1. Scott Wells repo owner

    Hi. IC2 resolves custom labels for purposes of code completion and reference resolution using local metadata files. Have you retrieved your custom label metadata into the local project? If so, are those custom label files under a configured source root?

  2. Ilin Argirov reporter

    Hello Scott,

    Thank you for the quick response.

    I believe that I have the correct configuration (screenshot attached). My CustomLabels metadata file contains all of the labels I am referring to in the code.

    I am not sure as to how deep I need to go when specifying the project source root. At present it is set to the “force-app” folder, and SObject code completion, as well as other IC2 features are working correctly.

    Any guidance is appreciated. Thanks for your time!

  3. Scott Wells repo owner

    That looks correct. Dumb question, but have you restarted the IDE since adding the custom labels file to the local project? I ask because at one point I think I remember another user finding that there was an overly-aggressive in-memory cache for label metadata that wasn't getting updated properly if you added a custom labels file. Obviously if that's the case, that's a bug I need to address, and if it's not, there's some other bug I need to address.

    Assuming that a simple IDE restart doesn't resolve the issue, let's get some diagnostic info. Please add the following to Help>Diagnostic Tools>Debug Log Setting:

    #com.illuminatedcloud.intellij.completion.MetadataCompletionUtil
    

    Note that the leading # is important and must be retained. Then restart the IDE and open a file with custom label references...perhaps even try some Label. code completions. That should result in some debug logging showing how IC2 is trying to find custom labels. Feel free to send me the resulting idea.log file and hopefully it'll provide some insights into what's going on.

  4. Ilin Argirov reporter

    I have restarted the IDE on a number of occasions for sure. I must admit that label completion never worked for me. I just assumed that it was a feature not yet implemented and just got round to submitting a ticket today.

    As per your instructions, I have done the following:
    1. Restarted the IDE. The issue still persists.

    2. Added the diagnostic command to the Debug Tool Settings as it is written in your response.

    3. Quit the IDE and archived the old bloated log

    4. Started the IDE, and attempted Label code completion in the same file where I am currently using Label code completions.

    5. Quit the IDE.

    pastebin with the log.

    From a cursory glance at the log, I did not see any references to the issue I am having. Here’s to hoping I am wrong!

  5. Scott Wells repo owner

    Thanks. Can you verify the name of that file on-disk? Is it CustomLabels.labels-meta.xml or CustomLabels.labels? And also does this project have an sfdx-project.json file in its root directory?

  6. Scott Wells repo owner

    Okay. I may need to get you a build with some additional debug logging that provides more information about how it's searching for local custom labels files. Let me wrap up what I'm doing now and I'll post a new build here. The good news is that custom labels should work well. We just need to figure out why they're not working properly for you right now...

  7. Scott Wells repo owner

    Okay, here's a build that includes more debug logging in this area. Download the attached archive but don't extract it. Install it using Settings / Preferences > Plugins > Install plugin from disk (under the gear drop-down menu). Allow the IDE to restart and try to work with custom labels in Apex. Send over the resulting idea.log after doing so for review.

  8. Scott Wells repo owner

    Hi. I'm not seeing where there's any custom label-related activity. I would expect to see log entries like the following:

    2022-01-21 11:03:07,383 [  29151]  DEBUG - pletion.MetadataCompletionUtil - Finding all custom labels files for module 'module-name'. 
    2022-01-21 11:03:07,383 [  29151]  DEBUG - pletion.MetadataCompletionUtil -   Finding files with extension 'labels-meta.xml'. 
    2022-01-21 11:03:07,467 [  29235]  DEBUG - pletion.MetadataCompletionUtil -   Found 1 matching files:
    /path/to/project/force-app/main/default/labels/CustomLabels.labels-meta.xml 
    2022-01-21 11:03:07,467 [  29235]  DEBUG - pletion.MetadataCompletionUtil -   The custom labels file URLs for module 'module-name' are:
    file://path/to/project/force-app/main/default/labels/CustomLabels.labels-meta.xml 
    2022-01-21 11:03:07,467 [  29235]  DEBUG - pletion.MetadataCompletionUtil - Looking for labels in file /path/to/project/force-app/main/default/labels/CustomLabels.labels-meta.xml. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label addCommentLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label addShoppingListLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label amountLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label clientLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label dateLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label delLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label deleteMe. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label expensesLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label mustBeQuoted. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label myExpensesLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label numberOfExpensesLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label reimbursedLabel. 
    2022-01-21 11:03:07,474 [  29242]  DEBUG - pletion.MetadataCompletionUtil -   Adding label totalExpensesLabel. 
    

    Can you please type Label.<CTRL+SPACE> in an Apex file (even Anonymous Apex) and provide the resulting log? You should see entries similar to the above in the log, even if no files are found.

  9. Ilin Argirov reporter

    Hi. Please see the linked Video of me following your instructions with the idea.log open beside the IDE.

    In it I show the set debug command as well as the IC2 “about” page.

    Attempting to get Label suggestions does not generate logs. Additionally, getting a random SObject’s suggestions does not seem to generate logs as well (not sure if it is meant to).

    Toward the end of the demo, it can be seen that the idea.log changes with a few lines added. I think this means that logging while the file is open works, although I have also tried the steps with the file closed and after a few IDE restarts.

    EDIT:

    I have repeated the steps on the machine at work - installed the custom build and set the debug property as discussed before.

    Unfortunately, nothing of relevance is logged there as well. It is also worth mentioning that Labels do not work there as well.

    EDIT2:

    After consulting with members of my team, it appears that they, too, (in a different project from mine) have experienced the same problem.

  10. Scott Wells repo owner

    Hi. Thanks for the video. I see one very important thing at about 35-37 seconds into the video where you try to get completions for Label.. It doesn't look like it even knows about the Label system type through which those are accessed. Now that I know to look for that, I see the same thing in your original screenshot where Label is flagged as unresolvable. That's why you're not getting any log entries...to get to the logic that logs, it must have determined that you're trying to access children of the System.Label type. For example, here's what it looks like for me:

    System_Label_Completion.png

    Let's focus on that. Can you verify that in your project's offline symbol table, you see a type under the System namespace called Label? If so, it should look something like:

    // Generated by Illuminated Cloud on Fri Jan 21 15:43:40 CST 2022. Do not edit.
    
    global class /*System.*/Label 
    {
        global class Site 
        {
            global static final String authorization_required;
            ...
        }
    
        /**
         * Custom labels for the 'XXX' namespace.
         */
        global class XXX 
        {
            /**
             * Some custom label from an installed managed package.
             */
            global static final String yyy_zzz = 'Some custom label from an installed managed package.';
            ...
       }
    
       ...
    }
    

    If you don't see that, please regenerate the OST and allow the project to close and reopen. If you still don't see it after regenerating the OST, I'll need to get debug logs for that action. If you do see it, are there any other types in your project named Label that might make resolution of that type name ambiguous?

    Hopefully this strategy will get us to a better understanding and ultimately an answer...

  11. Ilin Argirov reporter

    Hi Scott, bullseye!

    My OST has the Label type, although it appears that the IDE has some built-in (configurable) limits as to file size when it comes to intellisense. Screenshot:

    I have used this workaround to enable intellisense for Labels in my case: https://stackoverflow.com/a/42147946

    I thank you again for your time and help with this matter!

    I think it would be quite valuable to warn the user of this and guide them to a potential solution (e.g. as a suggestion below the “No suggestions“ after ctrl + space). Inevitably, there would be a performance impact of changing this setting, but unless my IDE hangs for seconds at a time, it is worth it for me.

  12. Scott Wells repo owner

    Funny...here's mine:

    # custom IntelliJ IDEA properties
    
    idea.max.intellisense.filesize=5000
    
  13. Ilin Argirov reporter

    I have adjusted the max file size to 5000 like you. I’ll keep my ear on the ground when it comes to this, and will increase the size accordingly if needed.

    Another question, how can I get back to the regular non-debug enabled IC2, without losing my settings? I do not mind waiting for the next official release from the jetbrains marketplace if that’s the easiest way to go about it.

  14. Scott Wells repo owner

    The build you have installed has the same version as the current released build. Once I push a new build on Thursday, it will prompt you to update automatically. Nothing special you need to do. You can also remove the entry from debug log settings if you'd like.

  15. Log in to comment