Skip to content

Commit c474ebb

Browse files
committed
use indexmap instead of BTreeMap for deterministic snippet output
1 parent 7b0c05d commit c474ebb

File tree

4 files changed

+48
-45
lines changed

4 files changed

+48
-45
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.

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ always-assert = "0.1.2"
5252
# in our transitive deps to prevent them from pulling in windows-sys 0.45.0
5353
mio = "=0.8.5"
5454
parking_lot_core = "=0.9.6"
55+
indexmap = { version = "2.0.0", features = ["serde"] }
5556

5657
cfg.workspace = true
5758
flycheck.workspace = true

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use ide_db::{
2222
imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
2323
SnippetCap,
2424
};
25+
use indexmap::IndexMap;
2526
use itertools::Itertools;
2627
use la_arena::Arena;
2728
use lsp_types::{ClientCapabilities, MarkupKind};
@@ -30,7 +31,6 @@ use project_model::{
3031
};
3132
use rustc_hash::{FxHashMap, FxHashSet};
3233
use serde::{de::DeserializeOwned, Deserialize, Serialize};
33-
use std::collections::BTreeMap;
3434
use toml;
3535
use vfs::{AbsPath, AbsPathBuf, FileId};
3636

@@ -384,8 +384,8 @@ config_data! {
384384
/// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
385385
completion_privateEditable_enable: bool = false,
386386
/// Custom completion snippets.
387-
// NOTE: we use BTreeMap for deterministic serialization ordering
388-
completion_snippets_custom: BTreeMap<String, SnippetDef> = @from_str: r#"{
387+
// NOTE: we use IndexMap for deterministic serialization ordering
388+
completion_snippets_custom: IndexMap<String, SnippetDef> = serde_json::from_str(r#"{
389389
"Arc::new": {
390390
"postfix": "arc",
391391
"body": "Arc::new(${receiver})",
@@ -425,7 +425,7 @@ config_data! {
425425
"description": "Wrap the expression in an `Option::Some`",
426426
"scope": "expr"
427427
}
428-
}"#,
428+
}"#).unwrap(),
429429

430430
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
431431
highlightRelated_breakPoints_enable: bool = true,
@@ -2560,7 +2560,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
25602560
"FxHashMap<Box<str>, Box<[Box<str>]>>" => set! {
25612561
"type": "object",
25622562
},
2563-
"BTreeMap<String, SnippetDef>" => set! {
2563+
"IndexMap<String, SnippetDef>" => set! {
25642564
"type": "object",
25652565
},
25662566
"FxHashMap<String, String>" => set! {

docs/user/generated_config.adoc

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -278,46 +278,46 @@ Enables completions of private items and fields that are defined in the current
278278
Default:
279279
----
280280
{
281-
"Arc::new": {
282-
"postfix": "arc",
283-
"body": "Arc::new(${receiver})",
284-
"requires": "std::sync::Arc",
285-
"description": "Put the expression into an `Arc`",
286-
"scope": "expr"
287-
},
288-
"Rc::new": {
289-
"postfix": "rc",
290-
"body": "Rc::new(${receiver})",
291-
"requires": "std::rc::Rc",
292-
"description": "Put the expression into an `Rc`",
293-
"scope": "expr"
294-
},
295-
"Box::pin": {
296-
"postfix": "pinbox",
297-
"body": "Box::pin(${receiver})",
298-
"requires": "std::boxed::Box",
299-
"description": "Put the expression into a pinned `Box`",
300-
"scope": "expr"
301-
},
302-
"Ok": {
303-
"postfix": "ok",
304-
"body": "Ok(${receiver})",
305-
"description": "Wrap the expression in a `Result::Ok`",
306-
"scope": "expr"
307-
},
308-
"Err": {
309-
"postfix": "err",
310-
"body": "Err(${receiver})",
311-
"description": "Wrap the expression in a `Result::Err`",
312-
"scope": "expr"
313-
},
314-
"Some": {
315-
"postfix": "some",
316-
"body": "Some(${receiver})",
317-
"description": "Wrap the expression in an `Option::Some`",
318-
"scope": "expr"
319-
}
320-
}
281+
"Arc::new": {
282+
"postfix": "arc",
283+
"body": "Arc::new(${receiver})",
284+
"requires": "std::sync::Arc",
285+
"description": "Put the expression into an `Arc`",
286+
"scope": "expr"
287+
},
288+
"Rc::new": {
289+
"postfix": "rc",
290+
"body": "Rc::new(${receiver})",
291+
"requires": "std::rc::Rc",
292+
"description": "Put the expression into an `Rc`",
293+
"scope": "expr"
294+
},
295+
"Box::pin": {
296+
"postfix": "pinbox",
297+
"body": "Box::pin(${receiver})",
298+
"requires": "std::boxed::Box",
299+
"description": "Put the expression into a pinned `Box`",
300+
"scope": "expr"
301+
},
302+
"Ok": {
303+
"postfix": "ok",
304+
"body": "Ok(${receiver})",
305+
"description": "Wrap the expression in a `Result::Ok`",
306+
"scope": "expr"
307+
},
308+
"Err": {
309+
"postfix": "err",
310+
"body": "Err(${receiver})",
311+
"description": "Wrap the expression in a `Result::Err`",
312+
"scope": "expr"
313+
},
314+
"Some": {
315+
"postfix": "some",
316+
"body": "Some(${receiver})",
317+
"description": "Wrap the expression in an `Option::Some`",
318+
"scope": "expr"
319+
}
320+
}
321321
----
322322
Custom completion snippets.
323323

0 commit comments

Comments
 (0)