diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index 4e9b4f7e41b4..a50e1e8f49ad 100644 --- a/src/tools/rust-analyzer/Cargo.lock +++ b/src/tools/rust-analyzer/Cargo.lock @@ -897,6 +897,7 @@ checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", "hashbrown 0.14.5", + "serde", ] [[package]] @@ -1866,6 +1867,7 @@ dependencies = [ "ide-completion", "ide-db", "ide-ssr", + "indexmap", "intern", "itertools", "load-cargo", diff --git a/src/tools/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/Cargo.toml index ce2d66000e39..35afbdd1b5c2 100644 --- a/src/tools/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/Cargo.toml @@ -117,7 +117,7 @@ expect-test = "1.4.0" hashbrown = { version = "0.14", features = [ "inline-more", ], default-features = false } -indexmap = "2.1.0" +indexmap = { version = "2.1.0", features = ["serde"] } itertools = "0.12.0" libc = "0.2.150" libloading = "0.8.0" diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml index 6c81c238fd3f..9d30c5d38eb4 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml @@ -25,6 +25,7 @@ crossbeam-channel.workspace = true dirs = "5.0.1" dissimilar.workspace = true ide-completion.workspace = true +indexmap.workspace = true itertools.workspace = true scip = "0.5.1" lsp-types = { version = "=0.95.0", features = ["proposed"] } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index 45ac68339b38..8d5440b85843 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -41,6 +41,8 @@ use crate::{ lsp_ext::{WorkspaceSymbolSearchKind, WorkspaceSymbolSearchScope}, }; +type FxIndexMap = indexmap::IndexMap; + mod patch_old_style; // Conventions for configuration keys to preserve maximal extendability without breakage: @@ -81,7 +83,7 @@ config_data! { cachePriming_numThreads: NumThreads = NumThreads::Physical, /// Custom completion snippets. - completion_snippets_custom: FxHashMap = Config::completion_snippets_default(), + completion_snippets_custom: FxIndexMap = Config::completion_snippets_default(), /// These paths (file/directories) will be ignored by rust-analyzer. They are @@ -931,7 +933,7 @@ impl Config { patch_old_style::patch_json_for_outdated_configs(&mut json); let mut json_errors = vec![]; - let snips = get_field_json::>( + let snips = get_field_json::>( &mut json, &mut json_errors, "completion_snippets_custom", @@ -2032,21 +2034,13 @@ impl Config { *self.cfg_setTest(source_root) } - pub(crate) fn completion_snippets_default() -> FxHashMap { + pub(crate) fn completion_snippets_default() -> FxIndexMap { serde_json::from_str( r#"{ - "Arc::new": { - "postfix": "arc", - "body": "Arc::new(${receiver})", - "requires": "std::sync::Arc", - "description": "Put the expression into an `Arc`", - "scope": "expr" - }, - "Rc::new": { - "postfix": "rc", - "body": "Rc::new(${receiver})", - "requires": "std::rc::Rc", - "description": "Put the expression into an `Rc`", + "Ok": { + "postfix": "ok", + "body": "Ok(${receiver})", + "description": "Wrap the expression in a `Result::Ok`", "scope": "expr" }, "Box::pin": { @@ -2056,10 +2050,17 @@ impl Config { "description": "Put the expression into a pinned `Box`", "scope": "expr" }, - "Ok": { - "postfix": "ok", - "body": "Ok(${receiver})", - "description": "Wrap the expression in a `Result::Ok`", + "Arc::new": { + "postfix": "arc", + "body": "Arc::new(${receiver})", + "requires": "std::sync::Arc", + "description": "Put the expression into an `Arc`", + "scope": "expr" + }, + "Some": { + "postfix": "some", + "body": "Some(${receiver})", + "description": "Wrap the expression in an `Option::Some`", "scope": "expr" }, "Err": { @@ -2068,10 +2069,11 @@ impl Config { "description": "Wrap the expression in a `Result::Err`", "scope": "expr" }, - "Some": { - "postfix": "some", - "body": "Some(${receiver})", - "description": "Wrap the expression in an `Option::Some`", + "Rc::new": { + "postfix": "rc", + "body": "Rc::new(${receiver})", + "requires": "std::rc::Rc", + "description": "Put the expression into an `Rc`", "scope": "expr" } }"#, @@ -3210,7 +3212,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json "FxHashMap, Box<[Box]>>" => set! { "type": "object", }, - "FxHashMap" => set! { + "FxIndexMap" => set! { "type": "object", }, "FxHashMap" => set! {