6797: Normalize spelling to American English r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-12-10 14:53:59 +00:00 committed by GitHub
commit 83aa6fbd1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 43 deletions

View file

@ -5,7 +5,7 @@
//! assists if we are allowed to. //! assists if we are allowed to.
use hir::PrefixKind; use hir::PrefixKind;
use ide_db::helpers::insert_use::MergeBehaviour; use ide_db::helpers::insert_use::MergeBehavior;
use crate::AssistKind; use crate::AssistKind;
@ -39,12 +39,12 @@ impl Default for AssistConfig {
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct InsertUseConfig { pub struct InsertUseConfig {
pub merge: Option<MergeBehaviour>, pub merge: Option<MergeBehavior>,
pub prefix_kind: PrefixKind, pub prefix_kind: PrefixKind,
} }
impl Default for InsertUseConfig { impl Default for InsertUseConfig {
fn default() -> Self { fn default() -> Self {
InsertUseConfig { merge: Some(MergeBehaviour::Full), prefix_kind: PrefixKind::Plain } InsertUseConfig { merge: Some(MergeBehavior::Full), prefix_kind: PrefixKind::Plain }
} }
} }

View file

@ -1,4 +1,4 @@
use ide_db::helpers::insert_use::{try_merge_imports, try_merge_trees, MergeBehaviour}; use ide_db::helpers::insert_use::{try_merge_imports, try_merge_trees, MergeBehavior};
use syntax::{ use syntax::{
algo::{neighbor, SyntaxRewriter}, algo::{neighbor, SyntaxRewriter},
ast, AstNode, ast, AstNode,
@ -30,7 +30,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) { if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
let (merged, to_delete) = let (merged, to_delete) =
next_prev().filter_map(|dir| neighbor(&use_item, dir)).find_map(|use_item2| { next_prev().filter_map(|dir| neighbor(&use_item, dir)).find_map(|use_item2| {
try_merge_imports(&use_item, &use_item2, MergeBehaviour::Full).zip(Some(use_item2)) try_merge_imports(&use_item, &use_item2, MergeBehavior::Full).zip(Some(use_item2))
})?; })?;
rewriter.replace_ast(&use_item, &merged); rewriter.replace_ast(&use_item, &merged);
@ -42,7 +42,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
} else { } else {
let (merged, to_delete) = let (merged, to_delete) =
next_prev().filter_map(|dir| neighbor(&tree, dir)).find_map(|use_tree| { next_prev().filter_map(|dir| neighbor(&tree, dir)).find_map(|use_tree| {
try_merge_trees(&tree, &use_tree, MergeBehaviour::Full).zip(Some(use_tree)) try_merge_trees(&tree, &use_tree, MergeBehavior::Full).zip(Some(use_tree))
})?; })?;
rewriter.replace_ast(&tree, &merged); rewriter.replace_ast(&tree, &merged);

View file

@ -45,7 +45,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
}); });
if ctx.config.enable_autoimport_completions && ctx.config.resolve_additional_edits_lazily() { if ctx.config.enable_autoimport_completions && ctx.config.resolve_additional_edits_lazily() {
fuzzy_completion(acc, ctx).unwrap_or_default() fuzzy_completion(acc, ctx);
} }
} }
@ -100,10 +100,10 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only // To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only
// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers. // (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers.
// //
// .Merge Behaviour // .Merge Behavior
// //
// It is possible to configure how use-trees are merged with the `importMergeBehaviour` setting. // It is possible to configure how use-trees are merged with the `importMergeBehavior` setting.
// Mimics the corresponding behaviour of the `Auto Import` feature. // Mimics the corresponding behavior of the `Auto Import` feature.
// //
// .LSP and performance implications // .LSP and performance implications
// //
@ -150,7 +150,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
ImportEdit { ImportEdit {
import_path: import_path.clone(), import_path: import_path.clone(),
import_scope: import_scope.clone(), import_scope: import_scope.clone(),
merge_behaviour: ctx.config.merge, merge_behavior: ctx.config.merge,
}, },
&definition, &definition,
) )

View file

