aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/assists/add_custom_impl.rs2
-rw-r--r--crates/ra_cargo_watch/src/lib.rs13
-rw-r--r--crates/ra_cli/src/main.rs2
-rw-r--r--crates/ra_hir_ty/src/traits.rs44
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs2
-rw-r--r--crates/ra_ide/src/call_info.rs59
-rw-r--r--crates/ra_ide/src/completion/complete_path.rs2
-rw-r--r--crates/ra_ide/src/extend_selection.rs2
-rw-r--r--crates/ra_ide/src/references.rs13
-rw-r--r--crates/ra_ide/src/references/search_scope.rs3
-rw-r--r--crates/ra_lsp_server/src/main.rs4
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs1
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs4
13 files changed, 95 insertions, 56 deletions
diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs
index 037306fd6..9b8955710 100644
--- a/crates/ra_assists/src/assists/add_custom_impl.rs
+++ b/crates/ra_assists/src/assists/add_custom_impl.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10 TextRange, TextUnit, 10 TextRange, TextUnit,
11}; 11};
12 12
13const DERIVE_TRAIT: &'static str = "derive"; 13const DERIVE_TRAIT: &str = "derive";
14 14
15// Assist: add_custom_impl 15// Assist: add_custom_impl
16// 16//
diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs
index cb0856aa4..20fa5a924 100644
--- a/crates/ra_cargo_watch/src/lib.rs
+++ b/crates/ra_cargo_watch/src/lib.rs
@@ -184,8 +184,13 @@ impl CheckWatcherState {
184 workspace_root: PathBuf, 184 workspace_root: PathBuf,
185 shared: Arc<RwLock<CheckWatcherSharedState>>, 185 shared: Arc<RwLock<CheckWatcherSharedState>>,
186 ) -> CheckWatcherState { 186 ) -> CheckWatcherState {
187 let watcher = WatchThread::new(&options, &workspace_root); 187 CheckWatcherState {
188 CheckWatcherState { options, workspace_root, watcher, last_update_req: None, shared } 188 options,
189 workspace_root,
190 watcher: WatchThread::dummy(),
191 last_update_req: None,
192 shared,
193 }
189 } 194 }
190 195
191 fn run(&mut self, task_send: &Sender<CheckTask>, cmd_recv: &Receiver<CheckCommand>) { 196 fn run(&mut self, task_send: &Sender<CheckTask>, cmd_recv: &Receiver<CheckCommand>) {
@@ -313,6 +318,10 @@ enum CheckEvent {
313} 318}
314 319
315impl WatchThread { 320impl WatchThread {
321 fn dummy() -> WatchThread {
322 WatchThread { handle: None, message_recv: never() }
323 }
324
316 fn new(options: &CheckOptions, workspace_root: &PathBuf) -> WatchThread { 325 fn new(options: &CheckOptions, workspace_root: &PathBuf) -> WatchThread {
317 let mut args: Vec<String> = vec![ 326 let mut args: Vec<String> = vec![
318 options.command.clone(), 327 options.command.clone(),
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 3808590ab..806612c2c 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -22,7 +22,7 @@ pub enum Verbosity {
22} 22}
23 23
24impl Verbosity { 24impl Verbosity {
25 fn is_verbose(&self) -> bool { 25 fn is_verbose(self) -> bool {
26 match self { 26 match self {
27 Verbosity::Verbose => true, 27 Verbosity::Verbose => true,
28 _ => false, 28 _ => false,
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs
index c4dc857bc..4aabd66dc 100644
--- a/crates/ra_hir_ty/src/traits.rs
+++ b/crates/ra_hir_ty/src/traits.rs
@@ -1,10 +1,12 @@
1//! Trait solving using Chalk. 1//! Trait solving using Chalk.
2use std::sync::{Arc, Mutex}; 2use std::{
3 panic,
4 sync::{Arc, Mutex},
5};
3 6
4use chalk_ir::cast::Cast; 7use chalk_ir::cast::Cast;
5use hir_def::{expr::ExprId, DefWithBodyId, ImplId, TraitId, TypeAliasId}; 8use hir_def::{expr::ExprId, DefWithBodyId, ImplId, TraitId, TypeAliasId};
6use log::debug; 9use ra_db::{impl_intern_key, salsa, Canceled, CrateId};
7use ra_db::{impl_intern_key, salsa, CrateId};
8use ra_prof::profile; 10use ra_prof::profile;
9use rustc_hash::FxHashSet; 11use rustc_hash::FxHashSet;
10 12
@@ -39,7 +41,7 @@ impl TraitSolver {
39 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<TypeFamily>>>, 41 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<TypeFamily>>>,
40 ) -> Option<chalk_solve::Solution<TypeFamily>> { 42 ) -> Option<chalk_solve::Solution<TypeFamily>> {
41 let context = ChalkContext { db, krate: self.krate }; 43 let context = ChalkContext { db, krate: self.krate };
42 debug!("solve goal: {:?}", goal); 44 log::debug!("solve goal: {:?}", goal);
43 let mut solver = match self.inner.lock() { 45 let mut solver = match self.inner.lock() {
44 Ok(it) => it, 46 Ok(it) => it,
45 // Our cancellation works via unwinding, but, as chalk is not 47 // Our cancellation works via unwinding, but, as chalk is not
@@ -47,8 +49,28 @@ impl TraitSolver {
47 // Ideally, we should also make chalk panic-safe. 49 // Ideally, we should also make chalk panic-safe.
48 Err(_) => ra_db::Canceled::throw(), 50 Err(_) => ra_db::Canceled::throw(),
49 }; 51 };
50 let solution = solver.solve(&context, goal); 52
51 debug!("solve({:?}) => {:?}", goal, solution); 53 let solution = panic::catch_unwind({
54 let solver = panic::AssertUnwindSafe(&mut solver);
55 let context = panic::AssertUnwindSafe(&context);
56 move || solver.0.solve(context.0, goal)
57 });
58
59 let solution = match solution {
60 Ok(it) => it,
61 Err(err) => {
62 if err.downcast_ref::<Canceled>().is_some() {
63 panic::resume_unwind(err)
64 } else {
65 log::error!("chalk panicked :-(");
66 // Reset the solver, as it is not panic-safe.
67 *solver = create_chalk_solver();
68 None
69 }
70 }
71 };
72
73 log::debug!("solve({:?}) => {:?}", goal, solution);
52 solution 74 solution
53 } 75 }
54} 76}
@@ -70,9 +92,13 @@ pub(crate) fn trait_solver_query(
70) -> TraitSolver { 92) -> TraitSolver {
71 db.salsa_runtime().report_untracked_read(); 93 db.salsa_runtime().report_untracked_read();
72 // krate parameter is just so we cache a unique solver per crate 94 // krate parameter is just so we cache a unique solver per crate
95 log::debug!("Creating new solver for crate {:?}", krate);
96 TraitSolver { krate, inner: Arc::new(Mutex::new(create_chalk_solver())) }
97}
98
99fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> {
73 let solver_choice = chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE }; 100 let solver_choice = chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE };
74 debug!("Creating new solver for crate {:?}", krate); 101 solver_choice.into_solver()
75 TraitSolver { krate, inner: Arc::new(Mutex::new(solver_choice.into_solver())) }
76} 102}
77 103
78/// Collects impls for the given trait in the whole dependency tree of `krate`. 104/// Collects impls for the given trait in the whole dependency tree of `krate`.
@@ -181,7 +207,7 @@ pub(crate) fn trait_solve_query(
181 goal: Canonical<InEnvironment<Obligation>>, 207 goal: Canonical<InEnvironment<Obligation>>,
182) -> Option<Solution> { 208) -> Option<Solution> {
183 let _p = profile("trait_solve_query"); 209 let _p = profile("trait_solve_query");
184 debug!("trait_solve_query({})", goal.value.value.display(db)); 210 log::debug!("trait_solve_query({})", goal.value.value.display(db));
185 211
186 if let Obligation::Projection(pred) = &goal.value.value { 212 if let Obligation::Projection(pred) = &goal.value.value {
187 if let Ty::Bound(_) = &pred.projection_ty.parameters[0] { 213 if let Ty::Bound(_) = &pred.projection_ty.parameters[0] {
diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs
index 1cb712e32..aa5d60c7b 100644
--- a/crates/ra_ide/src/call_hierarchy.rs
+++ b/crates/ra_ide/src/call_hierarchy.rs
@@ -121,7 +121,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio
121 Some(macro_def.to_nav(db)) 121 Some(macro_def.to_nav(db))
122 } 122 }
123 } { 123 } {
124 Some((func_target.clone(), name_ref.value.text_range())) 124 Some((func_target, name_ref.value.text_range()))
125 } else { 125 } else {
126 None 126 None
127 } 127 }
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index a7023529b..72a68522e 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -1,10 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2
3use hir::db::AstDatabase; 2use hir::db::AstDatabase;
4use ra_syntax::{ 3use ra_syntax::{
5 ast::{self, ArgListOwner}, 4 ast::{self, ArgListOwner},
6 match_ast, AstNode, SyntaxNode, 5 match_ast, AstNode, SyntaxNode,
7}; 6};
7
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
10use crate::{ 10use crate::{
@@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
51 // If we have a calling expression let's find which argument we are on 51 // If we have a calling expression let's find which argument we are on
52 let num_params = call_info.parameters().len(); 52 let num_params = call_info.parameters().len();
53 53
54 if num_params == 1 { 54 match num_params {
55 if !has_self { 55 0 => (),
56 call_info.active_parameter = Some(0); 56 1 => {
57 } 57 if !has_self {
58 } else if num_params > 1 { 58 call_info.active_parameter = Some(0);
59 // Count how many parameters into the call we are.
60 if let Some(arg_list) = calling_node.arg_list() {
61 // Number of arguments specified at the call site
62 let num_args_at_callsite = arg_list.args().count();
63
64 let arg_list_range = arg_list.syntax().text_range();
65 if !arg_list_range.contains_inclusive(position.offset) {
66 tested_by!(call_info_bad_offset);
67 return None;
68 } 59 }
60 }
61 _ => {
62 if let Some(arg_list) = calling_node.arg_list() {
63 // Number of arguments specified at the call site
64 let num_args_at_callsite = arg_list.args().count();
65
66 let arg_list_range = arg_list.syntax().text_range();
67 if !arg_list_range.contains_inclusive(position.offset) {
68 tested_by!(call_info_bad_offset);
69 return None;
70 }
69 71
70 let mut param = std::cmp::min( 72 let mut param = std::cmp::min(
71 num_args_at_callsite, 73 num_args_at_callsite,
72 arg_list 74 arg_list
73 .args() 75 .args()
74 .take_while(|arg| arg.syntax().text_range().end() < position.offset) 76 .take_while(|arg| arg.syntax().text_range().end() < position.offset)
75 .count(), 77 .count(),
76 ); 78 );
77 79
78 // If we are in a method account for `self` 80 // If we are in a method account for `self`
79 if has_self { 81 if has_self {
80 param += 1; 82 param += 1;
81 } 83 }
82 84
83 call_info.active_parameter = Some(param); 85 call_info.active_parameter = Some(param);
86 }
84 } 87 }
85 } 88 }
86 89
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs
index cc1f7c830..0dce9dc2d 100644
--- a/crates/ra_ide/src/completion/complete_path.rs
+++ b/crates/ra_ide/src/completion/complete_path.rs
@@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
26 } 26 }
27 if let ScopeDef::Unknown = def { 27 if let ScopeDef::Unknown = def {
28 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { 28 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
29 if &name_ref.syntax().text() == name.to_string().as_str() { 29 if name_ref.syntax().text() == name.to_string().as_str() {
30 // for `use self::foo<|>`, don't suggest `foo` as a completion 30 // for `use self::foo<|>`, don't suggest `foo` as a completion
31 tested_by!(dont_complete_current_use); 31 tested_by!(dont_complete_current_use);
32 continue; 32 continue;
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index 70b6fde82..930e0c4c2 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -339,7 +339,7 @@ mod tests {
339 let (cursor, before) = extract_offset(before); 339 let (cursor, before) = extract_offset(before);
340 let (analysis, file_id) = single_file(&before); 340 let (analysis, file_id) = single_file(&before);
341 let range = TextRange::offset_len(cursor, 0.into()); 341 let range = TextRange::offset_len(cursor, 0.into());
342 let mut frange = FileRange { file_id: file_id, range }; 342 let mut frange = FileRange { file_id, range };
343 343
344 for &after in afters { 344 for &after in afters {
345 frange.range = analysis.extend_selection(frange).unwrap(); 345 frange.range = analysis.extend_selection(frange).unwrap();
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 4e52e0e7b..2c753dade 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -166,7 +166,7 @@ pub(crate) fn find_all_refs(
166 Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references })) 166 Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references }))
167} 167}
168 168
169fn find_name<'a>( 169fn find_name(
170 db: &RootDatabase, 170 db: &RootDatabase,
171 syntax: &SyntaxNode, 171 syntax: &SyntaxNode,
172 position: FilePosition, 172 position: FilePosition,
@@ -253,13 +253,10 @@ fn decl_access(
253 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?; 253 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
254 if let Some(_) = stmt.initializer() { 254 if let Some(_) = stmt.initializer() {
255 let pat = stmt.pat()?; 255 let pat = stmt.pat()?;
256 match pat { 256 if let ast::Pat::BindPat(it) = pat {
257 ast::Pat::BindPat(it) => { 257 if it.name()?.text().as_str() == name {
258 if it.name()?.text().as_str() == name { 258 return Some(ReferenceAccess::Write);
259 return Some(ReferenceAccess::Write);
260 }
261 } 259 }
262 _ => {}
263 } 260 }
264 } 261 }
265 262
@@ -286,7 +283,7 @@ fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option<Referenc
286 } 283 }
287 } 284 }
288 } 285 }
289 return Some(ReferenceAccess::Read); 286 Some(ReferenceAccess::Read)
290 }, 287 },
291 _ => {None} 288 _ => {None}
292 } 289 }
diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs
index 241dd358f..f8211a746 100644
--- a/crates/ra_ide/src/references/search_scope.rs
+++ b/crates/ra_ide/src/references/search_scope.rs
@@ -82,8 +82,7 @@ impl NameDefinition {
82 return SearchScope::new(res); 82 return SearchScope::new(res);
83 } 83 }
84 84
85 let vis = 85 let vis = self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default();
86 self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or("".to_string());
87 86
88 if vis.as_str() == "pub(super)" { 87 if vis.as_str() == "pub(super)" {
89 if let Some(parent_module) = self.container.parent(db) { 88 if let Some(parent_module) = self.container.parent(db) {
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index cdd925c9f..3879eeff2 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -47,6 +47,10 @@ fn run_server() -> Result<()> {
47 let initialize_params = connection.initialize(server_capabilities)?; 47 let initialize_params = connection.initialize(server_capabilities)?;
48 let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?; 48 let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?;
49 49
50 if let Some(client_info) = initialize_params.client_info {
51 log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default());
52 }
53
50 let cwd = std::env::current_dir()?; 54 let cwd = std::env::current_dir()?;
51 let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd); 55 let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd);
52 56
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 7a49cad86..84012b99d 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -417,6 +417,7 @@ fn loop_turn(
417 let msg = format!("workspace loaded, {} rust packages", n_packages); 417 let msg = format!("workspace loaded, {} rust packages", n_packages);
418 show_message(req::MessageType::Info, msg, &connection.sender); 418 show_message(req::MessageType::Info, msg, &connection.sender);
419 } 419 }
420 world_state.check_watcher.update();
420 } 421 }
421 422
422 if state_changed { 423 if state_changed {
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 3dfecfe76..6da4b1309 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -127,8 +127,8 @@ pub enum BinOp {
127} 127}
128 128
129impl BinOp { 129impl BinOp {
130 pub fn is_assignment(&self) -> bool { 130 pub fn is_assignment(self) -> bool {
131 match *self { 131 match self {
132 BinOp::Assignment 132 BinOp::Assignment
133 | BinOp::AddAssign 133 | BinOp::AddAssign
134 | BinOp::DivAssign 134 | BinOp::DivAssign