stkb / Rewrap

Rewrap extension for VSCode and Visual Studio
https://marketplace.visualstudio.com/items/stkb.rewrap
Other
506 stars 62 forks source link

Feature request: Add support for Clojure doc strings #325

Open jacobemcken opened 2 years ago

jacobemcken commented 2 years ago

The Clojure programming language offers the programmer to write so-called "doc strings" to document a specific function or namespace. At least on the surface it seems similar to Python doc strings which as far as I can tell is somewhat supported in Rewrap already?

In Clojure a doc string could look like the following:

(ns some-namespace.whatever
  "This namespace is just demoing how doc strings are being used. Of course they can take up several lines. Which makes them hard to read. It is much better when the text is wrapped.

   Sometimes with multiple paragraphs."
  (:require [clojure.string :as str]))

(defn my-function
  "Takes a ton of arguments and returns nothing of particular. Just showing of the awesomeness of doc strings."
  [first-arg other-arg & args]
  (println "Just printing something without using the args"))

Doc strings are ALWAYS put in double quotes ("), like any string. The only variant is that it can stretch multiple lines.

Of course, if Rewrap worked on Clojure doc strings, they could look like the following after having used Alt+q on the two doc strings:

(ns some-namespace.whatever
  "This namespace is just demoing how doc strings are being used. Of course
   they can take up several lines. Which makes them hard to read. It is much
   better when the text is wrapped.

   Sometimes with multiple paragraphs."
  (:require [clojure.string :as str]))

(defn my-function
  "Takes a ton of arguments and returns nothing of particular. Just showing
   of the awesomeness of doc strings."
  [first-arg other-arg & args]
  (println "Just printing something without using the args"))
PEZ commented 2 years ago

Since Clojure is a LISP and people define new type of forms at will, it can be quite tricky to identify a doc string. But the most common ones can be covered at least.

stkb commented 2 years ago

I've given some though to this and I'm a little wary of adding something as open as "wrapping any string" and in Python it's also caused problems like #293, though I do have ideas on how to solve that.

The most common cases for doc strings in defn & ns can probably be covered in a hacky way.

For anything else, in the next release it will be possible to wrap any lines that are selected (not just comments), so that might be enough for those.