@ -4,7 +4,7 @@
//! module, and we use to statically check that we only produce snippet //! module, and we use to statically check that we only produce snippet
//! completions if we are allowed to. //! completions if we are allowed to.
use ide_db::helpers::insert_use::MergeBehaviour; use ide_db::helpers::insert_use::MergeBehavior;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
@ -14,7 +14,7 @@ pub struct CompletionConfig {
pub add_call_parenthesis: bool, pub add_call_parenthesis: bool,
pub add_call_argument_snippets: bool, pub add_call_argument_snippets: bool,
pub snippet_cap: Option<SnippetCap>, pub snippet_cap: Option<SnippetCap>,
pub merge: Option<MergeBehaviour>, pub merge: Option<MergeBehavior>,
/// A set of capabilities, enabled on the client and supported on the server. /// A set of capabilities, enabled on the client and supported on the server.
pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>, pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>,
} }
@ -56,7 +56,7 @@ impl Default for CompletionConfig {
add_call_parenthesis: true, add_call_parenthesis: true,
add_call_argument_snippets: true, add_call_argument_snippets: true,
snippet_cap: Some(SnippetCap { _private: () }), snippet_cap: Some(SnippetCap { _private: () }),
merge: Some(MergeBehaviour::Full), merge: Some(MergeBehavior::Full),
active_resolve_capabilities: FxHashSet::default(), active_resolve_capabilities: FxHashSet::default(),
} }
} }

View file

@ -4,7 +4,7 @@ use std::fmt;
use hir::{Documentation, ModPath, Mutability}; use hir::{Documentation, ModPath, Mutability};
use ide_db::helpers::{ use ide_db::helpers::{
insert_use::{self, ImportScope, MergeBehaviour}, insert_use::{self, ImportScope, MergeBehavior},
mod_path_to_ast, mod_path_to_ast,
}; };
use syntax::{algo, TextRange}; use syntax::{algo, TextRange};
@ -271,7 +271,7 @@ impl CompletionItem {
pub struct ImportEdit { pub struct ImportEdit {
pub import_path: ModPath, pub import_path: ModPath,
pub import_scope: ImportScope, pub import_scope: ImportScope,
pub merge_behaviour: Option<MergeBehaviour>, pub merge_behavior: Option<MergeBehavior>,
} }
impl ImportEdit { impl ImportEdit {
@ -283,7 +283,7 @@ impl ImportEdit {
let rewriter = insert_use::insert_use( let rewriter = insert_use::insert_use(
&self.import_scope, &self.import_scope,
mod_path_to_ast(&self.import_path), mod_path_to_ast(&self.import_path),
self.merge_behaviour, self.merge_behavior,
); );
let old_ast = rewriter.rewrite_root()?; let old_ast = rewriter.rewrite_root()?;
let mut import_insert = TextEdit::builder(); let mut import_insert = TextEdit::builder();

View file

@ -153,7 +153,7 @@ pub fn resolve_completion_edits(
}) })
.find(|mod_path| mod_path.to_string() == full_import_path)?; .find(|mod_path| mod_path.to_string() == full_import_path)?;
ImportEdit { import_path, import_scope, merge_behaviour: config.merge } ImportEdit { import_path, import_scope, merge_behavior: config.merge }
.to_text_edit() .to_text_edit()
.map(|edit| vec![edit]) .map(|edit| vec![edit])
} }

View file

