rewrite-clj

https://github.com/clj-commons/rewrite-clj
2019-11-14T01:59:31.212600Z

after a bit of back and forth, it appears that the following idea leads to automatic closing of delimiters:

(defmethod parse-next* :eof
  [reader]
  (when-let [[open close row col] *delimiter*]
    nil
    #_(let [opening {:row row
                   :col col
                   :message (format "Found an opening %s with no matching %s" open close)}
          closing (assoc (reader/position reader :row :col)
                         :message (format "Expected a %s to match %s from line %d" close open row))]
    (throw (ex-info "Syntax error"
                    {:findings [opening closing]})))))
this is in clj-kondo's vendored rewrite-clj, fwiw. it's ofc a sketch -- need to arrange for the behavior to be optional i guess.

2019-11-14T05:17:51.215500Z

@lee at some point may be we can go over some or all of Marc O'Morain's PR 527 to clj-kondo -- https://github.com/borkdude/clj-kondo/pull/527 -- i'm particularly interested in: > Change rewrite-clj.parser.core/delimiters to keep track of a tuple of [open, close, row, col] rather than just the expected closing delimiter. The extra three fields allow is to construct more informative error messages when a parse error occurs.

lread 2019-11-14T12:13:39.216400Z

looks interesting @sogaiu!

2019-11-14T16:57:43.218100Z

regarding detecting expressions, i realized that it is insufficient to send the text up through the current cursor position (this may not handle the case of when the cursor is in the middle of an identifier) -- possibly a work-around is to send up to the end of the line / row that the current cursor is on.

borkdude 2019-11-14T18:58:48.218600Z

@sogaiu can you give an example of a complete input and the part you want to send to the REPL?

2019-11-14T19:16:18.223800Z

@borkdude here is an example: complete editor buffer content

(comment

  (-> (rz/of-string "(+ 1 1)")
    rz/down
    rz/tag) ; request detection of expression between the 'a' and 'g' on this line

    rz/right
    rz/string)

)
the original idea was to send just:
(comment

  (-> (rz/of-string "(+ 1 1)")
    rz/down
    rz/ta

2019-11-14T19:17:13.224200Z

but this will fail to identify rz/tag because the 'g' is missing. instead, sending up through the end of the line with rz/ta on it:

(comment

  (-> (rz/of-string "(+ 1 1)")
    rz/down
    rz/tag)
seems like it could work.

2019-11-14T23:54:41.224700Z

i made an attempt to get this to work with rewrite-cljs-playground -- here's what i've got so far: https://github.com/sogaiu/rewrite-cljs-playground/commit/7074cfc222aa65c93020bddeed83c0236e4f86b8

2019-11-14T23:55:17.225200Z

so short i wonder if i'm missing some important things...