There are multiple scenarios where we want to traverse an AST and keep track of scope information, e.g. indexing, type-resolving & type-checking, and autocompletion.
Instead of duplicating a bunch of spaghetti code across various crates, we should instead introduce a ScopeAwareVisitor that handles the scope tracking for us with some default method implementations, then we can override the methods that we care about.
The information that we care about is:
Current namespace
Imported classes, functions, constants
Then some helper methods for getting scope info too:
There are multiple scenarios where we want to traverse an AST and keep track of scope information, e.g. indexing, type-resolving & type-checking, and autocompletion.
Instead of duplicating a bunch of spaghetti code across various crates, we should instead introduce a
ScopeAwareVisitor
that handles the scope tracking for us with some default method implementations, then we can override the methods that we care about.The information that we care about is:
Then some helper methods for getting scope info too:
scope()
scope_mut()
current_namespace()
qualify()