diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-20 18:17:18 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-20 18:17:18 +0000 |
commit | b89f8b6b4929ec09be4f9b13f87ad56b3235bd39 (patch) | |
tree | 0cdaf64f538467c3f5a974cac51413f495250f06 | |
parent | 3508ba9bc2c2180a6495238c2fafa493557f36d0 (diff) | |
parent | 73836cdbbc928f3512156f0bc0166e5a39ad9864 (diff) |
Merge #580
580: extend selection expands macros and can totally panic r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 32 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 17 |
3 files changed, 24 insertions, 27 deletions
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 9f0ab2f1c..718b4def5 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -51,7 +51,7 @@ mod tests { | |||
51 | } | 51 | } |
52 | ", | 52 | ", |
53 | ); | 53 | ); |
54 | let r = analysis.extend_selection(frange); | 54 | let r = analysis.extend_selection(frange).unwrap(); |
55 | assert_eq!(r, TextRange::from_to(51.into(), 56.into())); | 55 | assert_eq!(r, TextRange::from_to(51.into(), 56.into())); |
56 | } | 56 | } |
57 | } | 57 | } |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 33bef178a..919d248e2 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -299,7 +299,7 @@ impl Analysis { | |||
299 | } | 299 | } |
300 | 300 | ||
301 | /// Gets the syntax tree of the file. | 301 | /// Gets the syntax tree of the file. |
302 | pub fn file_syntax(&self, file_id: FileId) -> TreeArc<SourceFile> { | 302 | pub fn parse(&self, file_id: FileId) -> TreeArc<SourceFile> { |
303 | self.db.source_file(file_id).clone() | 303 | self.db.source_file(file_id).clone() |
304 | } | 304 | } |
305 | 305 | ||
@@ -310,14 +310,15 @@ impl Analysis { | |||
310 | } | 310 | } |
311 | 311 | ||
312 | /// Selects the next syntactic nodes encopasing the range. | 312 | /// Selects the next syntactic nodes encopasing the range. |
313 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { | 313 | pub fn extend_selection(&self, frange: FileRange) -> Cancelable<TextRange> { |
314 | extend_selection::extend_selection(&self.db, frange) | 314 | self.with_db(|db| extend_selection::extend_selection(db, frange)) |
315 | } | 315 | } |
316 | 316 | ||
317 | /// Returns position of the mathcing brace (all types of braces are | 317 | /// Returns position of the mathcing brace (all types of braces are |
318 | /// supported). | 318 | /// supported). |
319 | pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { | 319 | pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> { |
320 | ra_ide_api_light::matching_brace(file, offset) | 320 | let file = self.db.source_file(position.file_id); |
321 | ra_ide_api_light::matching_brace(&file, position.offset) | ||
321 | } | 322 | } |
322 | 323 | ||
323 | /// Returns a syntax tree represented as `String`, for debug purposes. | 324 | /// Returns a syntax tree represented as `String`, for debug purposes. |
@@ -388,8 +389,7 @@ impl Analysis { | |||
388 | &self, | 389 | &self, |
389 | position: FilePosition, | 390 | position: FilePosition, |
390 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { | 391 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { |
391 | self.db | 392 | self.with_db(|db| goto_definition::goto_definition(db, position)) |
392 | .catch_canceled(|db| goto_definition::goto_definition(db, position)) | ||
393 | } | 393 | } |
394 | 394 | ||
395 | /// Finds all usages of the reference at point. | 395 | /// Finds all usages of the reference at point. |
@@ -404,8 +404,7 @@ impl Analysis { | |||
404 | 404 | ||
405 | /// Computes parameter information for the given call expression. | 405 | /// Computes parameter information for the given call expression. |
406 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 406 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { |
407 | self.db | 407 | self.with_db(|db| call_info::call_info(db, position)) |
408 | .catch_canceled(|db| call_info::call_info(db, position)) | ||
409 | } | 408 | } |
410 | 409 | ||
411 | /// Returns a `mod name;` declaration which created the current module. | 410 | /// Returns a `mod name;` declaration which created the current module. |
@@ -420,33 +419,28 @@ impl Analysis { | |||
420 | 419 | ||
421 | /// Returns the root file of the given crate. | 420 | /// Returns the root file of the given crate. |
422 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { | 421 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
423 | Ok(self.db.crate_graph().crate_root(crate_id)) | 422 | self.with_db(|db| db.crate_graph().crate_root(crate_id)) |
424 | } | 423 | } |
425 | 424 | ||
426 | /// Returns the set of possible targets to run for the current file. | 425 | /// Returns the set of possible targets to run for the current file. |
427 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { | 426 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { |
428 | self.db | 427 | self.with_db(|db| runnables::runnables(db, file_id)) |
429 | .catch_canceled(|db| runnables::runnables(db, file_id)) | ||
430 | } | 428 | } |
431 | 429 | ||
432 | /// Computes syntax highlighting for the given file. | 430 | /// Computes syntax highlighting for the given file. |
433 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 431 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
434 | self.db | 432 | self.with_db(|db| syntax_highlighting::highlight(db, file_id)) |
435 | .catch_canceled(|db| syntax_highlighting::highlight(db, file_id)) | ||
436 | } | 433 | } |
437 | 434 | ||
438 | /// Computes completions at the given position. | 435 | /// Computes completions at the given position. |
439 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 436 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
440 | let completions = self | 437 | self.with_db(|db| completion::completions(db, position).map(Into::into)) |
441 | .db | ||
442 | .catch_canceled(|db| completion::completions(db, position))?; | ||
443 | Ok(completions.map(|it| it.into())) | ||
444 | } | 438 | } |
445 | 439 | ||
446 | /// Computes assists (aks code actons aka intentions) for the given | 440 | /// Computes assists (aks code actons aka intentions) for the given |
447 | /// position. | 441 | /// position. |
448 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { | 442 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { |
449 | Ok(self.db.assists(frange)) | 443 | self.with_db(|db| db.assists(frange)) |
450 | } | 444 | } |
451 | 445 | ||
452 | /// Computes the set of diagnostics for the given file. | 446 | /// Computes the set of diagnostics for the given file. |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 8f9db68a2..02393f728 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -8,7 +8,7 @@ use lsp_types::{ | |||
8 | WorkspaceEdit | 8 | WorkspaceEdit |
9 | }; | 9 | }; |
10 | use ra_ide_api::{ | 10 | use ra_ide_api::{ |
11 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, | 11 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, |
12 | }; | 12 | }; |
13 | use ra_syntax::{AstNode, TextUnit}; | 13 | use ra_syntax::{AstNode, TextUnit}; |
14 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
@@ -40,9 +40,13 @@ pub fn handle_extend_selection( | |||
40 | .into_iter() | 40 | .into_iter() |
41 | .map_conv_with(&line_index) | 41 | .map_conv_with(&line_index) |
42 | .map(|range| FileRange { file_id, range }) | 42 | .map(|range| FileRange { file_id, range }) |
43 | .map(|frange| world.analysis().extend_selection(frange)) | 43 | .map(|frange| { |
44 | .map_conv_with(&line_index) | 44 | world |
45 | .collect(); | 45 | .analysis() |
46 | .extend_selection(frange) | ||
47 | .map(|it| it.conv_with(&line_index)) | ||
48 | }) | ||
49 | .collect::<Cancelable<Vec<_>>>()?; | ||
46 | Ok(req::ExtendSelectionResult { selections }) | 50 | Ok(req::ExtendSelectionResult { selections }) |
47 | } | 51 | } |
48 | 52 | ||
@@ -51,7 +55,6 @@ pub fn handle_find_matching_brace( | |||
51 | params: req::FindMatchingBraceParams, | 55 | params: req::FindMatchingBraceParams, |
52 | ) -> Result<Vec<Position>> { | 56 | ) -> Result<Vec<Position>> { |
53 | let file_id = params.text_document.try_conv_with(&world)?; | 57 | let file_id = params.text_document.try_conv_with(&world)?; |
54 | let file = world.analysis().file_syntax(file_id); | ||
55 | let line_index = world.analysis().file_line_index(file_id); | 58 | let line_index = world.analysis().file_line_index(file_id); |
56 | let res = params | 59 | let res = params |
57 | .offsets | 60 | .offsets |
@@ -60,7 +63,7 @@ pub fn handle_find_matching_brace( | |||
60 | .map(|offset| { | 63 | .map(|offset| { |
61 | world | 64 | world |
62 | .analysis() | 65 | .analysis() |
63 | .matching_brace(&file, offset) | 66 | .matching_brace(FilePosition { file_id, offset }) |
64 | .unwrap_or(offset) | 67 | .unwrap_or(offset) |
65 | }) | 68 | }) |
66 | .map_conv_with(&line_index) | 69 | .map_conv_with(&line_index) |
@@ -315,7 +318,7 @@ pub fn handle_completion( | |||
315 | let mut res = false; | 318 | let mut res = false; |
316 | if let Some(ctx) = params.context { | 319 | if let Some(ctx) = params.context { |
317 | if ctx.trigger_character.unwrap_or_default() == ":" { | 320 | if ctx.trigger_character.unwrap_or_default() == ":" { |
318 | let source_file = world.analysis().file_syntax(position.file_id); | 321 | let source_file = world.analysis().parse(position.file_id); |
319 | let syntax = source_file.syntax(); | 322 | let syntax = source_file.syntax(); |
320 | let text = syntax.text(); | 323 | let text = syntax.text(); |
321 | if let Some(next_char) = text.char_at(position.offset) { | 324 | if let Some(next_char) = text.char_at(position.offset) { |