cursive icon indicating copy to clipboard operation
cursive copied to clipboard

Symbol resolution for `clojure.core.match/match`

Open onetom opened this issue 3 years ago • 1 comments

Problem

The lack of macro support for clojure.core.match means, that

  1. the symbols defined in matching patterns are marked as unresolved, preventing eg. rename-refactoring
  2. indentation is not as expected

The only related issue - as of 2022-05-03 - is this: https://github.com/cursive-ide/cursive/issues/1832

Solution

Symbol resolution

Most of the features mentioned on the https://github.com/clojure/core.match/wiki/Basic-usage page would involve symbols, but they are quirky.

  1. for vectors any element can be a symbol and there is support for rest arguments
  2. in maps, the value part can introduce bindings for sure (but maybe the key part too?)
  3. if there are local bindings with the same name as a symbol, symbols act as a reference to the corresponding local binding
  4. within parens, bindings can be introduced after an :or keyword, but should be ignored after :only, :<< (function application) and :guard
  5. probably all of these rules apply recursively for nested vectors, lists and maps

Indentation

Some examples in the core.match README an wiki suggest that clojure.core.match/match should be indented the same way as clojure.core/case.

onetom avatar May 03 '22 03:05 onetom

Until support arrives, I set the symbol resolution of clojure.core.match/match to None, to avoid underlining of bindings and indentation to Indent, so the value to be matched can be on the same line as (match ..., while the pattern-value pairs are only indented with 2 space.

This however, doesn't let me expand selection to pattern-value pairs, only to either the pattern or value, then the whole match-expression.

onetom avatar May 03 '22 03:05 onetom