Replies: 1 comment 4 replies
-
Hey @sorawee, Langium is mainly designed as a toolkit to build language servers and surrounding tools from one code base. Language servers typically don't follow model- or type-driven development practices as they have a different set of requirements. They cannot simply outright reject invalid input, as that would make it impossible to provide meaningful, semantically correct results on not-quite correct data. I.e. programs that are in the process of being written.
The caching mechanism is designed with caching data for AST nodes in mind. More specifically, we usually use it to cache scoping and type system information for specific documents. Note that attaching data to an AST node directly (you can always attach more properties to an AST node in JS) is usually not a good idea, as the AST node is not recreated upon changes to the workspace. E.g. if you have a dependency from file A to file B, changing file B will not lead to file A getting re-parsed. However, our caching will catch that (assuming it is correctly configured), and invalidate the cache for file A as well, as changes to file B might invalidate computed data on file A. |
Beta Was this translation helpful? Give feedback.
-
There are common wisdoms in type-driven development like make illegal states unrepresentable and parse, don't validate. Langium's validation phase is the opposite of these approaches: validation doesn't allow us to decorate the AST with verified data and types that guarantee their correctness. I know there's a caching mechanism that I could use, but that really seems like a hack. Is there any other mechanisms that I missed?
Beta Was this translation helpful? Give feedback.
All reactions