Skip to content

SortUsings behaves differently in editor quick fix and save file action #651

@ernestasjuska

Description

@ernestasjuska

Hi,

SortUsings behaves differently in editor quick fix and save file action.

Sorting in the editor using quick fix:

settings.json

{
    // "editor.codeActionsOnSave": {
    //     "source.fixAll.al": "explicit",
    // },
    "alOutline.namespacesSortOrder": [
        "System",
        "Microsoft",
        "SofteraBaltic",
    ],
    // "alOutline.codeActionsOnSave": [
    //     "SortUsings",
    // ],
}

This

namespace X;

using SofteraBaltic.C;
using Microsoft.B;
using System.A;

is sorted like this using a "light bulb"

namespace X;

using System.A;
using Microsoft.B;
using SofteraBaltic.C;

which is correct order.

Sorting using file save action:

settings.json

{
    "editor.codeActionsOnSave": {
        "source.fixAll.al": "explicit",
    },
    "alOutline.namespacesSortOrder": [
        "System",
        "Microsoft",
        "SofteraBaltic",
    ],
    "alOutline.codeActionsOnSave": [
        "SortUsings",
    ],
}

This

namespace X;

using SofteraBaltic.C;
using Microsoft.B;
using System.A;

is sorted like this when saving the file:

namespace X;

using Microsoft.B;
using SofteraBaltic.C;
using System.A;

which is just alphabetical order.


Using SortUsings as part as code cleanup works as expected.

    "alOutline.codeCleanupActions": [
        "SortUsings",
    ],

It seems that SortUsings in alOutline.codeActionsOnSave does not consider the workspace settings - removing all workspace settings and using Sort usings quck fix gives the second result.

Here is a simple project without any dependencies for reproducing the problem:
Repro.zip

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions