Skip to content
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

rust-analyzer.completion.callable.snippets: "none" is not always respected #19175

Open
Natr1x opened this issue Feb 18, 2025 · 1 comment
Open
Labels
C-bug Category: bug

Comments

@Natr1x
Copy link

Natr1x commented Feb 18, 2025

I tend to find the snippet completions of callables to be more trouble than they are worth, especially when it comes to initiating structs.
And so I want to turn them off.

Unfortunately the rust-analyzer.completion.callable.snippets config does not seem to apply to struct completions.

Since I haven't been able to find any other setting specifically for structs I can only assume that this is a bug.

rust-analyzer version: rust-analyzer 1.84.1 (e71f9a9 2025-01-27)

rustc version: rustc 1.84.1 (e71f9a9a9 2025-01-27)

editor or extension:

NVIM v0.10.4
Build type: RelWithDebInfo
LuaJIT 2.1.1736781742

relevant settings:

default_settings = {
  -- rust-analyzer language server configuration
  ['rust-analyzer'] = {
    completion = {
      postfix = {
        enable = false,
      },
      autoimport = {
        enable = false,
      },
      callable = {
        snippets = "none",
      },
    },
  },
}

code snippet to reproduce:

mod amod {
    #[derive(Debug)]
    pub struct AnInitializerStructuWithManyFields {
        pub a_long_field_name: u32,
        pub b_long_field_name: u32,
        pub c_long_field_name: u32,
        pub d_long_field_name: u32,
        pub e_long_field_name: u32,
        pub f_long_field_name: u32,
        pub g_long_field_name: u32,
        pub h_long_field_name: u32,
        pub i_long_field_name: u32,
        pub j_long_field_name: u32,
        pub k_long_field_name: u32,
    }

    pub fn a_function_initialized_with_said_struct(init_args: &AnInitializerStructuWithManyFields) {
        println!("{init_args:?}");
    }
}

fn main() {
    // Start typing the following and let analyzer suggest completions:
    // amod::a_function_initialized_with_said_struct(&am

    // Expected completion behavior:
    amod::a_function_initialized_with_said_struct(&amod::AnInitializerStructuWithManyFields

    // Actual (incredibly unhelpful) behaviour:
    amod::a_function_initialized_with_said_struct(&amod::AnInitializerStructuWithManyFields { a_long_field_name: (), b_long_field_name: (), c_long_field_name: (), d_long_field_name: (), e_long_field_name: (), f_long_field_name: (), g_long_field_name: (), h_long_field_name: (), i_long_field_name: (), j_long_field_name: (), k_long_field_name: () }

    // If you continue to type until you complete the namespace before letting analyzer suggest completions:
    // Eg. `amod::a_function_initialized_with_said_struct(&amod::`
    // Then I am offered the expected completion of simply the plain struct name.
    // Which 9/10 is what you want if the structure has more than 3 fields since
    // then you can make use of init shorthands and defaults like below:

    let f_long_field_name = 42;
    amod::a_function_initialized_with_said_struct(&amod::AnInitializerStructuWithManyFields {
        f_long_field_name,
        ..Default::default()
    });
}
@Natr1x Natr1x added the C-bug Category: bug label Feb 18, 2025
@ChayimFriedman2
Copy link
Contributor

I don't think we have a setting for that, although we do show the bare path completion, even though it may come later. I guess we could add such setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants