From 569f47e427e0b9181075291c988446b86c5ba8f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Mar 2020 16:02:55 +0200 Subject: Better names for config structs --- crates/ra_ide/src/completion.rs | 10 ++-- crates/ra_ide/src/completion/complete_postfix.rs | 2 +- crates/ra_ide/src/completion/completion_context.rs | 8 +-- crates/ra_ide/src/completion/presentation.rs | 12 ++-- crates/ra_ide/src/completion/test_utils.rs | 6 +- crates/ra_ide/src/inlay_hints.rs | 68 +++++++++++----------- crates/ra_ide/src/lib.rs | 12 ++-- 7 files changed, 59 insertions(+), 59 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index cd0757be5..b683572fb 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs @@ -34,15 +34,15 @@ pub use crate::completion::completion_item::{ }; #[derive(Clone, Debug, PartialEq, Eq)] -pub struct CompletionOptions { +pub struct CompletionConfig { pub enable_postfix_completions: bool, pub add_call_parenthesis: bool, pub add_call_argument_snippets: bool, } -impl Default for CompletionOptions { +impl Default for CompletionConfig { fn default() -> Self { - CompletionOptions { + CompletionConfig { enable_postfix_completions: true, add_call_parenthesis: true, add_call_argument_snippets: true, @@ -75,9 +75,9 @@ impl Default for CompletionOptions { pub(crate) fn completions( db: &RootDatabase, position: FilePosition, - options: &CompletionOptions, + config: &CompletionConfig, ) -> Option { - let ctx = CompletionContext::new(db, position, options)?; + let ctx = CompletionContext::new(db, position, config)?; let mut acc = Completions::default(); diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index 0a00054b2..29c2881c6 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs @@ -15,7 +15,7 @@ use crate::{ }; pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.options.enable_postfix_completions { + if !ctx.config.enable_postfix_completions { return; } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 319e33b61..fdc0da2c5 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -11,7 +11,7 @@ use ra_syntax::{ }; use ra_text_edit::AtomTextEdit; -use crate::{completion::CompletionOptions, FilePosition}; +use crate::{completion::CompletionConfig, FilePosition}; /// `CompletionContext` is created early during completion to figure out, where /// exactly is the cursor, syntax-wise. @@ -19,7 +19,7 @@ use crate::{completion::CompletionOptions, FilePosition}; pub(crate) struct CompletionContext<'a> { pub(super) sema: Semantics<'a, RootDatabase>, pub(super) db: &'a RootDatabase, - pub(super) options: &'a CompletionOptions, + pub(super) config: &'a CompletionConfig, pub(super) offset: TextUnit, /// The token before the cursor, in the original file. pub(super) original_token: SyntaxToken, @@ -61,7 +61,7 @@ impl<'a> CompletionContext<'a> { pub(super) fn new( db: &'a RootDatabase, position: FilePosition, - options: &'a CompletionOptions, + config: &'a CompletionConfig, ) -> Option> { let sema = Semantics::new(db); @@ -85,7 +85,7 @@ impl<'a> CompletionContext<'a> { let mut ctx = CompletionContext { sema, db, - options, + config, original_token, token, offset: position.offset, diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 60f1b83f3..1c7c0924d 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -106,7 +106,7 @@ impl Completions { }; // Add `<>` for generic types - if ctx.is_path_type && !ctx.has_type_args && ctx.options.add_call_parenthesis { + if ctx.is_path_type && !ctx.has_type_args && ctx.config.add_call_parenthesis { let has_non_default_type_params = match resolution { ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db), ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db), @@ -211,14 +211,14 @@ impl Completions { .detail(function_signature.to_string()); // If not an import, add parenthesis automatically. - if ctx.use_item_syntax.is_none() && !ctx.is_call && ctx.options.add_call_parenthesis { + if ctx.use_item_syntax.is_none() && !ctx.is_call && ctx.config.add_call_parenthesis { tested_by!(inserts_parens_for_function_calls); let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { (format!("{}()$0", name), format!("{}()", name)) } else { builder = builder.trigger_call_info(); - let snippet = if ctx.options.add_call_argument_snippets { + let snippet = if ctx.config.add_call_argument_snippets { let to_skip = if has_self_param { 1 } else { 0 }; let function_params_snippet = function_signature .parameter_names @@ -311,7 +311,7 @@ mod tests { use crate::completion::{ test_utils::{do_completion, do_completion_with_options}, - CompletionItem, CompletionKind, CompletionOptions, + CompletionConfig, CompletionItem, CompletionKind, }; fn do_reference_completion(ra_fixture: &str) -> Vec { @@ -320,7 +320,7 @@ mod tests { fn do_reference_completion_with_options( ra_fixture: &str, - options: CompletionOptions, + options: CompletionConfig, ) -> Vec { do_completion_with_options(ra_fixture, CompletionKind::Reference, &options) } @@ -589,7 +589,7 @@ mod tests { s.f<|> } ", - CompletionOptions { + CompletionConfig { add_call_argument_snippets: false, .. Default::default() } diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index 136857315..eb90b5279 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs @@ -1,19 +1,19 @@ //! Runs completion for testing purposes. use crate::{ - completion::{completion_item::CompletionKind, CompletionOptions}, + completion::{completion_item::CompletionKind, CompletionConfig}, mock_analysis::{analysis_and_position, single_file_with_position}, CompletionItem, }; pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { - do_completion_with_options(code, kind, &CompletionOptions::default()) + do_completion_with_options(code, kind, &CompletionConfig::default()) } pub(crate) fn do_completion_with_options( code: &str, kind: CompletionKind, - options: &CompletionOptions, + options: &CompletionConfig, ) -> Vec { let (analysis, position) = if code.contains("//-") { analysis_and_position(code) diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index f4f0751c0..d06fc03d3 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -11,14 +11,14 @@ use ra_syntax::{ use crate::{FileId, FunctionSignature}; #[derive(Clone, Debug, PartialEq, Eq)] -pub struct InlayHintsOptions { +pub struct InlayHintsConfig { pub type_hints: bool, pub parameter_hints: bool, pub chaining_hints: bool, pub max_length: Option, } -impl Default for InlayHintsOptions { +impl Default for InlayHintsConfig { fn default() -> Self { Self { type_hints: true, parameter_hints: true, chaining_hints: true, max_length: None } } @@ -41,7 +41,7 @@ pub struct InlayHint { pub(crate) fn inlay_hints( db: &RootDatabase, file_id: FileId, - options: &InlayHintsOptions, + config: &InlayHintsConfig, ) -> Vec { let _p = profile("inlay_hints"); let sema = Semantics::new(db); @@ -50,14 +50,14 @@ pub(crate) fn inlay_hints( let mut res = Vec::new(); for node in file.syntax().descendants() { if let Some(expr) = ast::Expr::cast(node.clone()) { - get_chaining_hints(&mut res, &sema, options, expr); + get_chaining_hints(&mut res, &sema, config, expr); } match_ast! { match node { - ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, options, ast::Expr::from(it)); }, - ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, options, ast::Expr::from(it)); }, - ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, options, it); }, + ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, + ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, + ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); }, _ => (), } } @@ -68,10 +68,10 @@ pub(crate) fn inlay_hints( fn get_chaining_hints( acc: &mut Vec, sema: &Semantics, - options: &InlayHintsOptions, + config: &InlayHintsConfig, expr: ast::Expr, ) -> Option<()> { - if !options.chaining_hints { + if !config.chaining_hints { return None; } @@ -95,7 +95,7 @@ fn get_chaining_hints( let next = tokens.next()?.kind(); let next_next = tokens.next()?.kind(); if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT { - let label = ty.display_truncated(sema.db, options.max_length).to_string(); + let label = ty.display_truncated(sema.db, config.max_length).to_string(); acc.push(InlayHint { range: expr.syntax().text_range(), kind: InlayKind::ChainingHint, @@ -108,10 +108,10 @@ fn get_chaining_hints( fn get_param_name_hints( acc: &mut Vec, sema: &Semantics, - options: &InlayHintsOptions, + config: &InlayHintsConfig, expr: ast::Expr, ) -> Option<()> { - if !options.parameter_hints { + if !config.parameter_hints { return None; } @@ -148,10 +148,10 @@ fn get_param_name_hints( fn get_bind_pat_hints( acc: &mut Vec, sema: &Semantics, - options: &InlayHintsOptions, + config: &InlayHintsConfig, pat: ast::BindPat, ) -> Option<()> { - if !options.type_hints { + if !config.type_hints { return None; } @@ -164,7 +164,7 @@ fn get_bind_pat_hints( acc.push(InlayHint { range: pat.syntax().text_range(), kind: InlayKind::TypeHint, - label: ty.display_truncated(sema.db, options.max_length).to_string().into(), + label: ty.display_truncated(sema.db, config.max_length).to_string().into(), }); Some(()) } @@ -270,7 +270,7 @@ fn get_fn_signature(sema: &Semantics, expr: &ast::Expr) -> Option< #[cfg(test)] mod tests { - use crate::inlay_hints::InlayHintsOptions; + use crate::inlay_hints::InlayHintsConfig; use insta::assert_debug_snapshot; use crate::mock_analysis::single_file; @@ -284,7 +284,7 @@ mod tests { let _x = foo(4, 4); }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" [ InlayHint { range: [106; 107), @@ -308,7 +308,7 @@ mod tests { let _x = foo(4, 4); }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ type_hints: false, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"[]"###); + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: false, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"[]"###); } #[test] @@ -320,7 +320,7 @@ mod tests { let _x = foo(4, 4); }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" [ InlayHint { range: [97; 99), @@ -344,7 +344,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [69; 71), @@ -401,7 +401,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [193; 197), @@ -481,7 +481,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [21; 30), @@ -545,7 +545,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [21; 30), @@ -595,7 +595,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [188; 192), @@ -690,7 +690,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [188; 192), @@ -785,7 +785,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [252; 256), @@ -857,7 +857,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" [ InlayHint { range: [74; 75), @@ -945,7 +945,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" [ InlayHint { range: [798; 809), @@ -1067,7 +1067,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" [] "### ); @@ -1093,7 +1093,7 @@ fn main() { }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" [] "### ); @@ -1115,7 +1115,7 @@ fn main() { .into_c(); }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" [ InlayHint { range: [232; 269), @@ -1144,7 +1144,7 @@ fn main() { let c = A(B(C)).into_b().into_c(); }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"[]"###); + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"[]"###); } #[test] @@ -1162,7 +1162,7 @@ fn main() { .0; }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" [ InlayHint { range: [150; 221), @@ -1204,7 +1204,7 @@ fn main() { .into_c(); }"#, ); - assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" + assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" [ InlayHint { range: [403; 452), diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 937c9caa5..285381086 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -62,13 +62,13 @@ use crate::display::ToNav; pub use crate::{ assists::{Assist, AssistId}, call_hierarchy::CallItem, - completion::{CompletionItem, CompletionItemKind, CompletionOptions, InsertTextFormat}, + completion::{CompletionConfig, CompletionItem, CompletionItemKind, InsertTextFormat}, diagnostics::Severity, display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, expand_macro::ExpandedMacro, folding_ranges::{Fold, FoldKind}, hover::HoverResult, - inlay_hints::{InlayHint, InlayHintsOptions, InlayKind}, + inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, runnables::{Runnable, RunnableKind, TestId}, source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, @@ -325,9 +325,9 @@ impl Analysis { pub fn inlay_hints( &self, file_id: FileId, - inlay_hint_opts: &InlayHintsOptions, + config: &InlayHintsConfig, ) -> Cancelable> { - self.with_db(|db| inlay_hints::inlay_hints(db, file_id, inlay_hint_opts)) + self.with_db(|db| inlay_hints::inlay_hints(db, file_id, config)) } /// Returns the set of folding ranges. @@ -450,9 +450,9 @@ impl Analysis { pub fn completions( &self, position: FilePosition, - options: &CompletionOptions, + config: &CompletionConfig, ) -> Cancelable>> { - self.with_db(|db| completion::completions(db, position, options).map(Into::into)) + self.with_db(|db| completion::completions(db, position, config).map(Into::into)) } /// Computes assists (aka code actions aka intentions) for the given -- cgit v1.2.3