Unnamed repository; edit this file 'description' to name the repository.
internal(config): use `FxIndexMap` for default completion snippets
David Barsky 2025-03-10
parent 7368212 · commit 394374e
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--crates/rust-analyzer/Cargo.toml1
-rw-r--r--crates/rust-analyzer/src/config.rs50
4 files changed, 30 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4e9b4f7e41..a50e1e8f49 100644
--- a/Cargo.lock
+++ b/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/Cargo.toml b/Cargo.toml
index ce2d66000e..35afbdd1b5 100644
--- a/Cargo.toml
+++ b/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/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 6c81c238fd..9d30c5d38e 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/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/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 45ac68339b..8d5440b858 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/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! {