diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-28 16:17:19 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-28 16:17:19 +0000 |
commit | 7a268b9b9635425176f93d3c893fb5345e84e9ce (patch) | |
tree | 6ea69024cb22d3fc48a3b392a0185163fa452014 /crates/ra_analysis/src/imp.rs | |
parent | 9d6740a9c9ad2ca47c4885bd994f849e90bbef86 (diff) | |
parent | b911ee542b2f4d1cd62a655f24197856cd9b9097 (diff) |
Merge #350
350: Super simple macro support r=matklad a=matklad
Super simple support for macros, mostly for figuring out how to fit them into the current architecture. Expansion is hard-coded and string based (mid-term, we should try to copy-paste macro-by-example expander from rustc).
Ideally, we should handle
* highlighting inside the macro (done)
* extend selection inside the macro
* completion inside the macro
* indexing structs, produced by the macro
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index e6663810d..fcb4cd957 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -23,7 +23,7 @@ use crate::{ | |||
23 | AnalysisChange, | 23 | AnalysisChange, |
24 | Cancelable, | 24 | Cancelable, |
25 | completion::{CompletionItem, completions}, | 25 | completion::{CompletionItem, completions}, |
26 | CrateId, db, Diagnostic, FileId, FilePosition, FileSystemEdit, | 26 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, |
27 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, | 27 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, |
28 | symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase}, | 28 | symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase}, |
29 | }; | 29 | }; |
@@ -404,19 +404,21 @@ impl AnalysisImpl { | |||
404 | Ok(res) | 404 | Ok(res) |
405 | } | 405 | } |
406 | 406 | ||
407 | pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> { | 407 | pub fn assists(&self, frange: FileRange) -> Vec<SourceChange> { |
408 | let file = self.file_syntax(file_id); | 408 | let file = self.file_syntax(frange.file_id); |
409 | let offset = range.start(); | 409 | let offset = frange.range.start(); |
410 | let actions = vec![ | 410 | let actions = vec![ |
411 | ra_editor::flip_comma(&file, offset).map(|f| f()), | 411 | ra_editor::flip_comma(&file, offset).map(|f| f()), |
412 | ra_editor::add_derive(&file, offset).map(|f| f()), | 412 | ra_editor::add_derive(&file, offset).map(|f| f()), |
413 | ra_editor::add_impl(&file, offset).map(|f| f()), | 413 | ra_editor::add_impl(&file, offset).map(|f| f()), |
414 | ra_editor::make_pub_crate(&file, offset).map(|f| f()), | 414 | ra_editor::make_pub_crate(&file, offset).map(|f| f()), |
415 | ra_editor::introduce_variable(&file, range).map(|f| f()), | 415 | ra_editor::introduce_variable(&file, frange.range).map(|f| f()), |
416 | ]; | 416 | ]; |
417 | actions | 417 | actions |
418 | .into_iter() | 418 | .into_iter() |
419 | .filter_map(|local_edit| Some(SourceChange::from_local_edit(file_id, local_edit?))) | 419 | .filter_map(|local_edit| { |
420 | Some(SourceChange::from_local_edit(frange.file_id, local_edit?)) | ||
421 | }) | ||
420 | .collect() | 422 | .collect() |
421 | } | 423 | } |
422 | 424 | ||
@@ -487,13 +489,15 @@ impl AnalysisImpl { | |||
487 | Ok(None) | 489 | Ok(None) |
488 | } | 490 | } |
489 | 491 | ||
490 | pub fn type_of(&self, file_id: FileId, range: TextRange) -> Cancelable<Option<String>> { | 492 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
491 | let file = self.db.source_file(file_id); | 493 | let file = self.db.source_file(frange.file_id); |
492 | let syntax = file.syntax(); | 494 | let syntax = file.syntax(); |
493 | let node = find_covering_node(syntax, range); | 495 | let node = find_covering_node(syntax, frange.range); |
494 | let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast)); | 496 | let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast)); |
495 | let function = ctry!(source_binder::function_from_source( | 497 | let function = ctry!(source_binder::function_from_source( |
496 | &*self.db, file_id, parent_fn | 498 | &*self.db, |
499 | frange.file_id, | ||
500 | parent_fn | ||
497 | )?); | 501 | )?); |
498 | let infer = function.infer(&*self.db)?; | 502 | let infer = function.infer(&*self.db)?; |
499 | Ok(infer.type_of_node(node).map(|t| t.to_string())) | 503 | Ok(infer.type_of_node(node).map(|t| t.to_string())) |