Pedro-Bronsveld/anki-editor

Empty filter highlighted as an error

Closed this issue · 2 comments

I use this addon to add fields to card templates.
The issue is the added fields are basically empty filters, e.g. {{info-Type:}}, so the editor always throws the "Missing field name" error.

While I have added the needed fields into "Custom Filter Names" and even tried to disable the "Invalid Field Diagnostics" and "Invalid Filter Diagnostics" options in the VSCode extension settings, it doesn't seem to make the problem go away.

It isn't a big issue, but still, when valid parts of the code are always highlighted red it makes spotting actual mistakes significantly harder. It would be nice to see an option added for ignoring empty filter fields.

Hi, thanks for raising this issue. I hadn't considered that add-ons could add a filter that wouldn't require a field.

I've updated the setting for custom filters so you can now enter custom filters as both strings and objects. When defining it as an object, you can specify if a field is required when the filter is used in a replacement.
For example:

"anki-editor.customFilterNames": [
        "custom-filter1",
        {
            "name": "custom-filter2",
            "fieldRequired": false
        }
    ]

I've also added a setting to disable the missing field error entirely.

These changes are available in version 1.0.3, which has been published to the VSCode Marketplace.

I hope this solves your issue.

Works great!
Thank you for the quick fix