[#2143] New, faster algorithm for scopes completion, and caching for path normalization
Motivation and Context
This MR reimplements the scoping algorithm for completions, using a faster one. The old scopes are left for the debugger.
Moreover, the LSP would call Path.from_absolute
in a loop for inlay hints and document symbols. This function is expensive (in my machine, for over 800000 definitions, it would take around 5 seconds). Now there is a cache that decreases the time from around 0.14 to 0.24 seconds on my machine for these 800000 definitions.
Related issues
Part of #2143.
✅ Checklist for the LIGO Language Server
- I checked whether I need to update the
README.md
file for the plugin and did so if necessary:-
If I implemented a new LSP request, I added it to the list of supported features that may be disabled -
If I implemented a new LSP method, I added it to the list of supported functionality
-
-
I checked that my changes work in Emacs, Vim, and Visual Studio Code -
(Before merging) The commit history is squashed and prettified, and follows the Serokell commit policy, or the MR is set to squash the commits
Description
Reuse the document symbol def hierarchy building code and share it for completion. Implement a new scope_at_point
function that uses the hierarchy to build the scope for a single point (the original scopes built all scopes).
Component
-
compiler -
website -
webide -
vscode-plugin -
debugger
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
The LSP should now have faster times between keystrokes.
This happens because the LSP would previously calculate all scopes for all points between keystrokes for use in completions. Now, it will do so lazily, only when document symbols or completions for scopes are requested. Moreover, a new algorithm was implemented, that should be much faster.
Also, the LSP would try to normalize paths in a loop for all definitions in case a document symbol or inlay hints request was received. It will now cache those to avoid normalizing paths that were previously normalized, giving a performance boost.
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).