Anonymous Apex code is saved without .apex extension by default

Issue #2127 resolved
Paweł Znamiec created an issue

When I try to save Anonymous Apex code block into file, it saves without .apex extension, so after closing IDE and reopening it, it doesn’t show up its name in Anonymous Apex subtab, and I cannot load it into Anonymous Apex, as it throws ‘Invalid or missing file. Please choose a file with the .apex extension.’ error.

Steps to reproduce

  1. Go to Anonymous Apex tab.
  2. Type System.debug('test');
  3. Save it using ‘Save’ button on the left side, name it ‘test’.
  4. See that Apex code’s subtab changed name to ‘test’.
  5. Close IDE
  6. Open IDE with the same project.
  7. See that Apex code’s subtab has a name ‘Anonymous Apex 1’ (ISSUE 1)
  8. Click ‘Load’ button on the left side, choose ‘test’ file.
  9. See ‘Invalid or missing file. Please choose a file with the .apex extension.’. (ISSUE 2)

Is this intentional or should plugin add .apex extension when needed?

I have tested it on MacOS 12.3.1.

Comments (8)

  1. Scott Wells repo owner

    Hi. I'm not seeing that behavior. I realize that I'm just parroting back almost exactly what you said, but these steps worked fine for me:

    1. Open the Anonymous Apex tool window.
    2. Add some content to the default tab.
    3. Click the Save toolbar button.
    4. In the resulting dialog, provide the name anonApex and notice that it shows an apex extension in the drop-down to the right of the filename.
    5. The tab updated to anonApex.
    6. Close and reopen the project.
    7. Open the Anonymous Apex tool window. The anonApex tab is selected (different from your step 7).
    8. Click the Load toolbar button. It preselects the previously-saved anonApex.apex file.

    So there must be some other difference. For starters, can you confirm that you're using the latest versions of both the base JetBrains IDE and IC2? If so--or if this problem still persists after updating--please reproduce this behavior and immediately capture your idea.log for me to review.

  2. Paweł Znamiec reporter

    Yes, I have everything up-to-date. I recorded a video with reproduction steps for you: https://www.youtube.com/watch?v=85rXCoKuC7k

    It saves file without .apex extensions by default on MacOS. If I would write it myself, everything would be good.

    There is also one interesting quirk, where I try to Load file in “New tab” and it loads successfully. But loading into “Current Tab” throws an error related to .apex extension. It is in the video.

    Also, I attached idea.log file.

  3. Scott Wells repo owner

    Ah, interesting. Yes, this seems to be a Mac-specific behavior due to the native file selection dialogs used on that OS vs. the IDE-provided dialogs used on Windows/Linux. This is actually something that's changing in the upcoming 2022.2 which is already in EAP. Let me see if that update will resolve this issue on Mac. If not, I'll look into making this handle a name entered without an extension better on Mac.

  4. Scott Wells repo owner

    Okay, I just checked 2022.2 and it uses a different file selection dialog, but it still doesn't automatically include the extension. Looks like this needs to be fixed for Mac...

  5. Log in to comment