Description
We "discover" projects in a workspace and then initialize projects for every open document. Most of the time this is the same project.
However, if that project fails to initialize it's marked as disabled then it's re-initialized failing again. This registers several watchers and other resources. We should instead:
- Collect all unique projects for open documents
- Initialize those projects
- Work on a mechanism to recover from errors when loading the design system. This includes
@utility
or@variant
being in a nested spot, failure to load a plugin or config, failure to load an import, failure to parse an imported stylesheet, errors caused by invalid@apply
s, etc…
This will definitely require some work in v4 core's __unstable_loadDesignSystem(…)
. We'll likely need to introduce some kind of "error recovery" mode that can capture errors and proceed even when an error happens.
For example:
- Plugins can just not be loaded
- Ditto with configs
- Missing / failed imports can be replaced with an empty AST
- Missing classes in an
@apply
can be omitted - Some syntax errors can be made recoverable — may be able to take some inspiration from Lightning CSS
- Some current syntax errors may not need to be errors at all (e.g. extra semicolons)
We should also find a way to record these errors so they can be surfaced to the user. Doing this via warning notifications could end up being too noisy. Maybe we could present a single warning which can open a document explaining the error(s).
We also need to surface the CSS graph information outside of project discovery so we can provide graph-aware diagnostics.
For example, if a user import's a file into a layer that has @utility
we need to provide a diagnostic for this.