cyrusfirheir / twee3-language-tools

[ VSCode extension ] Syntax highlighting and programmatic language tools for Twee 3, and Twine 2 storyformats.
https://marketplace.visualstudio.com/items?itemName=cyrusfirheir.twee3-language-tools
MIT License
47 stars 16 forks source link

Cache macroList output #11

Closed MinusGix closed 3 years ago

MinusGix commented 3 years ago

The macroList function currently does not cache the files.
Since it is called by collect (which is called by SugarCube diagnostics and hover), it can be called pretty often. While not often enough to likely cause notable/visible input lag it is still reads the file and parses it quite often.
Solution: Use https://code.visualstudio.com/api/references/vscode-api#workspace.createFileSystemWatcher with the current glob for json/yaml/yml files, and keep a global variable (exported or not? I'd say no) of the last parsed result. Then macroList simple checks if it already exists. On a file edit/creation/deletion, all it has to do is perform the parsing again.

I can implement this.

MinusGix commented 3 years ago

Note: I realized that vscode.workspace.openTextDocument probably keeps the file open so it is not a full disk read every time.
Still, caching the parsing result would be useful, especially if/when more complex checks/transformations need to be applied to the information.

cyrusfirheir commented 3 years ago

Agreed! Adds in TODO The the 'list' changes very less, so this would be a lot better.

cyrusfirheir commented 3 years ago

Since #13 was merged... Closing this.