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/lib.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/lib.rs')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 65c3eb3ec..67b1c1482 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -16,6 +16,10 @@ mod completion; | |||
16 | mod symbol_index; | 16 | mod symbol_index; |
17 | pub mod mock_analysis; | 17 | pub mod mock_analysis; |
18 | 18 | ||
19 | mod extend_selection; | ||
20 | mod syntax_highlighting; | ||
21 | mod macros; | ||
22 | |||
19 | use std::{fmt, sync::Arc}; | 23 | use std::{fmt, sync::Arc}; |
20 | 24 | ||
21 | use rustc_hash::FxHashMap; | 25 | use rustc_hash::FxHashMap; |
@@ -37,7 +41,7 @@ pub use ra_editor::{ | |||
37 | pub use hir::FnSignatureInfo; | 41 | pub use hir::FnSignatureInfo; |
38 | 42 | ||
39 | pub use ra_db::{ | 43 | pub use ra_db::{ |
40 | Canceled, Cancelable, FilePosition, | 44 | Canceled, Cancelable, FilePosition, FileRange, |
41 | CrateGraph, CrateId, SourceRootId, FileId | 45 | CrateGraph, CrateId, SourceRootId, FileId |
42 | }; | 46 | }; |
43 | 47 | ||
@@ -276,8 +280,8 @@ impl Analysis { | |||
276 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { | 280 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { |
277 | self.imp.file_line_index(file_id) | 281 | self.imp.file_line_index(file_id) |
278 | } | 282 | } |
279 | pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange { | 283 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { |
280 | ra_editor::extend_selection(file, range).unwrap_or(range) | 284 | extend_selection::extend_selection(&self.imp.db, frange) |
281 | } | 285 | } |
282 | pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { | 286 | pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { |
283 | ra_editor::matching_brace(file, offset) | 287 | ra_editor::matching_brace(file, offset) |
@@ -286,9 +290,9 @@ impl Analysis { | |||
286 | let file = self.imp.file_syntax(file_id); | 290 | let file = self.imp.file_syntax(file_id); |
287 | ra_editor::syntax_tree(&file) | 291 | ra_editor::syntax_tree(&file) |
288 | } | 292 | } |
289 | pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange { | 293 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { |
290 | let file = self.imp.file_syntax(file_id); | 294 | let file = self.imp.file_syntax(frange.file_id); |
291 | SourceChange::from_local_edit(file_id, ra_editor::join_lines(&file, range)) | 295 | SourceChange::from_local_edit(frange.file_id, ra_editor::join_lines(&file, frange.range)) |
292 | } | 296 | } |
293 | pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { | 297 | pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { |
294 | let file = self.imp.file_syntax(position.file_id); | 298 | let file = self.imp.file_syntax(position.file_id); |
@@ -340,14 +344,13 @@ impl Analysis { | |||
340 | Ok(ra_editor::runnables(&file)) | 344 | Ok(ra_editor::runnables(&file)) |
341 | } | 345 | } |
342 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 346 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
343 | let file = self.imp.file_syntax(file_id); | 347 | syntax_highlighting::highlight(&*self.imp.db, file_id) |
344 | Ok(ra_editor::highlight(&file)) | ||
345 | } | 348 | } |
346 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 349 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
347 | self.imp.completions(position) | 350 | self.imp.completions(position) |
348 | } | 351 | } |
349 | pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> { | 352 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { |
350 | Ok(self.imp.assists(file_id, range)) | 353 | Ok(self.imp.assists(frange)) |
351 | } | 354 | } |
352 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 355 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
353 | self.imp.diagnostics(file_id) | 356 | self.imp.diagnostics(file_id) |
@@ -358,8 +361,8 @@ impl Analysis { | |||
358 | ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { | 361 | ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { |
359 | self.imp.resolve_callable(position) | 362 | self.imp.resolve_callable(position) |
360 | } | 363 | } |
361 | pub fn type_of(&self, file_id: FileId, range: TextRange) -> Cancelable<Option<String>> { | 364 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
362 | self.imp.type_of(file_id, range) | 365 | self.imp.type_of(frange) |
363 | } | 366 | } |
364 | } | 367 | } |
365 | 368 | ||