al-code-outline icon indicating copy to clipboard operation
al-code-outline copied to clipboard

AutoFormat vs. Fix KeyWords casing - Quotes around "Code"

Open pri-kise opened this issue 3 years ago • 10 comments

Hi, maybe you can help me with my current problem. I really love the Code Action to fix the casing. Right now I'm having a problem with the following: The Code Action Removes the quotation marks from field(1; "Code"; Code[20]) --> field(1; Code; Code[20]) but the autoformat feature re-adds the quotes.field(1; Code; Code[20]) --> field(1; "Code"; Code[20]) I don't know which extension causes this. Maybe others had this problem, too?

table 50000 "Dummy TAble"
{
    fields
    {
        field(1; Code; Code[20])
        {
            Caption = 'Code';
            DataClassification = CustomerContent;
            NotBlank = true;
        }
        field(2; Description; Text[50])
        {
            Caption = 'Description';
            DataClassification = CustomerContent;
        }
    }

    keys
    {
        key(Key1; Code)
        {
        }
    }

    fieldgroups
    {
    }
}

Those are the AL related Extensions I'm using right now:

  • AL Language
  • AL Language Tools
  • AL Navigator
  • AL object designer
  • AL Object Id Ninja
  • AL Toolbox
  • AL Variable Helper
  • AZ AL Dev Tools / AL Code Outline
  • BusinessCentral.LinterCop

pri-kise avatar Nov 30 '21 06:11 pri-kise

Hi.

I was trying to replicate your issue, but it works for me without any problems. Have you tried to disable your extensions one by one to check which one is causing it?

anzwdev avatar Dec 21 '21 20:12 anzwdev

I now disabled all extensions despite of the following three:

  • AL Lanuage,
  • AZ AL Dev Tools
  • waldo's CRS AL Language (Dep. of AZ AL Dev Tools)

And it still hapens: Auto-Format adds quotation marks:

        field(1; "Code"; Code[20])
        {
            Caption = 'Code';
            DataClassification = CustomerContent;
            NotBlank = true;
        }

And the code action removes the quotation marks

        field(1; Code; Code[20])
        {
            Caption = 'Code';
            DataClassification = CustomerContent;
            NotBlank = true;
        }

Maybe this is coming from the AL Language extension...?

pri-kise avatar Dec 23 '21 12:12 pri-kise

I've found what it is. It is caused by "CRS - Rename..." commands from waldo's CRS AL Language extension and happens only if you populate "CRS.ObjectNamePrefix" or "CRS.ObjectNameSuffix" settings. It also happens during document save if you select "Rename" or "Reorganize" in the "CRS.OnSaveAlFileAction" setting.

anzwdev avatar Dec 23 '21 21:12 anzwdev

Oh yes, I'm using those two settings for my project, too. I haven't thought about sharing the settings.json, but will try to have that in mind for the next time.

{
    "CRS.OnSaveAlFileAction": "Rename",
    "CRS.ObjectNamePrefix": "XXX ",
    "CRS.FileNamePattern": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
    "CRS.FileNamePatternExtensions": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
    "CRS.FileNamePatternPageCustomizations": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
    "CRS.RemovePrefixFromFilename": true,
    "al.enableCodeActions": true,
    "al.enableCodeAnalysis": true,
    "al.codeAnalyzers": [
        "${CodeCop}",
        "${UICop}",
        "${PerTenantExtensionCop}",
        "${AppSourceCop}"
    ],
    "al.ruleSetPath": "./.vscode/ruleset.json",
    "xliffSync.autoCheckMissingTranslations": true,
    "xliffSync.findBySource": true,
    "xliffSync.baseFile": "Automotive IT Base.g.xlf",
    "alOutline.codeActionsOnSave": [
        "SortProperties",
        "SortTableFields",
        "SortVariables",
        "SortPermissions",
        "SortPermissionSetList"
    ],
    "editor.codeActionsOnSave": {
        "source.fixAll": true
    }
}

Do you have some idea how I could proceed with this issue? Should I create an issue for waldo's CRS AL Language extension or could you provide some temporary help to ignore those Keywords if the CRS settings is present?

pri-kise avatar Dec 27 '21 07:12 pri-kise

Hi

I think that the best option would be to create an issue on Waldo's CRS AL Language github first and ask him to not add these quotes to control/field names even if the name is the same as one of AL keywords or detect if there are quotes around the name and leave it in the same state during save. Then we can wait for the Waldo's aswer and decide/discuss what to do next.

anzwdev avatar Dec 31 '21 14:12 anzwdev

Hi @anzwdev, I have this problem too in all my projects, but I think the best is TO KEEP all this quotes because in some special names like "Code" , "Type", "Document Type"::"Order", ObjectType::"Codeunit", etc which are spread throughout the standard code and in my custom code too, the VSCode AL Language automatic coloring highlights this words erroneusly in blue color because it thinks they are Keywords and not Identifiers.

Is there any way to retain this quotes with your great extension for VSCode?

JavierFuentes avatar Jan 30 '22 12:01 JavierFuentes

I've modified the extension and released a new version. It now keeps quotes around identifiers that look like keyword or data type. For keywords, quotes will never be removed as doing it can sometimes break al parser, but for names that look like al data type (i.e. Code), it is possible to enable old functionality of removing quotes by changing alOutline.fixCaseRemovesQuotesFromDataTypeIdentifiers setting to true.

anzwdev avatar Feb 20 '22 18:02 anzwdev

Hi @anzwdev, I have verified that this new parameter "alOutline.fixCaseRemovesQuotesFromDataTypeIdentifiers": false does not keep the double quotes that other extensions like Waldo's, which are also very useful, automatically add to the action("my_action") { ... } of the Pages.

Could you adapt it to do so and prevent both extensions from generating diffs in the code for this reason simply by pressing Ctrl+S in a .al file?

image

In fact, if I run the CLEANUP process on the Active Editor, it does NOT remove the quotes, but if I run it for the Entire Project it DOES...

Both actions (for 1 file and for all files) should be consistent and subject to the same settings, right?

JavierFuentes avatar Feb 28 '22 08:02 JavierFuentes

Hi @anzwdev , any news after my last feedback?

Could your extension's both actions keep double quotes on page actions when the setting is: "alOutline.fixCaseRemovesQuotesFromDataTypeIdentifiers": false

If you need I'll open a new issue for this, tell me please...

JavierFuentes avatar May 01 '22 11:05 JavierFuentes

Hi @JavierFuentes

I am currently working on another issue and will be looking at this one when I finish. Unfortunately that other task requires a bit of refactoring and it is taking more time that I originally planned :(

anzwdev avatar May 02 '22 22:05 anzwdev

I've released fix in the release 3.0.42. It is now possible to enable or disable removing quotes around identifiers that don't look like al data types by using alOutline.fixCaseRemovesQuotesFromNonDataTypeIdentifiers setting. Default value is true which means that quotes are removed.

anzwdev avatar Apr 02 '23 14:04 anzwdev