diff options
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 20 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 33 |
4 files changed, 44 insertions, 26 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 836fb89f5..b513736bb 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -205,7 +205,7 @@ impl AnalysisImpl { | |||
205 | 205 | ||
206 | /// This returns `Vec` because a module may be included from several places. We | 206 | /// This returns `Vec` because a module may be included from several places. We |
207 | /// don't handle this case yet though, so the Vec has length at most one. | 207 | /// don't handle this case yet though, so the Vec has length at most one. |
208 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 208 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
209 | let descr = match source_binder::module_from_position(&*self.db, position)? { | 209 | let descr = match source_binder::module_from_position(&*self.db, position)? { |
210 | None => return Ok(Vec::new()), | 210 | None => return Ok(Vec::new()), |
211 | Some(it) => it, | 211 | Some(it) => it, |
@@ -216,12 +216,12 @@ impl AnalysisImpl { | |||
216 | }; | 216 | }; |
217 | let decl = decl.borrowed(); | 217 | let decl = decl.borrowed(); |
218 | let decl_name = decl.name().unwrap(); | 218 | let decl_name = decl.name().unwrap(); |
219 | let sym = FileSymbol { | 219 | let symbol = FileSymbol { |
220 | name: decl_name.text(), | 220 | name: decl_name.text(), |
221 | node_range: decl_name.syntax().range(), | 221 | node_range: decl_name.syntax().range(), |
222 | kind: MODULE, | 222 | kind: MODULE, |
223 | }; | 223 | }; |
224 | Ok(vec![(file_id, sym)]) | 224 | Ok(vec![NavigationTarget { file_id, symbol }]) |
225 | } | 225 | } |
226 | /// Returns `Vec` for the same reason as `parent_module` | 226 | /// Returns `Vec` for the same reason as `parent_module` |
227 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 227 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 4d8bdb61b..75867ee86 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -24,7 +24,7 @@ mod macros; | |||
24 | use std::{fmt, sync::Arc}; | 24 | use std::{fmt, sync::Arc}; |
25 | 25 | ||
26 | use rustc_hash::FxHashMap; | 26 | use rustc_hash::FxHashMap; |
27 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 27 | use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind}; |
28 | use ra_text_edit::TextEdit; | 28 | use ra_text_edit::TextEdit; |
29 | use rayon::prelude::*; | 29 | use rayon::prelude::*; |
30 | use relative_path::RelativePathBuf; | 30 | use relative_path::RelativePathBuf; |
@@ -251,6 +251,12 @@ pub struct NavigationTarget { | |||
251 | } | 251 | } |
252 | 252 | ||
253 | impl NavigationTarget { | 253 | impl NavigationTarget { |
254 | pub fn name(&self) -> SmolStr { | ||
255 | self.symbol.name.clone() | ||
256 | } | ||
257 | pub fn kind(&self) -> SyntaxKind { | ||
258 | self.symbol.kind | ||
259 | } | ||
254 | pub fn file_id(&self) -> FileId { | 260 | pub fn file_id(&self) -> FileId { |
255 | self.file_id | 261 | self.file_id |
256 | } | 262 | } |
@@ -337,8 +343,14 @@ impl Analysis { | |||
337 | let file = self.imp.file_syntax(file_id); | 343 | let file = self.imp.file_syntax(file_id); |
338 | ra_editor::folding_ranges(&file) | 344 | ra_editor::folding_ranges(&file) |
339 | } | 345 | } |
340 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 346 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { |
341 | self.imp.world_symbols(query) | 347 | let res = self |
348 | .imp | ||
349 | .world_symbols(query)? | ||
350 | .into_iter() | ||
351 | .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) | ||
352 | .collect(); | ||
353 | Ok(res) | ||
342 | } | 354 | } |
343 | pub fn approximately_resolve_symbol( | 355 | pub fn approximately_resolve_symbol( |
344 | &self, | 356 | &self, |
@@ -352,7 +364,7 @@ impl Analysis { | |||
352 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { | 364 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { |
353 | self.imp.doc_text_for(nav) | 365 | self.imp.doc_text_for(nav) |
354 | } | 366 | } |
355 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 367 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
356 | self.imp.parent_module(position) | 368 | self.imp.parent_module(position) |
357 | } | 369 | } |
358 | pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { | 370 | pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 618486250..1107ffc8b 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -2,7 +2,7 @@ use languageserver_types::{ | |||
2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, | 3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange, CompletionItem, CompletionItemKind, InsertText}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange, CompletionItem, CompletionItemKind, InsertText, NavigationTarget}; |
6 | use ra_editor::{LineCol, LineIndex, translate_offset_with_edit}; | 6 | use ra_editor::{LineCol, LineIndex, translate_offset_with_edit}; |
7 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 7 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
@@ -322,6 +322,15 @@ impl TryConvWith for FileSystemEdit { | |||
322 | } | 322 | } |
323 | } | 323 | } |
324 | 324 | ||
325 | impl TryConvWith for &NavigationTarget { | ||
326 | type Ctx = ServerWorld; | ||
327 | type Output = Location; | ||
328 | fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { | ||
329 | let line_index = world.analysis().file_line_index(self.file_id()); | ||
330 | to_location(self.file_id(), self.range(), &world, &line_index) | ||
331 | } | ||
332 | } | ||
333 | |||
325 | pub fn to_location( | 334 | pub fn to_location( |
326 | file_id: FileId, | 335 | file_id: FileId, |
327 | range: TextRange, | 336 | range: TextRange, |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5ff6219f9..26b6c7d8a 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -188,12 +188,11 @@ pub fn handle_workspace_symbol( | |||
188 | 188 | ||
189 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { | 189 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { |
190 | let mut res = Vec::new(); | 190 | let mut res = Vec::new(); |
191 | for (file_id, symbol) in world.analysis().symbol_search(query)? { | 191 | for nav in world.analysis().symbol_search(query)? { |
192 | let line_index = world.analysis().file_line_index(file_id); | ||
193 | let info = SymbolInformation { | 192 | let info = SymbolInformation { |
194 | name: symbol.name.to_string(), | 193 | name: nav.name().into(), |
195 | kind: symbol.kind.conv(), | 194 | kind: nav.kind().conv(), |
196 | location: to_location(file_id, symbol.node_range, world, &line_index)?, | 195 | location: nav.try_conv_with(world)?, |
197 | container_name: None, | 196 | container_name: None, |
198 | deprecated: None, | 197 | deprecated: None, |
199 | }; | 198 | }; |
@@ -212,12 +211,11 @@ pub fn handle_goto_definition( | |||
212 | None => return Ok(None), | 211 | None => return Ok(None), |
213 | Some(it) => it, | 212 | Some(it) => it, |
214 | }; | 213 | }; |
215 | let mut res = Vec::new(); | 214 | let res = rr |
216 | for nav in rr.resolves_to { | 215 | .resolves_to |
217 | let line_index = world.analysis().file_line_index(nav.file_id()); | 216 | .into_iter() |
218 | let location = to_location(nav.file_id(), nav.range(), &world, &line_index)?; | 217 | .map(|nav| nav.try_conv_with(&world)) |
219 | res.push(location) | 218 | .collect::<Result<Vec<_>>>()?; |
220 | } | ||
221 | Ok(Some(req::GotoDefinitionResponse::Array(res))) | 219 | Ok(Some(req::GotoDefinitionResponse::Array(res))) |
222 | } | 220 | } |
223 | 221 | ||
@@ -226,13 +224,12 @@ pub fn handle_parent_module( | |||
226 | params: req::TextDocumentPositionParams, | 224 | params: req::TextDocumentPositionParams, |
227 | ) -> Result<Vec<Location>> { | 225 | ) -> Result<Vec<Location>> { |
228 | let position = params.try_conv_with(&world)?; | 226 | let position = params.try_conv_with(&world)?; |
229 | let mut res = Vec::new(); | 227 | world |
230 | for (file_id, symbol) in world.analysis().parent_module(position)? { | 228 | .analysis() |
231 | let line_index = world.analysis().file_line_index(file_id); | 229 | .parent_module(position)? |
232 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 230 | .into_iter() |
233 | res.push(location); | 231 | .map(|nav| nav.try_conv_with(&world)) |
234 | } | 232 | .collect::<Result<Vec<_>>>() |
235 | Ok(res) | ||
236 | } | 233 | } |
237 | 234 | ||
238 | pub fn handle_runnables( | 235 | pub fn handle_runnables( |