ray-x/cmp-treesitter

Example Rust and collaboration with https://github.com/nvim-treesitter

MarcWeber opened this issue · 0 comments

async fn run(options: Opt) -> Result<()> {
    let (certs, key) = if let (Some(key_path), Some(cert_path)) = (&options.key, &options.cert) {
      key_log
        let key = fs::read(key_path).context("failed to read private key")?;
        let key = if key_path.extension().map_or(false, |x| x == "der") {
            rustls::PrivateKey(key)
        } else {
            let pkcs8 = rustls_pemfile::pkcs8_private_keys(&mut &*key)
                .context("malformed PKCS #8 private key")?;

is sample Rust code from quinn (server.rs in examples).

You see that Some(key_path) defines a var you want to complete.

That Some(key_path) get's understood as identifier (See HERE)

    let_declaration [62, 4] - [121, 6]
      pattern: tuple_pattern [62, 8] - [62, 20]
        identifier [62, 9] - [62, 14]
        identifier [62, 16] - [62, 19]
      value: if_expression [62, 23] - [121, 5]
        condition: let_condition [62, 26] - [62, 95]
          pattern: tuple_pattern [62, 30] - [62, 63]
            tuple_struct_pattern [62, 31] - [62, 45]
              type: identifier [62, 31] - [62, 35] << HERE
              identifier [62, 36] - [62, 44]
            tuple_struct_pattern [62, 47] - [62, 62]
              type: identifier [62, 47] - [62, 51]
              identifier [62, 52] - [62, 61]

Not all identifiers are declarations.

https://github.com/ms-jpq/coq_nvim also has a treesitter based completion implementation. So there might be yet another trace for joint efforts ?

What I am exactly interested in is

  1. preserve order (above cursor, closest first) because I am most likely to be using them again and it means least typing effort
    You seem to have implemented caching, and tell that treesitter is slow. The playground indicated might be fast ?

I have uploaded my code here so that you get a feeling how it behaves and how much it saves.
https://github.com/MarcWeber/nvim-cmp-local-identifiers-by-regex-completion-quick-and-dirty