Skip to content

Commit 394374e

Browse files
committed
internal(config): use FxIndexMap for default completion snippets
1 parent 7368212 commit 394374e

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ expect-test = "1.4.0"
117117
hashbrown = { version = "0.14", features = [
118118
"inline-more",
119119
], default-features = false }
120-
indexmap = "2.1.0"
120+
indexmap = { version = "2.1.0", features = ["serde"] }
121121
itertools = "0.12.0"
122122
libc = "0.2.150"
123123
libloading = "0.8.0"

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ crossbeam-channel.workspace = true
2525
dirs = "5.0.1"
2626
dissimilar.workspace = true
2727
ide-completion.workspace = true
28+
indexmap.workspace = true
2829
itertools.workspace = true
2930
scip = "0.5.1"
3031
lsp-types = { version = "=0.95.0", features = ["proposed"] }

crates/rust-analyzer/src/config.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ use crate::{
4141
lsp_ext::{WorkspaceSymbolSearchKind, WorkspaceSymbolSearchScope},
4242
};
4343

44+
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, rustc_hash::FxBuildHasher>;
45+
4446
mod patch_old_style;
4547

4648
// Conventions for configuration keys to preserve maximal extendability without breakage:
@@ -81,7 +83,7 @@ config_data! {
8183
cachePriming_numThreads: NumThreads = NumThreads::Physical,
8284

8385
/// Custom completion snippets.
84-
completion_snippets_custom: FxHashMap<String, SnippetDef> = Config::completion_snippets_default(),
86+
completion_snippets_custom: FxIndexMap<String, SnippetDef> = Config::completion_snippets_default(),
8587

8688

8789
/// These paths (file/directories) will be ignored by rust-analyzer. They are
@@ -931,7 +933,7 @@ impl Config {
931933
patch_old_style::patch_json_for_outdated_configs(&mut json);
932934

933935
let mut json_errors = vec![];
934-
let snips = get_field_json::<FxHashMap<String, SnippetDef>>(
936+
let snips = get_field_json::<FxIndexMap<String, SnippetDef>>(
935937
&mut json,
936938
&mut json_errors,
937939
"completion_snippets_custom",
@@ -2032,21 +2034,13 @@ impl Config {
20322034
*self.cfg_setTest(source_root)
20332035
}
20342036

2035-
pub(crate) fn completion_snippets_default() -> FxHashMap<String, SnippetDef> {
2037+
pub(crate) fn completion_snippets_default() -> FxIndexMap<String, SnippetDef> {
20362038
serde_json::from_str(
20372039
r#"{
2038-
"Arc::new": {
2039-
"postfix": "arc",
2040-
"body": "Arc::new(${receiver})",
2041-
"requires": "std::sync::Arc",
2042-
"description": "Put the expression into an `Arc`",
2043-
"scope": "expr"
2044-
},
2045-
"Rc::new": {
2046-
"postfix": "rc",
2047-
"body": "Rc::new(${receiver})",
2048-
"requires": "std::rc::Rc",
2049-
"description": "Put the expression into an `Rc`",
2040+
"Ok": {
2041+
"postfix": "ok",
2042+
"body": "Ok(${receiver})",
2043+
"description": "Wrap the expression in a `Result::Ok`",
20502044
"scope": "expr"
20512045
},
20522046
"Box::pin": {
@@ -2056,10 +2050,17 @@ impl Config {
20562050
"description": "Put the expression into a pinned `Box`",
20572051
"scope": "expr"
20582052
},
2059-
"Ok": {
2060-
"postfix": "ok",
2061-
"body": "Ok(${receiver})",
2062-
"description": "Wrap the expression in a `Result::Ok`",
2053+
"Arc::new": {
2054+
"postfix": "arc",
2055+
"body": "Arc::new(${receiver})",
2056+
"requires": "std::sync::Arc",
2057+
"description": "Put the expression into an `Arc`",
2058+
"scope": "expr"
2059+
},
2060+
"Some": {
2061+
"postfix": "some",
2062+
"body": "Some(${receiver})",
2063+
"description": "Wrap the expression in an `Option::Some`",
20632064
"scope": "expr"
20642065
},
20652066
"Err": {
@@ -2068,10 +2069,11 @@ impl Config {
20682069
"description": "Wrap the expression in a `Result::Err`",
20692070
"scope": "expr"
20702071
},
2071-
"Some": {
2072-
"postfix": "some",
2073-
"body": "Some(${receiver})",
2074-
"description": "Wrap the expression in an `Option::Some`",
2072+
"Rc::new": {
2073+
"postfix": "rc",
2074+
"body": "Rc::new(${receiver})",
2075+
"requires": "std::rc::Rc",
2076+
"description": "Put the expression into an `Rc`",
20752077
"scope": "expr"
20762078
}
20772079
}"#,
@@ -3210,7 +3212,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
32103212
"FxHashMap<Box<str>, Box<[Box<str>]>>" => set! {
32113213
"type": "object",
32123214
},
3213-
"FxHashMap<String, SnippetDef>" => set! {
3215+
"FxIndexMap<String, SnippetDef>" => set! {
32143216
"type": "object",
32153217
},
32163218
"FxHashMap<String, String>" => set! {

0 commit comments

Comments
 (0)