Repository: rust-analyzer/rust-analyzer
Pull request #5012 (2020-06-23 19:30:09)

Slightly better name


bors r+
🤖


Patch:
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs
index ca8a6a6509..a98264fb33 100644
--- a/crates/ra_ide/src/display/function_signature.rs
+++ b/crates/ra_ide/src/display/function_signature.rs
@@ -10,7 +10,7 @@ use std::{
 use hir::{Docs, Documentation, HasSource, HirDisplay};
 use ra_ide_db::RootDatabase;
 use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
-use stdx::{split1, SepBy};
+use stdx::{split_delim, SepBy};
 
 use crate::display::{generic_parameters, where_predicates};
 
@@ -210,7 +210,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
                 // macro-generated functions are missing whitespace
                 fn fmt_param(param: ast::Param) -> String {
                     let text = param.syntax().text().to_string();
-                    match split1(&text, ':') {
+                    match split_delim(&text, ':') {
                         Some((left, right)) => format!("{}: {}", left.trim(), right.trim()),
                         _ => text,
                     }
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index a44959abe7..221b902b2e 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -26,7 +26,7 @@ use ra_project_model::TargetKind;
 use ra_syntax::{AstNode, SyntaxKind, TextRange, TextSize};
 use serde::{Deserialize, Serialize};
 use serde_json::to_value;
-use stdx::{format_to, split1};
+use stdx::{format_to, split_delim};
 
 use crate::{
     cargo_target_spec::CargoTargetSpec,
@@ -785,7 +785,7 @@ pub fn handle_resolve_code_action(
     let frange = FileRange { file_id, range };
 
     let assists = snap.analysis().resolved_assists(&snap.config.assist, frange)?;
-    let (id_string, index) = split1(&params.id, ':').unwrap();
+    let (id_string, index) = split_delim(&params.id, ':').unwrap();
     let index = index.parse::<usize>().unwrap();
     let assist = &assists[index];
     assert!(assist.assist.id.0 == id_string);
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index f2ff0e4359..100db9d5db 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -124,7 +124,7 @@ pub fn replace(buf: &mut String, from: char, to: &str) {
     *buf = buf.replace(from, to)
 }
 
-pub fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {
+pub fn split_delim(haystack: &str, delim: char) -> Option<(&str, &str)> {
     let idx = haystack.find(delim)?;
     Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..]))
 }


Test patch:
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 9108e49d96..0cd51ab3ef 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -2,7 +2,7 @@
 //! rust-analyzer database from a single string.
 
 use rustc_hash::FxHashMap;
-use stdx::split1;
+use stdx::split_delim;
 
 #[derive(Debug, Eq, PartialEq)]
 pub struct Fixture {
@@ -81,14 +81,14 @@ The offending line: {:?}"#,
         let mut cfg_key_values = Vec::new();
         let mut env = FxHashMap::default();
         for component in components[1..].iter() {
-            let (key, value) = split1(component, ':').unwrap();
+            let (key, value) = split_delim(component, ':').unwrap();
             match key {
                 "crate" => krate = Some(value.to_string()),
                 "deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
                 "edition" => edition = Some(value.to_string()),
                 "cfg" => {
                     for entry in value.split(',') {
-                        match split1(entry, '=') {
+                        match split_delim(entry, '=') {
                             Some((k, v)) => cfg_key_values.push((k.to_string(), v.to_string())),
                             None => cfg_atoms.push(entry.to_string()),
                         }
@@ -96,7 +96,7 @@ The offending line: {:?}"#,
                 }
                 "env" => {
                     for key in value.split(',') {
-                        if let Some((k, v)) = split1(key, '=') {
+                        if let Some((k, v)) = split_delim(key, '=') {
                             env.insert(k.into(), v.into());
                         }
                     }