aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/helpers
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-12-10 14:41:57 +0000
committerAleksey Kladov <[email protected]>2020-12-10 14:51:56 +0000
commit17f236c2b041de7abd8ec3be208b8eff75fd7ffb (patch)
tree164ef144e07ed4f24c751355b735169878468789 /crates/ide_db/src/helpers
parent1341a98f0551edf3a445c40507ab1abb3d7c71bb (diff)
Normalize spelling to American English
Diffstat (limited to 'crates/ide_db/src/helpers')
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs20
-rw-r--r--crates/ide_db/src/helpers/insert_use/tests.rs16
2 files changed, 18 insertions, 18 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs
index 040843990..9be36d59b 100644
--- a/crates/ide_db/src/helpers/insert_use.rs
+++ b/crates/ide_db/src/helpers/insert_use.rs
@@ -93,7 +93,7 @@ fn is_inner_comment(token: SyntaxToken) -> bool {
93pub fn insert_use<'a>( 93pub fn insert_use<'a>(
94 scope: &ImportScope, 94 scope: &ImportScope,
95 path: ast::Path, 95 path: ast::Path,
96 merge: Option<MergeBehaviour>, 96 merge: Option<MergeBehavior>,
97) -> SyntaxRewriter<'a> { 97) -> SyntaxRewriter<'a> {
98 let _p = profile::span("insert_use"); 98 let _p = profile::span("insert_use");
99 let mut rewriter = SyntaxRewriter::default(); 99 let mut rewriter = SyntaxRewriter::default();
@@ -183,7 +183,7 @@ fn eq_visibility(vis0: Option<ast::Visibility>, vis1: Option<ast::Visibility>) -
183pub fn try_merge_imports( 183pub fn try_merge_imports(
184 lhs: &ast::Use, 184 lhs: &ast::Use,
185 rhs: &ast::Use, 185 rhs: &ast::Use,
186 merge_behaviour: MergeBehaviour, 186 merge_behavior: MergeBehavior,
187) -> Option<ast::Use> { 187) -> Option<ast::Use> {
188 // don't merge imports with different visibilities 188 // don't merge imports with different visibilities
189 if !eq_visibility(lhs.visibility(), rhs.visibility()) { 189 if !eq_visibility(lhs.visibility(), rhs.visibility()) {
@@ -191,14 +191,14 @@ pub fn try_merge_imports(
191 } 191 }
192 let lhs_tree = lhs.use_tree()?; 192 let lhs_tree = lhs.use_tree()?;
193 let rhs_tree = rhs.use_tree()?; 193 let rhs_tree = rhs.use_tree()?;
194 let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behaviour)?; 194 let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behavior)?;
195 Some(lhs.with_use_tree(merged)) 195 Some(lhs.with_use_tree(merged))
196} 196}
197 197
198pub fn try_merge_trees( 198pub fn try_merge_trees(
199 lhs: &ast::UseTree, 199 lhs: &ast::UseTree,
200 rhs: &ast::UseTree, 200 rhs: &ast::UseTree,
201 merge: MergeBehaviour, 201 merge: MergeBehavior,
202) -> Option<ast::UseTree> { 202) -> Option<ast::UseTree> {
203 let lhs_path = lhs.path()?; 203 let lhs_path = lhs.path()?;
204 let rhs_path = rhs.path()?; 204 let rhs_path = rhs.path()?;
@@ -220,7 +220,7 @@ pub fn try_merge_trees(
220fn recursive_merge( 220fn recursive_merge(
221 lhs: &ast::UseTree, 221 lhs: &ast::UseTree,
222 rhs: &ast::UseTree, 222 rhs: &ast::UseTree,
223 merge: MergeBehaviour, 223 merge: MergeBehavior,
224) -> Option<ast::UseTree> { 224) -> Option<ast::UseTree> {
225 let mut use_trees = lhs 225 let mut use_trees = lhs
226 .use_tree_list() 226 .use_tree_list()
@@ -301,7 +301,7 @@ fn recursive_merge(
301 } 301 }
302 } 302 }
303 Err(_) 303 Err(_)
304 if merge == MergeBehaviour::Last 304 if merge == MergeBehavior::Last
305 && use_trees.len() > 0 305 && use_trees.len() > 0
306 && rhs_t.use_tree_list().is_some() => 306 && rhs_t.use_tree_list().is_some() =>
307 { 307 {
@@ -438,20 +438,20 @@ fn path_segment_cmp(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
438 438
439/// What type of merges are allowed. 439/// What type of merges are allowed.
440#[derive(Copy, Clone, Debug, PartialEq, Eq)] 440#[derive(Copy, Clone, Debug, PartialEq, Eq)]
441pub enum MergeBehaviour { 441pub enum MergeBehavior {
442 /// Merge everything together creating deeply nested imports. 442 /// Merge everything together creating deeply nested imports.
443 Full, 443 Full,
444 /// Only merge the last import level, doesn't allow import nesting. 444 /// Only merge the last import level, doesn't allow import nesting.
445 Last, 445 Last,
446} 446}
447 447
448impl MergeBehaviour { 448impl MergeBehavior {
449 #[inline] 449 #[inline]
450 fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool { 450 fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool {
451 match self { 451 match self {
452 MergeBehaviour::Full => true, 452 MergeBehavior::Full => true,
453 // only simple single segment paths are allowed 453 // only simple single segment paths are allowed
454 MergeBehaviour::Last => { 454 MergeBehavior::Last => {
455 tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1) 455 tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1)
456 } 456 }
457 } 457 }
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs
index 86bfa5b41..9e194354e 100644
--- a/crates/ide_db/src/helpers/insert_use/tests.rs
+++ b/crates/ide_db/src/helpers/insert_use/tests.rs
@@ -533,7 +533,7 @@ fn merge_last_fail() {
533 check_merge_only_fail( 533 check_merge_only_fail(
534 r"use foo::bar::{baz::{Qux, Fez}};", 534 r"use foo::bar::{baz::{Qux, Fez}};",
535 r"use foo::bar::{baaz::{Quux, Feez}};", 535 r"use foo::bar::{baaz::{Quux, Feez}};",
536 MergeBehaviour::Last, 536 MergeBehavior::Last,
537 ); 537 );
538} 538}
539 539
@@ -542,7 +542,7 @@ fn merge_last_fail1() {
542 check_merge_only_fail( 542 check_merge_only_fail(
543 r"use foo::bar::{baz::{Qux, Fez}};", 543 r"use foo::bar::{baz::{Qux, Fez}};",
544 r"use foo::bar::baaz::{Quux, Feez};", 544 r"use foo::bar::baaz::{Quux, Feez};",
545 MergeBehaviour::Last, 545 MergeBehavior::Last,
546 ); 546 );
547} 547}
548 548
@@ -551,7 +551,7 @@ fn merge_last_fail2() {
551 check_merge_only_fail( 551 check_merge_only_fail(
552 r"use foo::bar::baz::{Qux, Fez};", 552 r"use foo::bar::baz::{Qux, Fez};",
553 r"use foo::bar::{baaz::{Quux, Feez}};", 553 r"use foo::bar::{baaz::{Quux, Feez}};",
554 MergeBehaviour::Last, 554 MergeBehavior::Last,
555 ); 555 );
556} 556}
557 557
@@ -560,7 +560,7 @@ fn merge_last_fail3() {
560 check_merge_only_fail( 560 check_merge_only_fail(
561 r"use foo::bar::baz::{Qux, Fez};", 561 r"use foo::bar::baz::{Qux, Fez};",
562 r"use foo::bar::baaz::{Quux, Feez};", 562 r"use foo::bar::baaz::{Quux, Feez};",
563 MergeBehaviour::Last, 563 MergeBehavior::Last,
564 ); 564 );
565} 565}
566 566
@@ -568,7 +568,7 @@ fn check(
568 path: &str, 568 path: &str,
569 ra_fixture_before: &str, 569 ra_fixture_before: &str,
570 ra_fixture_after: &str, 570 ra_fixture_after: &str,
571 mb: Option<MergeBehaviour>, 571 mb: Option<MergeBehavior>,
572 module: bool, 572 module: bool,
573) { 573) {
574 let mut syntax = ast::SourceFile::parse(ra_fixture_before).tree().syntax().clone(); 574 let mut syntax = ast::SourceFile::parse(ra_fixture_before).tree().syntax().clone();
@@ -589,18 +589,18 @@ fn check(
589} 589}
590 590
591fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 591fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
592 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Full), false) 592 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Full), false)
593} 593}
594 594
595fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 595fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
596 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Last), false) 596 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Last), false)
597} 597}
598 598
599fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 599fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
600 check(path, ra_fixture_before, ra_fixture_after, None, false) 600 check(path, ra_fixture_before, ra_fixture_after, None, false)
601} 601}
602 602
603fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehaviour) { 603fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehavior) {
604 let use0 = ast::SourceFile::parse(ra_fixture0) 604 let use0 = ast::SourceFile::parse(ra_fixture0)
605 .tree() 605 .tree()
606 .syntax() 606 .syntax()