kilbd / nova-rust

A Rust extension for the Nova text editor, using the Rust Analyzer language server.
MIT License
29 stars 5 forks source link

[SYNTAX] Result<Self, Box<dyn Error>> throws off syntax highlighting #25

Closed adamierymenko closed 2 years ago

adamierymenko commented 2 years ago

Describe what doesn't look right It looks like certain template constructs throw off the highlighter. Can't figure out exactly what it is but I can reproduce.

Screenshots Screen Shot 2022-05-13 at 4 01 53 PM

How would you expect the features to be highlighted? It should highlight Box<dyn Error> and other things after it normally

Sample code

impl Service {
    pub async fn new(base_path: &str) -> Result<Self, Box<dyn Error>> {
        let mut svc = Self {
            rt: tokio::runtime::Handle::current(),
            data: DataDir::open(base_path).await.map_err(|e| Box::new(e))?,
            udp_sockets: parking_lot::RwLock::new(UdpSocketCollection {
                id_assignment_counter: 1,
                sockets: HashMap::with_capacity(16),
                socket_ids: Vec::with_capacity(4),
            }),
            core: None,
        };
        let _ = svc.core.insert(NetworkHypervisor::new(&svc, true).map_err(|e| Box::new(e))?);

        let config = svc.data.config().await;

        Ok(svc)
    }
}

Additional Information

kilbd commented 2 years ago

Thank you for submitting this issue! You managed to uncover TWO syntax issues with the above snippet. First, as you noted, is that return types weren't parsing generics and I don't know how this hasn't come up before. Second, I had overlooked the async keyword for methods, which was breaking parsing.

I added fixes in the v2.0.2 patch release that I just submitted to the Extension Library.