Skip to content

Commit fa3c774

Browse files
bors[bot]matklad
andauthored
Merge #3790
3790: Better names for config structs r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 6546edc + 569f47e commit fa3c774

File tree

14 files changed

+135
-121
lines changed

14 files changed

+135
-121
lines changed

crates/ra_cargo_watch/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic};
2222
pub use crate::conv::url_from_path_with_drive_lowercasing;
2323

2424
#[derive(Clone, Debug)]
25-
pub struct CheckOptions {
25+
pub struct CheckConfig {
2626
pub enable: bool,
2727
pub args: Vec<String>,
2828
pub command: String,
@@ -42,13 +42,11 @@ pub struct CheckWatcher {
4242
}
4343

4444
impl CheckWatcher {
45-
pub fn new(options: &CheckOptions, workspace_root: PathBuf) -> CheckWatcher {
46-
let options = options.clone();
47-
45+
pub fn new(config: CheckConfig, workspace_root: PathBuf) -> CheckWatcher {
4846
let (task_send, task_recv) = unbounded::<CheckTask>();
4947
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
5048
let handle = jod_thread::spawn(move || {
51-
let mut check = CheckWatcherThread::new(options, workspace_root);
49+
let mut check = CheckWatcherThread::new(config, workspace_root);
5250
check.run(&task_send, &cmd_recv);
5351
});
5452
CheckWatcher { task_recv, cmd_send, handle: Some(handle) }
@@ -78,14 +76,14 @@ pub enum CheckCommand {
7876
}
7977

8078
struct CheckWatcherThread {
81-
options: CheckOptions,
79+
options: CheckConfig,
8280
workspace_root: PathBuf,
8381
watcher: WatchThread,
8482
last_update_req: Option<Instant>,
8583
}
8684

8785
impl CheckWatcherThread {
88-
fn new(options: CheckOptions, workspace_root: PathBuf) -> CheckWatcherThread {
86+
fn new(options: CheckConfig, workspace_root: PathBuf) -> CheckWatcherThread {
8987
CheckWatcherThread {
9088
options,
9189
workspace_root,
@@ -324,7 +322,7 @@ impl WatchThread {
324322
WatchThread { message_recv: never(), _handle: None }
325323
}
326324

327-
fn new(options: &CheckOptions, workspace_root: &Path) -> WatchThread {
325+
fn new(options: &CheckConfig, workspace_root: &Path) -> WatchThread {
328326
let mut args: Vec<String> = vec![
329327
options.command.clone(),
330328
"--workspace".to_string(),

crates/ra_ide/src/completion.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ pub use crate::completion::completion_item::{
3434
};
3535

3636
#[derive(Clone, Debug, PartialEq, Eq)]
37-
pub struct CompletionOptions {
37+
pub struct CompletionConfig {
3838
pub enable_postfix_completions: bool,
3939
pub add_call_parenthesis: bool,
4040
pub add_call_argument_snippets: bool,
4141
}
4242

43-
impl Default for CompletionOptions {
43+
impl Default for CompletionConfig {
4444
fn default() -> Self {
45-
CompletionOptions {
45+
CompletionConfig {
4646
enable_postfix_completions: true,
4747
add_call_parenthesis: true,
4848
add_call_argument_snippets: true,
@@ -75,9 +75,9 @@ impl Default for CompletionOptions {
7575
pub(crate) fn completions(
7676
db: &RootDatabase,
7777
position: FilePosition,
78-
options: &CompletionOptions,
78+
config: &CompletionConfig,
7979
) -> Option<Completions> {
80-
let ctx = CompletionContext::new(db, position, options)?;
80+
let ctx = CompletionContext::new(db, position, config)?;
8181

8282
let mut acc = Completions::default();
8383

crates/ra_ide/src/completion/complete_postfix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
};
1616

1717
pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
18-
if !ctx.options.enable_postfix_completions {
18+
if !ctx.config.enable_postfix_completions {
1919
return;
2020
}
2121

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use ra_syntax::{
1111
};
1212
use ra_text_edit::AtomTextEdit;
1313

14-
use crate::{completion::CompletionOptions, FilePosition};
14+
use crate::{completion::CompletionConfig, FilePosition};
1515

1616
/// `CompletionContext` is created early during completion to figure out, where
1717
/// exactly is the cursor, syntax-wise.
1818
#[derive(Debug)]
1919
pub(crate) struct CompletionContext<'a> {
2020
pub(super) sema: Semantics<'a, RootDatabase>,
2121
pub(super) db: &'a RootDatabase,
22-
pub(super) options: &'a CompletionOptions,
22+
pub(super) config: &'a CompletionConfig,
2323
pub(super) offset: TextUnit,
2424
/// The token before the cursor, in the original file.
2525
pub(super) original_token: SyntaxToken,
@@ -61,7 +61,7 @@ impl<'a> CompletionContext<'a> {
6161
pub(super) fn new(
6262
db: &'a RootDatabase,
6363
position: FilePosition,
64-
options: &'a CompletionOptions,
64+
config: &'a CompletionConfig,
6565
) -> Option<CompletionContext<'a>> {
6666
let sema = Semantics::new(db);
6767

@@ -85,7 +85,7 @@ impl<'a> CompletionContext<'a> {
8585
let mut ctx = CompletionContext {
8686
sema,
8787
db,
88-
options,
88+
config,
8989
original_token,
9090
token,
9191
offset: position.offset,

crates/ra_ide/src/completion/presentation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Completions {
106106
};
107107

108108
// Add `<>` for generic types
109-
if ctx.is_path_type && !ctx.has_type_args && ctx.options.add_call_parenthesis {
109+
if ctx.is_path_type && !ctx.has_type_args && ctx.config.add_call_parenthesis {
110110
let has_non_default_type_params = match resolution {
111111
ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db),
112112
ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db),
@@ -211,14 +211,14 @@ impl Completions {
211211
.detail(function_signature.to_string());
212212

213213
// If not an import, add parenthesis automatically.
214-
if ctx.use_item_syntax.is_none() && !ctx.is_call && ctx.options.add_call_parenthesis {
214+
if ctx.use_item_syntax.is_none() && !ctx.is_call && ctx.config.add_call_parenthesis {
215215
tested_by!(inserts_parens_for_function_calls);
216216

217217
let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 {
218218
(format!("{}()$0", name), format!("{}()", name))
219219
} else {
220220
builder = builder.trigger_call_info();
221-
let snippet = if ctx.options.add_call_argument_snippets {
221+
let snippet = if ctx.config.add_call_argument_snippets {
222222
let to_skip = if has_self_param { 1 } else { 0 };
223223
let function_params_snippet = function_signature
224224
.parameter_names
@@ -311,7 +311,7 @@ mod tests {
311311

312312
use crate::completion::{
313313
test_utils::{do_completion, do_completion_with_options},
314-
CompletionItem, CompletionKind, CompletionOptions,
314+
CompletionConfig, CompletionItem, CompletionKind,
315315
};
316316

317317
fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> {
@@ -320,7 +320,7 @@ mod tests {
320320

321321
fn do_reference_completion_with_options(
322322
ra_fixture: &str,
323-
options: CompletionOptions,
323+
options: CompletionConfig,
324324
) -> Vec<CompletionItem> {
325325
do_completion_with_options(ra_fixture, CompletionKind::Reference, &options)
326326
}
@@ -589,7 +589,7 @@ mod tests {
589589
s.f<|>
590590
}
591591
",
592-
CompletionOptions {
592+
CompletionConfig {
593593
add_call_argument_snippets: false,
594594
.. Default::default()
595595
}

crates/ra_ide/src/completion/test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//! Runs completion for testing purposes.
22
33
use crate::{
4-
completion::{completion_item::CompletionKind, CompletionOptions},
4+
completion::{completion_item::CompletionKind, CompletionConfig},
55
mock_analysis::{analysis_and_position, single_file_with_position},
66
CompletionItem,
77
};
88

99
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
10-
do_completion_with_options(code, kind, &CompletionOptions::default())
10+
do_completion_with_options(code, kind, &CompletionConfig::default())
1111
}
1212

1313
pub(crate) fn do_completion_with_options(
1414
code: &str,
1515
kind: CompletionKind,
16-
options: &CompletionOptions,
16+
options: &CompletionConfig,
1717
) -> Vec<CompletionItem> {
1818
let (analysis, position) = if code.contains("//-") {
1919
analysis_and_position(code)

0 commit comments

Comments
 (0)