Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions crates/ra_cargo_watch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic};
pub use crate::conv::url_from_path_with_drive_lowercasing;

#[derive(Clone, Debug)]
pub struct CheckOptions {
pub struct CheckConfig {
pub enable: bool,
pub args: Vec<String>,
pub command: String,
Expand All @@ -42,13 +42,11 @@ pub struct CheckWatcher {
}

impl CheckWatcher {
pub fn new(options: &CheckOptions, workspace_root: PathBuf) -> CheckWatcher {
let options = options.clone();

pub fn new(config: CheckConfig, workspace_root: PathBuf) -> CheckWatcher {
let (task_send, task_recv) = unbounded::<CheckTask>();
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
let handle = jod_thread::spawn(move || {
let mut check = CheckWatcherThread::new(options, workspace_root);
let mut check = CheckWatcherThread::new(config, workspace_root);
check.run(&task_send, &cmd_recv);
});
CheckWatcher { task_recv, cmd_send, handle: Some(handle) }
Expand Down Expand Up @@ -78,14 +76,14 @@ pub enum CheckCommand {
}

struct CheckWatcherThread {
options: CheckOptions,
options: CheckConfig,
workspace_root: PathBuf,
watcher: WatchThread,
last_update_req: Option<Instant>,
}

impl CheckWatcherThread {
fn new(options: CheckOptions, workspace_root: PathBuf) -> CheckWatcherThread {
fn new(options: CheckConfig, workspace_root: PathBuf) -> CheckWatcherThread {
CheckWatcherThread {
options,
workspace_root,
Expand Down Expand Up @@ -324,7 +322,7 @@ impl WatchThread {
WatchThread { message_recv: never(), _handle: None }
}

fn new(options: &CheckOptions, workspace_root: &Path) -> WatchThread {
fn new(options: &CheckConfig, workspace_root: &Path) -> WatchThread {
let mut args: Vec<String> = vec![
options.command.clone(),
"--workspace".to_string(),
Expand Down
10 changes: 5 additions & 5 deletions crates/ra_ide/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -75,9 +75,9 @@ impl Default for CompletionOptions {
pub(crate) fn completions(
db: &RootDatabase,
position: FilePosition,
options: &CompletionOptions,
config: &CompletionConfig,
) -> Option<Completions> {
let ctx = CompletionContext::new(db, position, options)?;
let ctx = CompletionContext::new(db, position, config)?;

let mut acc = Completions::default();

Expand Down
2 changes: 1 addition & 1 deletion crates/ra_ide/src/completion/complete_postfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions crates/ra_ide/src/completion/completion_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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.
#[derive(Debug)]
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,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl<'a> CompletionContext<'a> {
pub(super) fn new(
db: &'a RootDatabase,
position: FilePosition,
options: &'a CompletionOptions,
config: &'a CompletionConfig,
) -> Option<CompletionContext<'a>> {
let sema = Semantics::new(db);

Expand All @@ -85,7 +85,7 @@ impl<'a> CompletionContext<'a> {
let mut ctx = CompletionContext {
sema,
db,
options,
config,
original_token,
token,
offset: position.offset,
Expand Down
12 changes: 6 additions & 6 deletions crates/ra_ide/src/completion/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<CompletionItem> {
Expand All @@ -320,7 +320,7 @@ mod tests {

fn do_reference_completion_with_options(
ra_fixture: &str,
options: CompletionOptions,
options: CompletionConfig,
) -> Vec<CompletionItem> {
do_completion_with_options(ra_fixture, CompletionKind::Reference, &options)
}
Expand Down Expand Up @@ -589,7 +589,7 @@ mod tests {
s.f<|>
}
",
CompletionOptions {
CompletionConfig {
add_call_argument_snippets: false,
.. Default::default()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ra_ide/src/completion/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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<CompletionItem> {
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<CompletionItem> {
let (analysis, position) = if code.contains("//-") {
analysis_and_position(code)
Expand Down
Loading