diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/caps.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 12 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 24 | ||||
-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 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/path_map.rs | 6 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 2 |
7 files changed, 71 insertions, 42 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index bcf857fce..560f64989 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -19,7 +19,7 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
19 | hover_provider: Some(true), | 19 | hover_provider: Some(true), |
20 | completion_provider: Some(CompletionOptions { | 20 | completion_provider: Some(CompletionOptions { |
21 | resolve_provider: None, | 21 | resolve_provider: None, |
22 | trigger_characters: None, | 22 | trigger_characters: Some(vec![":".to_string()]), |
23 | }), | 23 | }), |
24 | signature_help_provider: Some(SignatureHelpOptions { | 24 | signature_help_provider: Some(SignatureHelpOptions { |
25 | trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]), | 25 | trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]), |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index e5a2449c2..28368787c 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -49,10 +49,9 @@ impl ConvWith for Position { | |||
49 | type Output = TextUnit; | 49 | type Output = TextUnit; |
50 | 50 | ||
51 | fn conv_with(self, line_index: &LineIndex) -> TextUnit { | 51 | fn conv_with(self, line_index: &LineIndex) -> TextUnit { |
52 | // TODO: UTF-16 | ||
53 | let line_col = LineCol { | 52 | let line_col = LineCol { |
54 | line: self.line as u32, | 53 | line: self.line as u32, |
55 | col: (self.character as u32).into(), | 54 | col_utf16: self.character as u32, |
56 | }; | 55 | }; |
57 | line_index.offset(line_col) | 56 | line_index.offset(line_col) |
58 | } | 57 | } |
@@ -64,8 +63,7 @@ impl ConvWith for TextUnit { | |||
64 | 63 | ||
65 | fn conv_with(self, line_index: &LineIndex) -> Position { | 64 | fn conv_with(self, line_index: &LineIndex) -> Position { |
66 | let line_col = line_index.line_col(self); | 65 | let line_col = line_index.line_col(self); |
67 | // TODO: UTF-16 | 66 | Position::new(u64::from(line_col.line), u64::from(line_col.col_utf16)) |
68 | Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))) | ||
69 | } | 67 | } |
70 | } | 68 | } |
71 | 69 | ||
@@ -204,7 +202,7 @@ impl TryConvWith for SourceChange { | |||
204 | .unwrap_or(&[]); | 202 | .unwrap_or(&[]); |
205 | let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); | 203 | let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); |
206 | let position = | 204 | let position = |
207 | Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))); | 205 | Position::new(u64::from(line_col.line), u64::from(line_col.col_utf16)); |
208 | Some(TextDocumentPositionParams { | 206 | Some(TextDocumentPositionParams { |
209 | text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), | 207 | text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), |
210 | position, | 208 | position, |
@@ -247,12 +245,12 @@ fn translate_offset_with_edit( | |||
247 | if in_edit_line_col.line == 0 { | 245 | if in_edit_line_col.line == 0 { |
248 | LineCol { | 246 | LineCol { |
249 | line: edit_line_col.line, | 247 | line: edit_line_col.line, |
250 | col: edit_line_col.col + in_edit_line_col.col, | 248 | col_utf16: edit_line_col.col_utf16 + in_edit_line_col.col_utf16, |
251 | } | 249 | } |
252 | } else { | 250 | } else { |
253 | LineCol { | 251 | LineCol { |
254 | line: edit_line_col.line + in_edit_line_col.line, | 252 | line: edit_line_col.line + in_edit_line_col.line, |
255 | col: in_edit_line_col.col, | 253 | col_utf16: in_edit_line_col.col_utf16, |
256 | } | 254 | } |
257 | } | 255 | } |
258 | } | 256 | } |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 26bcddd8e..8301a1044 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -65,27 +65,3 @@ fn main_inner() -> Result<()> { | |||
65 | info!("... IO is down"); | 65 | info!("... IO is down"); |
66 | Ok(()) | 66 | Ok(()) |
67 | } | 67 | } |
68 | |||
69 | /* | ||
70 | (let ((backend (eglot-xref-backend))) | ||
71 | (mapcar | ||
72 | (lambda (xref) | ||
73 | (let ((loc (xref-item-location xref))) | ||
74 | (propertize | ||
75 | (concat | ||
76 | (when (xref-file-location-p loc) | ||
77 | (with-slots (file line column) loc | ||
78 | (format "%s:%s:%s:" | ||
79 | (propertize (file-relative-name file) | ||
80 | 'face 'compilation-info) | ||
81 | (propertize (format "%s" line) | ||
82 | 'face 'compilation-line | ||
83 | ) | ||
84 | column))) | ||
85 | (xref-item-summary xref)) | ||
86 | 'xref xref))) | ||
87 | (xref-backend-apropos backend "Analysis")) | ||
88 | ) | ||
89 | |||
90 | |||
91 | */ | ||
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); |
diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs index 87eabf9be..02e54629c 100644 --- a/crates/ra_lsp_server/src/path_map.rs +++ b/crates/ra_lsp_server/src/path_map.rs | |||
@@ -43,7 +43,7 @@ impl PathMap { | |||
43 | (inserted, file_id) | 43 | (inserted, file_id) |
44 | } | 44 | } |
45 | pub fn get_id(&self, path: &Path) -> Option<FileId> { | 45 | pub fn get_id(&self, path: &Path) -> Option<FileId> { |
46 | self.path2id.get(path).map(|&id| id) | 46 | self.path2id.get(path).cloned() |
47 | } | 47 | } |
48 | pub fn get_path(&self, file_id: FileId) -> &Path { | 48 | pub fn get_path(&self, file_id: FileId) -> &Path { |
49 | self.id2path.get(&file_id).unwrap().as_path() | 49 | self.id2path.get(&file_id).unwrap().as_path() |
@@ -79,6 +79,10 @@ impl FileResolver for PathMap { | |||
79 | let path = normalize(&path); | 79 | let path = normalize(&path); |
80 | self.get_id(&path) | 80 | self.get_id(&path) |
81 | } | 81 | } |
82 | |||
83 | fn debug_path(&self, file_id: FileId) -> Option<PathBuf> { | ||
84 | Some(self.get_path(file_id).to_owned()) | ||
85 | } | ||
82 | } | 86 | } |
83 | 87 | ||
84 | fn normalize(path: &Path) -> PathBuf { | 88 | fn normalize(path: &Path) -> PathBuf { |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 3e7670fcc..12faeb93a 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -140,7 +140,7 @@ impl ServerWorldState { | |||
140 | Ok(file_id) | 140 | Ok(file_id) |
141 | } | 141 | } |
142 | pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) { | 142 | pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) { |
143 | let mut crate_graph = CrateGraph::new(); | 143 | let mut crate_graph = CrateGraph::default(); |
144 | ws.iter() | 144 | ws.iter() |
145 | .flat_map(|ws| { | 145 | .flat_map(|ws| { |
146 | ws.packages() | 146 | ws.packages() |