How Plugin Works¶
When AutoSetSyntax is loaded or plugin/project settings updated, AutoSetSyntax runs following procedures.
- Generate merged settings.
- Find
Match
/Constraint
implementations. - Compile merged settings into rule objects.
- Optimize compiled rule objects.
AutoSetSyntax has some event listeners (see listener.py
) which tests syntax rules by calling SyntaxRuleCollection.test(...)
under certain circumstances.
Before SyntaxRuleCollection.test(...)
runs, ViewSnapshot
is a snapshot of the view at the moment and that snapshot will be used in this whole run to prevent from calling expensive APIs multiple times.
When SyntaxRuleCollection.test(...)
runs, syntax rules in it are tested in the order as they are defined in settings. If there is a syntax rule matches, the test ends and the syntax of the view will be set to the one defined in the syntax rule.
Merge Settings¶
Merged settings are per-window. They are generated by merging plugin settings with project settings.
- If the user updates plugin settings, merged settings for all existing windows should be re-generated.
- If the user updates project settings, only settings of the corresponding project window needs to be re-generated.
Info
Settings precedence: Project settings
> User settings
> Default settings
Find Implementations¶
- Built-in implementations are hard-coded. (see
plugin/rules/constraints/__init__.py
) - Custom implementations are loaded from specific folders if any. (see
_load_custom_implementations()
)
Rule Compilation¶
This step compiles merged settings into a SyntaxRuleCollection
object. All necessary objects are created in this step (and re-used in the future) rather than when rules are tested every time.
Rule Optimization¶
This step optimizes the compiled SyntaxRuleCollection
object by calling its optimize
method.
Currently, it drops invalid rules (like object with invalid args) and unreachable rules. is_droppable
functions in Match
es and Constraint
s are evaluated to decide whether it can be dropped or not.