A namespace-managing plugin


#1

I have an idea for a new plugin which works much like parinfer (and maybe can piggieback on it) for keeping one’s namespace form correct and clean. I’m curious what people think of the idea and opinions on how to execute it. Here’s what I’ve got so far:

  • It knows how to find Clojure source files, which means a minimal bit of reading project.clj to find source directories, including :test and such.
  • It parses all source files into a database that includes what namespaces are included with which aliases, which symbols are :refer’d in other files in your project, and so forth.
  • As you type, if you type, s/def, for example, it would find that clojure.spec.alpha is aliased as s/ in another namespace, and add a :require form for it with an alias at the top of your file.
  • If you type, deftest, for example, it would see that this is :refer’d from clojure.test elsewhere in your project, and so it would add it to the :refer for this namespace in this file.
  • It would keep things sorted, of course.
  • It would remove :refer symbols when they are deleted from the file.
  • It would remove a namespace when it has no more used refer symbols or alias prefix.
  • Except, if a namespace never had an alias or refer clause, it is kept (for defmethod and implementations).

What do you think?


#2

Apologies for not seeing this sooner. Just updated my email settings to send daily updates.

I suppose this entering the territory of inferring namespace imports. I would certainly check with the clojure emacs tools to see if there’s anything that does this already. (I’m not an emacs user, but I know they have a ton of automation things like this)


#3

I’ve discussed with some people on the #vim channel, and it seems like the clojure-lsp project is the right place to do this (and it might already do a small bit of it).

I’ve actually been wondering whether the Language Server Protocol spec (which is JSON-RPC) is better than the JSON structures I’m using for Vim calls to parinfer-rust. It has almost everything needed for smart mode, but not quite. I haven’t yet read up on best practices for extending it.