mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
Merge #6797
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:
commit
83aa6fbd1e
10 changed files with 44 additions and 43 deletions
|
@ -5,7 +5,7 @@
|
|||
//! assists if we are allowed to.
|
||||
|
||||
use hir::PrefixKind;
|
||||
use ide_db::helpers::insert_use::MergeBehaviour;
|
||||
use ide_db::helpers::insert_use::MergeBehavior;
|
||||
|
||||
use crate::AssistKind;
|
||||
|
||||
|
@ -39,12 +39,12 @@ impl Default for AssistConfig {
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct InsertUseConfig {
|
||||
pub merge: Option<MergeBehaviour>,
|
||||
pub merge: Option<MergeBehavior>,
|
||||
pub prefix_kind: PrefixKind,
|
||||
}
|
||||
|
||||
impl Default for InsertUseConfig {
|
||||
fn default() -> Self {
|
||||
InsertUseConfig { merge: Some(MergeBehaviour::Full), prefix_kind: PrefixKind::Plain }
|
||||
InsertUseConfig { merge: Some(MergeBehavior::Full), prefix_kind: PrefixKind::Plain }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::{
|
||||
algo::{neighbor, SyntaxRewriter},
|
||||
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) {
|
||||
let (merged, to_delete) =
|
||||
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);
|
||||
|
@ -42,7 +42,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
|
|||
} else {
|
||||
let (merged, to_delete) =
|
||||
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);
|
||||
|
|
|
@ -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() {
|
||||
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
|
||||
// (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.
|
||||
// Mimics the corresponding behaviour of the `Auto Import` feature.
|
||||
// It is possible to configure how use-trees are merged with the `importMergeBehavior` setting.
|
||||
// Mimics the corresponding behavior of the `Auto Import` feature.
|
||||
//
|
||||
// .LSP and performance implications
|
||||
//
|
||||
|
@ -150,7 +150,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
|
|||
ImportEdit {
|
||||
import_path: import_path.clone(),
|
||||
import_scope: import_scope.clone(),
|
||||
merge_behaviour: ctx.config.merge,
|
||||
merge_behavior: ctx.config.merge,
|
||||
},
|
||||
&definition,
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! module, and we use to statically check that we only produce snippet
|
||||
//! completions if we are allowed to.
|
||||
|
||||
use ide_db::helpers::insert_use::MergeBehaviour;
|
||||
use ide_db::helpers::insert_use::MergeBehavior;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -14,7 +14,7 @@ pub struct CompletionConfig {
|
|||
pub add_call_parenthesis: bool,
|
||||
pub add_call_argument_snippets: bool,
|
||||
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.
|
||||
pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>,
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ impl Default for CompletionConfig {
|
|||
add_call_parenthesis: true,
|
||||
add_call_argument_snippets: true,
|
||||
snippet_cap: Some(SnippetCap { _private: () }),
|
||||
merge: Some(MergeBehaviour::Full),
|
||||
merge: Some(MergeBehavior::Full),
|
||||
active_resolve_capabilities: FxHashSet::default(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt;
|
|||
|
||||
use hir::{Documentation, ModPath, Mutability};
|
||||
use ide_db::helpers::{
|
||||
insert_use::{self, ImportScope, MergeBehaviour},
|
||||
insert_use::{self, ImportScope, MergeBehavior},
|
||||
mod_path_to_ast,
|
||||
};
|
||||
use syntax::{algo, TextRange};
|
||||
|
@ -271,7 +271,7 @@ impl CompletionItem {
|
|||
pub struct ImportEdit {
|
||||
pub import_path: ModPath,
|
||||
pub import_scope: ImportScope,
|
||||
pub merge_behaviour: Option<MergeBehaviour>,
|
||||
pub merge_behavior: Option<MergeBehavior>,
|
||||
}
|
||||
|
||||
impl ImportEdit {
|
||||
|
@ -283,7 +283,7 @@ impl ImportEdit {
|
|||
let rewriter = insert_use::insert_use(
|
||||
&self.import_scope,
|
||||
mod_path_to_ast(&self.import_path),
|
||||
self.merge_behaviour,
|
||||
self.merge_behavior,
|
||||
);
|
||||
let old_ast = rewriter.rewrite_root()?;
|
||||
let mut import_insert = TextEdit::builder();
|
||||
|
|
|
@ -153,7 +153,7 @@ pub fn resolve_completion_edits(
|
|||
})
|
||||
.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()
|
||||
.map(|edit| vec![edit])
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ fn is_inner_comment(token: SyntaxToken) -> bool {
|
|||
pub fn insert_use<'a>(
|
||||
scope: &ImportScope,
|
||||
path: ast::Path,
|
||||
merge: Option<MergeBehaviour>,
|
||||
merge: Option<MergeBehavior>,
|
||||
) -> SyntaxRewriter<'a> {
|
||||
let _p = profile::span("insert_use");
|
||||
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(
|
||||
lhs: &ast::Use,
|
||||
rhs: &ast::Use,
|
||||
merge_behaviour: MergeBehaviour,
|
||||
merge_behavior: MergeBehavior,
|
||||
) -> Option<ast::Use> {
|
||||
// don't merge imports with different visibilities
|
||||
if !eq_visibility(lhs.visibility(), rhs.visibility()) {
|
||||
|
@ -191,14 +191,14 @@ pub fn try_merge_imports(
|
|||
}
|
||||
let lhs_tree = lhs.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))
|
||||
}
|
||||
|
||||
pub fn try_merge_trees(
|
||||
lhs: &ast::UseTree,
|
||||
rhs: &ast::UseTree,
|
||||
merge: MergeBehaviour,
|
||||
merge: MergeBehavior,
|
||||
) -> Option<ast::UseTree> {
|
||||
let lhs_path = lhs.path()?;
|
||||
let rhs_path = rhs.path()?;
|
||||
|
@ -220,7 +220,7 @@ pub fn try_merge_trees(
|
|||
fn recursive_merge(
|
||||
lhs: &ast::UseTree,
|
||||
rhs: &ast::UseTree,
|
||||
merge: MergeBehaviour,
|
||||
merge: MergeBehavior,
|
||||
) -> Option<ast::UseTree> {
|
||||
let mut use_trees = lhs
|
||||
.use_tree_list()
|
||||
|
@ -301,7 +301,7 @@ fn recursive_merge(
|
|||
}
|
||||
}
|
||||
Err(_)
|
||||
if merge == MergeBehaviour::Last
|
||||
if merge == MergeBehavior::Last
|
||||
&& use_trees.len() > 0
|
||||
&& 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.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum MergeBehaviour {
|
||||
pub enum MergeBehavior {
|
||||
/// Merge everything together creating deeply nested imports.
|
||||
Full,
|
||||
/// Only merge the last import level, doesn't allow import nesting.
|
||||
Last,
|
||||
}
|
||||
|
||||
impl MergeBehaviour {
|
||||
impl MergeBehavior {
|
||||
#[inline]
|
||||
fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool {
|
||||
match self {
|
||||
MergeBehaviour::Full => true,
|
||||
MergeBehavior::Full => true,
|
||||
// only simple single segment paths are allowed
|
||||
MergeBehaviour::Last => {
|
||||
MergeBehavior::Last => {
|
||||
tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -533,7 +533,7 @@ fn merge_last_fail() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::{baz::{Qux, Fez}};",
|
||||
r"use foo::bar::{baaz::{Quux, Feez}};",
|
||||
MergeBehaviour::Last,
|
||||
MergeBehavior::Last,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ fn merge_last_fail1() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::{baz::{Qux, Fez}};",
|
||||
r"use foo::bar::baaz::{Quux, Feez};",
|
||||
MergeBehaviour::Last,
|
||||
MergeBehavior::Last,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -551,7 +551,7 @@ fn merge_last_fail2() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::baz::{Qux, Fez};",
|
||||
r"use foo::bar::{baaz::{Quux, Feez}};",
|
||||
MergeBehaviour::Last,
|
||||
MergeBehavior::Last,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -560,7 +560,7 @@ fn merge_last_fail3() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::baz::{Qux, Fez};",
|
||||
r"use foo::bar::baaz::{Quux, Feez};",
|
||||
MergeBehaviour::Last,
|
||||
MergeBehavior::Last,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -568,7 +568,7 @@ fn check(
|
|||
path: &str,
|
||||
ra_fixture_before: &str,
|
||||
ra_fixture_after: &str,
|
||||
mb: Option<MergeBehaviour>,
|
||||
mb: Option<MergeBehavior>,
|
||||
module: bool,
|
||||
) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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)
|
||||
.tree()
|
||||
.syntax()
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::{convert::TryFrom, ffi::OsString, path::PathBuf};
|
|||
use flycheck::FlycheckConfig;
|
||||
use hir::PrefixKind;
|
||||
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 lsp_types::{ClientCapabilities, MarkupKind};
|
||||
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
|
||||
|
@ -25,7 +25,7 @@ use crate::{caps::enabled_completions_resolve_capabilities, diagnostics::Diagnos
|
|||
config_data! {
|
||||
struct ConfigData {
|
||||
/// 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.
|
||||
assist_importPrefix: ImportPrefixDef = "\"plain\"",
|
||||
|
||||
|
@ -447,9 +447,9 @@ impl Config {
|
|||
};
|
||||
|
||||
self.assist.insert_use.merge = match data.assist_importMergeBehaviour {
|
||||
MergeBehaviourDef::None => None,
|
||||
MergeBehaviourDef::Full => Some(MergeBehaviour::Full),
|
||||
MergeBehaviourDef::Last => Some(MergeBehaviour::Last),
|
||||
MergeBehaviorDef::None => None,
|
||||
MergeBehaviorDef::Full => Some(MergeBehavior::Full),
|
||||
MergeBehaviorDef::Last => Some(MergeBehavior::Last),
|
||||
};
|
||||
self.assist.insert_use.prefix_kind = match data.assist_importPrefix {
|
||||
ImportPrefixDef::Plain => PrefixKind::Plain,
|
||||
|
@ -606,7 +606,7 @@ enum ManifestOrProjectJson {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum MergeBehaviourDef {
|
||||
enum MergeBehaviorDef {
|
||||
None,
|
||||
Full,
|
||||
Last,
|
||||
|
@ -740,7 +740,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
|||
"type": ["null", "array"],
|
||||
"items": { "type": "string" },
|
||||
},
|
||||
"MergeBehaviourDef" => set! {
|
||||
"MergeBehaviorDef" => set! {
|
||||
"type": "string",
|
||||
"enum": ["none", "full", "last"],
|
||||
"enumDescriptions": [
|
||||
|
|
|
@ -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)).
|
||||
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`).
|
||||
Prefer American spelling (color, behavior).
|
||||
|
||||
Default names:
|
||||
|
||||
|
|
Loading…
Reference in a new issue