oleg-shilo / codemap.vscode

Code map (syntax tree) of the active document
MIT License
84 stars 28 forks source link

Alpha Sorting for custom generic mapper #50

Closed achmed13 closed 1 year ago

achmed13 commented 3 years ago

I have set up a custom mapper for MapBasic (syntax similar to VBScript) as follows:

"codemap.mb": [
    {
        "pattern": "^([Ff]unction|[Ss]ub) .*",
        "clear": "[Ff]unction |[Ss]ub ",
        "suffix": "",
        "icon": "function"
    }
],
"codemap.sortingEnabled": true,

It is correctly listing my Functions and Subs, but they are sorted by position and not by name. I have enabled Codemap: Sorting Enabled in the settings, as reflected in the above snippet from settings.json.

Do I need to do something else to enable alphabetical sorting?

Thanks!

oleg-shilo commented 3 years ago

I don't think so.

Can you please share a MapBasic code so I can try to debug?

achmed13 commented 3 years ago

Here is a simple script, zipped. The extension is .mb, and the syntax is similar to VB. The apostrophe is the comment character.

Thanks for taking a look.

ScaleRuler.zip

achmed13 commented 3 years ago

I believe I have found the problem. In mapper_generic.js it is creating the "members" array, but it never sorts it. I added a sort on line 58 (before members.forEach) and it seems to be sorting fine now. It does not obey the extension preference Codemap: Sorting Enabled, but for my purposes I always sort alphabetically anyhow.

Thanks for the great extension!

oleg-shilo commented 3 years ago

The actual problem was caused by the very root level not being sorted. Unfortunately the approach you have proposed conflicts with the nested items and only works for the flat trees like in your sample.

The problem is fixed now (directly). The fix will be available in the very next release.