@ -93,7 +93,7 @@ fn is_inner_comment(token: SyntaxToken) -> bool {
pub fn insert_use<'a>( pub fn insert_use<'a>(
scope: &ImportScope, scope: &ImportScope,
path: ast::Path, path: ast::Path,
merge: Option<MergeBehaviour>, merge: Option<MergeBehavior>,
) -> SyntaxRewriter<'a> { ) -> SyntaxRewriter<'a> {
let _p = profile::span("insert_use"); let _p = profile::span("insert_use");
let mut rewriter = SyntaxRewriter::default(); let mut rewriter = SyntaxRewriter::default();
@ -183,7 +183,7 @@ fn eq_visibility(vis0: Option<ast::Visibility>, vis1: Option<ast::Visibility>) -
pub fn try_merge_imports( pub fn try_merge_imports(
lhs: &ast::Use, lhs: &ast::Use,
rhs: &ast::Use, rhs: &ast::Use,
merge_behaviour: MergeBehaviour, merge_behavior: MergeBehavior,
) -> Option<ast::Use> { ) -> Option<ast::Use> {
// don't merge imports with different visibilities // don't merge imports with different visibilities
if !eq_visibility(lhs.visibility(), rhs.visibility()) { if !eq_visibility(lhs.visibility(), rhs.visibility()) {
@ -191,14 +191,14 @@ pub fn try_merge_imports(
} }
let lhs_tree = lhs.use_tree()?; let lhs_tree = lhs.use_tree()?;
let rhs_tree = rhs.use_tree()?; let rhs_tree = rhs.use_tree()?;
let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behaviour)?; let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behavior)?;
Some(lhs.with_use_tree(merged)) Some(lhs.with_use_tree(merged))
} }
pub fn try_merge_trees( pub fn try_merge_trees(
lhs: &ast::UseTree, lhs: &ast::UseTree,
rhs: &ast::UseTree, rhs: &ast::UseTree,
merge: MergeBehaviour, merge: MergeBehavior,
) -> Option<ast::UseTree> { ) -> Option<ast::UseTree> {
let lhs_path = lhs.path()?; let lhs_path = lhs.path()?;
let rhs_path = rhs.path()?; let rhs_path = rhs.path()?;
@ -220,7 +220,7 @@ pub fn try_merge_trees(
fn recursive_merge( fn recursive_merge(
lhs: &ast::UseTree, lhs: &ast::UseTree,
rhs: &ast::UseTree, rhs: &ast::UseTree,
merge: MergeBehaviour, merge: MergeBehavior,
) -> Option<ast::UseTree> { ) -> Option<ast::UseTree> {
let mut use_trees = lhs let mut use_trees = lhs
.use_tree_list() .use_tree_list()
@ -301,7 +301,7 @@ fn recursive_merge(
} }
} }
Err(_) Err(_)
if merge == MergeBehaviour::Last if merge == MergeBehavior::Last
&& use_trees.len() > 0 && use_trees.len() > 0
&& rhs_t.use_tree_list().is_some() => && rhs_t.use_tree_list().is_some() =>
{ {
@ -438,20 +438,20 @@ fn path_segment_cmp(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
/// What type of merges are allowed. /// What type of merges are allowed.
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum MergeBehaviour { pub enum MergeBehavior {
/// Merge everything together creating deeply nested imports. /// Merge everything together creating deeply nested imports.
Full, Full,
/// Only merge the last import level, doesn't allow import nesting. /// Only merge the last import level, doesn't allow import nesting.
Last, Last,
} }
impl MergeBehaviour { impl MergeBehavior {
#[inline] #[inline]
fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool { fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool {
match self { match self {
MergeBehaviour::Full => true, MergeBehavior::Full => true,
// only simple single segment paths are allowed // only simple single segment paths are allowed
MergeBehaviour::Last => { MergeBehavior::Last => {
tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1) tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1)
} }
} }

View file

@ -533,7 +533,7 @@ fn merge_last_fail() {
check_merge_only_fail( check_merge_only_fail(
r"use foo::bar::{baz::{Qux, Fez}};", r"use foo::bar::{baz::{Qux, Fez}};",
r"use foo::bar::{baaz::{Quux, Feez}};", r"use foo::bar::{baaz::{Quux, Feez}};",
MergeBehaviour::Last, MergeBehavior::Last,
); );
} }
@ -542,7 +542,7 @@ fn merge_last_fail1() {
check_merge_only_fail( check_merge_only_fail(
r"use foo::bar::{baz::{Qux, Fez}};", r"use foo::bar::{baz::{Qux, Fez}};",
r"use foo::bar::baaz::{Quux, Feez};", r"use foo::bar::baaz::{Quux, Feez};",
MergeBehaviour::Last, MergeBehavior::Last,
); );
} }
@ -551,7 +551,7 @@ fn merge_last_fail2() {
check_merge_only_fail( check_merge_only_fail(
r"use foo::bar::baz::{Qux, Fez};", r"use foo::bar::baz::{Qux, Fez};",
r"use foo::bar::{baaz::{Quux, Feez}};", r"use foo::bar::{baaz::{Quux, Feez}};",
MergeBehaviour::Last, MergeBehavior::Last,
); );
} }
@ -560,7 +560,7 @@ fn merge_last_fail3() {
check_merge_only_fail( check_merge_only_fail(
r"use foo::bar::baz::{Qux, Fez};", r"use foo::bar::baz::{Qux, Fez};",
r"use foo::bar::baaz::{Quux, Feez};", r"use foo::bar::baaz::{Quux, Feez};",
MergeBehaviour::Last, MergeBehavior::Last,
); );
} }
@ -568,7 +568,7 @@ fn check(
path: &str, path: &str,
ra_fixture_before: &str, ra_fixture_before: &str,
ra_fixture_after: &str, ra_fixture_after: &str,
mb: Option<MergeBehaviour>, mb: Option<MergeBehavior>,
module: bool, module: bool,
) { ) {
let mut syntax = ast::SourceFile::parse(ra_fixture_before).tree().syntax().clone(); let mut syntax = ast::SourceFile::parse(ra_fixture_before).tree().syntax().clone();
@ -589,18 +589,18 @@ fn check(
} }
fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Full), false) check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Full), false)
} }
fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Last), false) check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Last), false)
} }
fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
check(path, ra_fixture_before, ra_fixture_after, None, false) check(path, ra_fixture_before, ra_fixture_after, None, false)
} }
fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehaviour) { fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehavior) {
let use0 = ast::SourceFile::parse(ra_fixture0) let use0 = ast::SourceFile::parse(ra_fixture0)
.tree() .tree()
.syntax() .syntax()

View file

@ -12,7 +12,7 @@ use std::{convert::TryFrom, ffi::OsString, path::PathBuf};
use flycheck::FlycheckConfig; use flycheck::FlycheckConfig;
use hir::PrefixKind; use hir::PrefixKind;
use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig}; use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig};
use ide_db::helpers::insert_use::MergeBehaviour; use ide_db::helpers::insert_use::MergeBehavior;
use itertools::Itertools; use itertools::Itertools;
use lsp_types::{ClientCapabilities, MarkupKind}; use lsp_types::{ClientCapabilities, MarkupKind};
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
@ -25,7 +25,7 @@ use crate::{caps::enabled_completions_resolve_capabilities, diagnostics::Diagnos
config_data! { config_data! {
struct ConfigData { struct ConfigData {
/// The strategy to use when inserting new imports or merging imports. /// The strategy to use when inserting new imports or merging imports.
assist_importMergeBehaviour: MergeBehaviourDef = "\"full\"", assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"",
/// The path structure for newly inserted paths to use. /// The path structure for newly inserted paths to use.
assist_importPrefix: ImportPrefixDef = "\"plain\"", assist_importPrefix: ImportPrefixDef = "\"plain\"",
@ -447,9 +447,9 @@ impl Config {
}; };
self.assist.insert_use.merge = match data.assist_importMergeBehaviour { self.assist.insert_use.merge = match data.assist_importMergeBehaviour {
MergeBehaviourDef::None => None, MergeBehaviorDef::None => None,
MergeBehaviourDef::Full => Some(MergeBehaviour::Full), MergeBehaviorDef::Full => Some(MergeBehavior::Full),
MergeBehaviourDef::Last => Some(MergeBehaviour::Last), MergeBehaviorDef::Last => Some(MergeBehavior::Last),
}; };
self.assist.insert_use.prefix_kind = match data.assist_importPrefix { self.assist.insert_use.prefix_kind = match data.assist_importPrefix {
ImportPrefixDef::Plain => PrefixKind::Plain, ImportPrefixDef::Plain => PrefixKind::Plain,
@ -606,7 +606,7 @@ enum ManifestOrProjectJson {
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
enum MergeBehaviourDef { enum MergeBehaviorDef {
None, None,
Full, Full,
Last, Last,
@ -740,7 +740,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"type": ["null", "array"], "type": ["null", "array"],
"items": { "type": "string" }, "items": { "type": "string" },
}, },
"MergeBehaviourDef" => set! { "MergeBehaviorDef" => set! {
"type": "string", "type": "string",
"enum": ["none", "full", "last"], "enum": ["none", "full", "last"],
"enumDescriptions": [ "enumDescriptions": [

View file

@ -514,6 +514,7 @@ impl Parent {
Use boring and long names for local variables ([yay code completion](https://github.com/rust-analyzer/rust-analyzer/pull/4162#discussion_r417130973)). Use boring and long names for local variables ([yay code completion](https://github.com/rust-analyzer/rust-analyzer/pull/4162#discussion_r417130973)).
The default name is a lowercased name of the type: `global_state: GlobalState`. The default name is a lowercased name of the type: `global_state: GlobalState`.
Avoid ad-hoc acronyms and contractions, but use the ones that exist consistently (`db`, `ctx`, `acc`). Avoid ad-hoc acronyms and contractions, but use the ones that exist consistently (`db`, `ctx`, `acc`).
Prefer American spelling (color, behavior).
Default names: Default names: