diff options
| author | David Barsky <me@davidbarsky.com> | 2025-03-10 12:16:59 -0400 |
|---|---|---|
| committer | David Barsky <me@davidbarsky.com> | 2025-03-10 12:55:46 -0400 |
| commit | 83c1c4c2bb7c5744fe7e39869c941f52d54d80b7 (patch) | |
| tree | e18678638e27f244353da855d0630998229440cc | |
| parent | 5dfe55fb494f1d1efa8ea895de99bd697fe5b265 (diff) | |
| download | rust-83c1c4c2bb7c5744fe7e39869c941f52d54d80b7.tar.gz rust-83c1c4c2bb7c5744fe7e39869c941f52d54d80b7.zip | |
internal(config): use `FxIndexMap` for default completion snippets
| -rw-r--r-- | src/tools/rust-analyzer/Cargo.lock | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs | 50 |
4 files changed, 30 insertions, 25 deletions
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index 4e9b4f7e41b..a50e1e8f49a 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 ce2d66000e3..35afbdd1b5c 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 6c81c238fd3..9d30c5d38eb 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 45ac68339b3..8d5440b8584 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<K, V> = indexmap::IndexMap<K, V, rustc_hash::FxBuildHasher>; + 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<String, SnippetDef> = Config::completion_snippets_default(), + completion_snippets_custom: FxIndexMap<String, SnippetDef> = 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::<FxHashMap<String, SnippetDef>>( + let snips = get_field_json::<FxIndexMap<String, SnippetDef>>( &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<String, SnippetDef> { + pub(crate) fn completion_snippets_default() -> FxIndexMap<String, SnippetDef> { 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<str>, Box<[Box<str>]>>" => set! { "type": "object", }, - "FxHashMap<String, SnippetDef>" => set! { + "FxIndexMap<String, SnippetDef>" => set! { "type": "object", }, "FxHashMap<String, String>" => set! { |
