Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce cached document analysis (#457)
This commit introduced analysis, a means to parse, analyze, and cache a document. Currently, analysis only tracks aliases, but it will be extended in the future to track additional scope information, such as imports, bindings, etc. The idea for an analysis struct was borne from performance issues with the existing alias expansion, which would re-walk the AST each time an alias needed to be expanded. This was particularly egregious during indexing -- this new approach indexes the Lexical codebase about an order of magnitude faster. Additionally, the document store (`Lexical.Document.Store`) now has a new feature: derived data. This allows us to lazily analyze documents as needed and cache the analysis result alongside the document in the store, invalidating the analysis whenever the document changes. Selected summary of new APIs/changes: * `Lexical.Ast.analyze(document)` - returns `%Analysis{}` which may or may not be valid (`analysis.valid?`). Used for whole-document analysis, e.g. indexing. * `Lexical.Ast.reanalyze_to(analysis, position)` - returns `%Analysis{}` using the fragment of the original document up to the given position. Useful for things that may not require the whole document, e.g. resolving aliases. If the given analysis is already valid, this is a no-op. * `Lexical.Ast.Aliases` has been removed in favor of analysis. * Many `Lexical.Ast` functions have been refactored to also (or only) accept an analysis in place of a document. * Added concept of derived data to `Lexical.Document.Store`. This allows for a derived analysis to be saved alongside the document and fetched using `{:ok, %Document{}, %Analysis{}} = Document.Store.fetch(uri, :analysis)`. * Refactored a number of existing LS features to use analysis, including entity resolution, completions, references.
- Loading branch information