helix icon indicating copy to clipboard operation
helix copied to clipboard

Bug: Matching brackets not working in plain text.

Open heliostatic opened this issue 4 years ago • 8 comments

Reproduction steps

Expected: Using mm on an eligible character will go to the matching character in the pair. Actual: This only seems to work in files with a language server?

https://user-images.githubusercontent.com/70898/141857740-3cfd7da9-3e57-414c-b6dc-8fae4d277c08.mp4

Environment

  • Platform: macOS
  • Helix version: v0.5.0-114-g225e790

heliostatic avatar Nov 15 '21 21:11 heliostatic

Parsing of matching brackets is done by Tree Sitter, so mm only works on files with a Tree Sitter grammar (not language server).

Omnikar avatar Nov 16 '21 01:11 Omnikar

Right, I meant tree sitter, good correction. But I wasn't clear if @archseer was saying it should also work on raw text as well: Screenshot_20211115-204257.png

heliostatic avatar Nov 16 '21 01:11 heliostatic

Yeah so mm specifically requires tree-sitter: https://docs.helix-editor.com/keymap.html#match-mode

@sudormrfbin recently labeled all the keybindings that require a LSP or a tree-sitter grammar

archseer avatar Nov 16 '21 02:11 archseer

Interesting, thanks!

heliostatic avatar Nov 16 '21 02:11 heliostatic

Also wondering about why some brackets match in tree-sitter supported files and others don't:

https://user-images.githubusercontent.com/70898/142031507-84b35f13-8a2b-4eaa-855f-315b820112e9.mp4

heliostatic avatar Nov 16 '21 17:11 heliostatic

I think that's because it's not the first and last item in a named node.

https://github.com/ikatyang/tree-sitter-toml/blob/7cff70bbcbbc62001b465603ca1ea88edd668704/grammar.js#L48-L55

    table: $ =>
      seq(
        "[",
        choice($.dotted_key, $._key),
        "]",
        $._line_ending_or_eof,
        repeat(choice($.pair, newline)),
      ),

Our implementation.

https://github.com/helix-editor/helix/blob/ed76cdf238b93846fa4edd8f926f6c05fc26b9fd/helix-core/src/match_brackets.rs#L22-L28

Notice the you showed that worked because it's the first and last item.

https://github.com/ikatyang/tree-sitter-toml/blob/7cff70bbcbbc62001b465603ca1ea88edd668704/grammar.js#L187-L200

    array: $ =>
      seq(
        "[",
        repeat(newline),
        optional(
          seq(
            $._inline_value,
            repeat(newline),
            repeat(seq(",", repeat(newline), $._inline_value, repeat(newline))),
            optional(seq(",", repeat(newline))),
          ),
        ),
        "]",
      ),

Not very familiar with this, not sure how to solve.

pickfire avatar Nov 19 '21 14:11 pickfire

We need an implementation sans tree-sitter anyway for working with plaintext files or files without a grammar, so we could fall back to that if tree-sitter based matching returns no results.

sudormrfbin avatar Nov 19 '21 14:11 sudormrfbin

I too have noticed that mm doesn't work in many places.

txtyash avatar Sep 16 '22 20:09 txtyash

This was adrwssed by #4288 and shortcoming in bracket matching when TS is available discussed in the comments were addressed I'm a seperate PR

pascalkuthe avatar Jul 20 '23 01:07 pascalkuthe