diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 35 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/mod.rs | 32 |
2 files changed, 59 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c872b0dc4..6d5622b15 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -9,7 +9,7 @@ use languageserver_types::{ | |||
9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, | 9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, |
10 | }; | 10 | }; |
11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; |
12 | use ra_syntax::text_utils::contains_offset_nonstrict; | 12 | use ra_syntax::{TextUnit, text_utils::contains_offset_nonstrict}; |
13 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
14 | use serde_json::to_value; | 14 | use serde_json::to_value; |
15 | 15 | ||
@@ -381,6 +381,28 @@ pub fn handle_completion( | |||
381 | let offset = params.position.conv_with(&line_index); | 381 | let offset = params.position.conv_with(&line_index); |
382 | FilePosition { file_id, offset } | 382 | FilePosition { file_id, offset } |
383 | }; | 383 | }; |
384 | let completion_triggered_after_single_colon = { | ||
385 | let mut res = false; | ||
386 | if let Some(ctx) = params.context { | ||
387 | if ctx.trigger_character.unwrap_or_default() == ":" { | ||
388 | let source_file = world.analysis().file_syntax(position.file_id); | ||
389 | let syntax = source_file.syntax(); | ||
390 | let text = syntax.text(); | ||
391 | if let Some(next_char) = text.char_at(position.offset) { | ||
392 | let diff = TextUnit::of_char(next_char) + TextUnit::of_char(':'); | ||
393 | let prev_char = position.offset - diff; | ||
394 | if text.char_at(prev_char) != Some(':') { | ||
395 | res = true; | ||
396 | } | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | res | ||
401 | }; | ||
402 | if completion_triggered_after_single_colon { | ||
403 | return Ok(None); | ||
404 | } | ||
405 | |||
384 | let items = match world.analysis().completions(position)? { | 406 | let items = match world.analysis().completions(position)? { |
385 | None => return Ok(None), | 407 | None => return Ok(None), |
386 | Some(items) => items, | 408 | Some(items) => items, |
@@ -545,10 +567,13 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option< | |||
545 | let mut changes = HashMap::new(); | 567 | let mut changes = HashMap::new(); |
546 | for r in refs { | 568 | for r in refs { |
547 | if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) { | 569 | if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) { |
548 | changes.entry(loc.uri).or_insert(Vec::new()).push(TextEdit { | 570 | changes |
549 | range: loc.range, | 571 | .entry(loc.uri) |
550 | new_text: params.new_name.clone(), | 572 | .or_insert_with(Vec::new) |
551 | }); | 573 | .push(TextEdit { |
574 | range: loc.range, | ||
575 | new_text: params.new_name.clone(), | ||
576 | }); | ||
552 | } | 577 | } |
553 | } | 578 | } |
554 | 579 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 78d93741a..36f08be2f 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs | |||
@@ -168,9 +168,35 @@ fn main_loop_inner( | |||
168 | let workspaces = vec![ws]; | 168 | let workspaces = vec![ws]; |
169 | feedback(internal_mode, "workspace loaded", msg_sender); | 169 | feedback(internal_mode, "workspace loaded", msg_sender); |
170 | for ws in workspaces.iter() { | 170 | for ws in workspaces.iter() { |
171 | for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { | 171 | // Add each library as constant input. If library is |
172 | debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); | 172 | // within the workspace, don't treat it as a library. |
173 | fs_worker.send(pkg.root(ws).to_path_buf()); | 173 | // |
174 | // HACK: If source roots are nested, pick the outer one. | ||
175 | |||
176 | let mut roots = ws | ||
177 | .packages() | ||
178 | .filter(|pkg| !pkg.is_member(ws)) | ||
179 | .filter_map(|pkg| { | ||
180 | let root = pkg.root(ws).to_path_buf(); | ||
181 | if root.starts_with(&ws_root) { | ||
182 | None | ||
183 | } else { | ||
184 | Some(root) | ||
185 | } | ||
186 | }) | ||
187 | .collect::<Vec<_>>(); | ||
188 | roots.sort_by_key(|it| it.as_os_str().len()); | ||
189 | let unique = roots | ||
190 | .iter() | ||
191 | .enumerate() | ||
192 | .filter(|&(idx, long)| { | ||
193 | !roots[..idx].iter().any(|short| long.starts_with(short)) | ||
194 | }) | ||
195 | .map(|(_idx, root)| root); | ||
196 | |||
197 | for root in unique { | ||
198 | debug!("sending root, {}", root.display()); | ||
199 | fs_worker.send(root.to_owned()); | ||
174 | } | 200 | } |
175 | } | 201 | } |
176 | state.set_workspaces(workspaces); | 202 | state.set_workspaces(workspaces); |