wkirschbaum / elixir-ts-mode

Elixir mode using Treesitter for fontification, navigation and indentation
GNU General Public License v3.0
61 stars 11 forks source link

String quote in multi-line @doc interfering with prettify-symbols-mode #42

Open bunnylushington opened 10 months ago

bunnylushington commented 10 months ago

An unterminated single or double quote inside a multi-line @doc construct will inhibit prettify-symbols-mode from functioning correctly. The function prettify-symbols-default-compose-p is specific about when it's willing to prettify a symbol and it appears that the syntax class of the character preceding the symbol is incorrect.

With the simple configuration

(push '("|>" . "▷") prettify-symbols-alist)

we get

@doc """
documentation is here
"""
def test do
  :an_atom
  ▷ IO.inspect
end

@doc """
here's the error, note the apostrophe
"""
def test_2 do
  :an_atom
  |> IO.inspect
end

Single line comments don't trigger the issue. A lone double quote will. Matched quotes of either sort will not.

Not, obviously, a serious or pressing issue! I happen to use a lot of contractions in my docs and noticed the behavior though I'm stumped how best to address it.

wkirschbaum commented 9 months ago

@bunnylushington this is probably related to a syntax-propertize-function setting the quoted text \"\"\" to "$". I am not sure what it is supposed to be, so any insight there will be useful.

I suspect this is the offending function:

(defun elixir-ts--syntax-propertize (start end)
  "Apply syntax text properties between START and END for `elixir-ts-mode'."
  (let ((captures
         (treesit-query-capture 'elixir elixir-ts--syntax-propertize-query start end)))
    (pcase-dolist (`(,name . ,node) captures)
      (pcase-exhaustive name
        ('quoted-text
         (put-text-property (1- (treesit-node-end node)) (treesit-node-end node)
                            'syntax-table (string-to-syntax "$")))))))

The \"\"\" should probably be handled better, but I won't have time to fix it very soon without help.