Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background static analysis for multiple projects loaded on Emacs startup #1

Open
practicalli-johnny opened this issue Apr 29, 2020 · 4 comments

Comments

@practicalli-johnny
Copy link

practicalli-johnny commented Apr 29, 2020

When using anakondo with Spacemacs (develop) and multiple projects are re-opened on restarting, interaction with Spacemacs is blocked until static analysis is complete.

To reproduce:

  1. Add anakondo as described in the Spacemacs configuration below
  2. Add several Clojure projects (or one very large one) to emacs using projectile or layouts
  3. Restart Spacemacs so existing projects reload
  4. Wait as anakondo statically analyses all project. I have 13 Clojure projects and have to wait approximately 60 seconds for the analysis (12 thread i7 cpu).
  5. Once analysis of all projects is complete, Spacemacs responds to key presses.

Spacemacs configuration
anakondo is added to the dotspacemacs-additional-packages '(anakondo) list which downloads the package.

anakondo is enabled by including the following in dotspacemacs/user-config

  ;; Lazy load of anakondo until Clojure buffer is used
  (autoload 'anakondo-minor-mode "anakondo")
  ;;
  ;; Enable anakondo-minor-mode in all Clojure buffers
  (add-hook 'clojure-mode-hook #'anakondo-minor-mode)
  ;; Enable anakondo-minor-mode in all ClojureScript buffers
  (add-hook 'clojurescript-mode-hook #'anakondo-minor-mode)
  ;; Enable anakondo-minor-mode in all cljc buffers
  (add-hook 'clojurec-mode-hook #'anakondo-minor-mode)
@practicalli-johnny
Copy link
Author

Spacemacs also blocked when loading in a perspectives file that contains multiple Clojure projects, until static analysis has completed.

@practicalli-johnny practicalli-johnny changed the title background static analysis to support automatic loading of projects after Emacs restart background static analysis for multiple projects loaded on Emacs startup Apr 29, 2020
@practicalli-johnny
Copy link
Author

For the moment, I have commented out the code in dotspacemacs/user-config and simply include anakondo in the dotspacemacs-additional-packages.

SPC SPC anakondo-minor-mode then enables the package and starts the static analysis just for that specific project (which is usually just a few seconds or less).

@didibus
Copy link
Owner

didibus commented May 3, 2020

Making analysis happen async in the background is still a goal of mine. But it requires a certain level of refactor and adds a bit of complexity.

I'm thinking an alternate solution that gives us 80% of the benefits is to cache the analysis to a file. I'm thinking I can key the cache on the deps.edn last modified timestamp. So if you haven't changed your dependencies, it won't need to rerun analysis. Source code changes, if they are all made inside Emacs with anakondo turned on should automatically update the cache. Right now it does so when you call for completion, but I could make it more robust and have it re-run per-file when the buffer is saved as well. Single file analysis is really quick, so users wouldn't even notice this happens after save.

So the issues with this would be:

  1. Can get out of sync with source code if source files are added or changed outside of anakondo buffers.

  2. When source files are removed, it won't get synced. This shouldn't be a big deal, since people will most likely remove the require as well. But could cause a little be of drift.

  3. Can get out of sync if dependencies use snapshot release, and so changes can be pulled in without touching the deps.edn file.

Whenever the user feels things are out of sync, they can force refresh the cache with anakondo-refresh-project-cache command. So since I expect it to be rare, I think this is a good 80/20 rule solution.

I think implementing this wouldn't take me very long, compared to async analysis, so I might start with it, and postpone the work for async analysis.

One more consideration:

  • I'll keep it so that if the mode is disabled in a particular buffer for the project, the cache is deleted. I think disablong/re-enabling the mode should reset everything as I imagine that be one reason for users to do so is if they feel things are acting weird.

Another consideration, where to put the cache directory or file? Options are:

  • In the same place clj-kondo puts it's cache
  • Inside the anakondo package dir
  • In OS tmp folder
  • In some new anakondo specific folder that would go in ones project directory

@andreyorst
Copy link
Contributor

Another consideration, where to put the cache directory or file?

Some projects use .cache directory under emacs-user-directory. I think clj-kondo directory is okay too, unless this cache will not interfere with clj-kondo's own cache and produce errors or make either of projects behave incorrectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants