nvim-treesitter-context icon indicating copy to clipboard operation
nvim-treesitter-context copied to clipboard

dropping duplicates in display window

Open ThePrimeagen opened this issue 2 years ago • 3 comments

As of now its pretty impossible to drop duplicates based on node id.

The reason being is if we match the following:

patterns = {
    "else_clause",
    "if_statement",
}

in typescript an else if statement has both of those in a parent child relationship, so you will get 2 copies of the else if ...

A simple fix would be to not append to the list if the previous item is exactly the same.

Thoughts?

ThePrimeagen avatar Mar 09 '22 21:03 ThePrimeagen

Sorry, I don't 100% understand the issue. Can you provide an example?

lewis6991 avatar May 24 '22 11:05 lewis6991

The problem here is that an else if clause is parsed as an else clause, that happens to contain an if statement.

For example this code:

if (false) {

} else if (true) {

}

is parsed as:

if_statement [0, 0] - [4, 1]
  condition: parenthesized_expression [0, 3] - [0, 10]
    false [0, 4] - [0, 9]
  consequence: statement_block [0, 11] - [2, 1]
  alternative: else_clause [2, 2] - [4, 1]
    if_statement [2, 7] - [4, 1]
      condition: parenthesized_expression [2, 10] - [2, 16]
        true [2, 11] - [2, 15]
      consequence: statement_block [2, 17] - [4, 1]

Saecki avatar Jun 20 '22 18:06 Saecki

This shouldn't be an issue anymore, since a context line is only added once even if there are multiple matches in it. At least I can't reproduce it.

Saecki avatar Jun 23 '22 13:06 Saecki