Plugin configuration with a list

I’m building a plugin which has a list of patterns it tries to match. It loops over the patterns in order and uses the first one that matched.
I want to make the list configurable, so users can add or remove items from the list depending on their needs, maybe even per filetype.

However, the order of the list is important because some patterns are contained in others. I tried using a dictionary but it seems to reorder the elements when iterating over them.

What would be the best way to allow configuration of that list, while avoiding users having to change their config too much when additions are made to the default list?

Maybe you can add another abstraction layer, i.e. the priority.
So you will have a list of priorities, for example 1-10. Then, each entry will have a dictionary for the patterns. And the patterns with same priority does not have specific order.
In this way, user can also add their patterns with different priorities.

1 Like

I like the idea.
I’ve added a priority field to each entry in the list, and sort them in the setup function.

Thanks!