Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match inside/around closest surrounding pair sometimes fails #4568

Closed
Awesomerly opened this issue Nov 2, 2022 · 4 comments
Closed

Match inside/around closest surrounding pair sometimes fails #4568

Awesomerly opened this issue Nov 2, 2022 · 4 comments
Labels
A-core Area: Helix core improvements C-bug Category: This is a bug

Comments

@Awesomerly
Copy link

Awesomerly commented Nov 2, 2022

As a noob to Rust, I’ve started reading the rust book. The finished code block for Chapter 2 looks like this:

use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
    println!("Guess the number!");

    let secret_number = rand::thread_rng().gen_range(1..=100);

    loop {
        println!("Please input your guess.");

        let mut guess = String::new();

        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("You guessed: {guess}");

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}

When I position my cursor into any part of the curly brace enclosed blocks (except for the lines with only right curly brackets) and issue the mim or mam command, no selection is made. mm goes to the enclosing braces just fine, and mi{ / mi} works as expected and selects within the enclosing brackets.

@the-mikedavis the-mikedavis added the C-bug Category: This is a bug label Nov 2, 2022
@kirawi kirawi added the A-core Area: Helix core improvements label Nov 3, 2022
@emilyyyylime
Copy link
Contributor

After a little investigation I came to the conclusion this is caused by < and > not always being used as a matching pair (here in the arrow of the match cases). Do you think we should just ignore them when searching for the closest pair or should we employ some more sophisticated algorithm for searching for the matching pair? (perhaps something that looks in both directions)

@Ktoks
Copy link

Ktoks commented Nov 6, 2022

I've found that mam and mim both work from the ending bracket, but not the beginning bracket of the block of code.
Also, mm, mim, and mam don't work with back-ticks.
I feel like these two could be separate from 4568 though. Would you like another new issue for each to keep them apart?

@emilyyyylime
Copy link
Contributor

emilyyyylime commented Nov 6, 2022

@Ktoks the end/start thing is precisely this issue, the current algorithm to figure out the closest pair only looks for a mismatched closing pair, and it starts from the cursor — so with your cursor on an opening brace it will never find the correct closing brace. furthermore, if there's any mismatched closing brace (including <s) within the braces you're trying to select, it will fail to match as well.

About backticks, however, they aren't a matching surround pair, so the current algorithm doesn't even consider them when looking.

But for good news I think I thought of something that'll fix both of those issues in one — using the tree-sitter to find the closest pair, and only falling back to a general algorithm if no tree-sitter is active. I'll definitely experiment with this more later today

@Ktoks
Copy link

Ktoks commented Nov 6, 2022

That's great news for those who can get treesitter working!

@helix-editor helix-editor locked and limited conversation to collaborators Apr 30, 2024
@pascalkuthe pascalkuthe converted this issue into discussion #10638 Apr 30, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
A-core Area: Helix core improvements C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

5 participants