obsidian-linter icon indicating copy to clipboard operation
obsidian-linter copied to clipboard

Draft: Move Most Linting Logic to Web Workers

Open pjkaufman opened this issue 4 months ago • 0 comments

Fixes #337 Relates to #927 Relates to #872 This should unblock #488 which gets us closer to #183

To make the linting experience better for users, it is better if we can run the linting logic on a separate thread from the main thread. This will allow the user to be able to work on things if linting a file is taking a while. Most rules can run in the web workers. But the ones that deal with moment or obsidian specific logic have to remain on the main thread since they cannot have their data passed to and from the web worker (this is a limitation due to the complexity of the moment object) and because the source code is not available at compile time which makes it impossible to inline the logic from obsidian. So we have to compromise a little here. But this should still be a net improvement for users with larger files or who use mass linting options on their vaults. This will need to be in BETA for some time if possible. So I will need to setup BRAT for this change.

TODO:

  • [x] Swap out uses of the RulesRunner class for references to the lint file manager
  • [ ] Make sure linting on active file change works
  • [ ] Make sure linting on active file change works when custom commands are used and no change is made
  • [ ] Make sure linting on active file change works when custom commands are used and a change is made
  • [ ] Make sure regular linting works
  • [ ] Make sure regular linting works when custom commands are used and no change is made
  • [ ] Make sure regular linting works when custom commands are used and a change is made
  • [ ] Make sure linting a folder works
  • [ ] Make sure linting the vault works
  • [ ] Make sure linting on paste works
  • [ ] Make sure that linting a file with YAML frontmatter that says that all rules are disabled does not run custom commands
  • [ ] Make sure that regular rule disabling via the YAML frontmatter is respected
  • [x] Remove old copy folder and files
  • [ ] Move linting functions to the utils folder as a lint or lint-runner file since it is just a set of related functions that are useful when running linting operations
    • These should mostly be used by the file lint manager, but we shall see
  • [ ] See about setting a timeout on how long the worker can run before it will throw an error to prevent an infinite loop from happening and not allowing more linting to happen
    • I am thinking that 5 or 10 minutes should be a good value to use as a measurement
    • This will help out with making sure that we prevent long running lints from happening unexpectedly
    • We may want a user override, but that can probably wait until users request it
  • [ ] Break up rules runner UTs into their own separate files to make sure that things still work as intended
    • Maybe add more UTs to see how things work together if possible

If we want to have more than 1 worker running at a time:

  • [ ] See about adding file name to logs in console log for lints since there may be 2+ workers now which will make things pretty hectic when it comes to making sure that logs are displayed back to back in the console

pjkaufman avatar Mar 16 '24 16:03 pjkaufman