diff options
Diffstat (limited to 'crates/ide/src/lib.rs')
-rw-r--r-- | crates/ide/src/lib.rs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 3f73c0632..99e45633e 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -69,7 +69,7 @@ use crate::display::ToNav; | |||
69 | pub use crate::{ | 69 | pub use crate::{ |
70 | annotations::{Annotation, AnnotationConfig, AnnotationKind}, | 70 | annotations::{Annotation, AnnotationConfig, AnnotationKind}, |
71 | call_hierarchy::CallItem, | 71 | call_hierarchy::CallItem, |
72 | diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity}, | 72 | diagnostics::{Diagnostic, DiagnosticsConfig, Severity}, |
73 | display::navigation_target::NavigationTarget, | 73 | display::navigation_target::NavigationTarget, |
74 | expand_macro::ExpandedMacro, | 74 | expand_macro::ExpandedMacro, |
75 | file_structure::{StructureNode, StructureNodeKind}, | 75 | file_structure::{StructureNode, StructureNodeKind}, |
@@ -82,7 +82,7 @@ pub use crate::{ | |||
82 | references::{rename::RenameError, ReferenceSearchResult}, | 82 | references::{rename::RenameError, ReferenceSearchResult}, |
83 | runnables::{Runnable, RunnableKind, TestId}, | 83 | runnables::{Runnable, RunnableKind, TestId}, |
84 | syntax_highlighting::{ | 84 | syntax_highlighting::{ |
85 | tags::{Highlight, HlMod, HlMods, HlPunct, HlTag}, | 85 | tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag}, |
86 | HlRange, | 86 | HlRange, |
87 | }, | 87 | }, |
88 | }; | 88 | }; |
@@ -244,6 +244,12 @@ impl Analysis { | |||
244 | self.with_db(|db| db.parse(file_id).tree()) | 244 | self.with_db(|db| db.parse(file_id).tree()) |
245 | } | 245 | } |
246 | 246 | ||
247 | /// Returns true if this file belongs to an immutable library. | ||
248 | pub fn is_library_file(&self, file_id: FileId) -> Cancelable<bool> { | ||
249 | use ide_db::base_db::SourceDatabaseExt; | ||
250 | self.with_db(|db| db.source_root(db.file_source_root(file_id)).is_library) | ||
251 | } | ||
252 | |||
247 | /// Gets the file's `LineIndex`: data structure to convert between absolute | 253 | /// Gets the file's `LineIndex`: data structure to convert between absolute |
248 | /// offsets and line/column representation. | 254 | /// offsets and line/column representation. |
249 | pub fn file_line_index(&self, file_id: FileId) -> Cancelable<Arc<LineIndex>> { | 255 | pub fn file_line_index(&self, file_id: FileId) -> Cancelable<Arc<LineIndex>> { |
@@ -526,9 +532,39 @@ impl Analysis { | |||
526 | pub fn diagnostics( | 532 | pub fn diagnostics( |
527 | &self, | 533 | &self, |
528 | config: &DiagnosticsConfig, | 534 | config: &DiagnosticsConfig, |
535 | resolve: bool, | ||
529 | file_id: FileId, | 536 | file_id: FileId, |
530 | ) -> Cancelable<Vec<Diagnostic>> { | 537 | ) -> Cancelable<Vec<Diagnostic>> { |
531 | self.with_db(|db| diagnostics::diagnostics(db, config, file_id)) | 538 | self.with_db(|db| diagnostics::diagnostics(db, config, resolve, file_id)) |
539 | } | ||
540 | |||
541 | /// Convenience function to return assists + quick fixes for diagnostics | ||
542 | pub fn assists_with_fixes( | ||
543 | &self, | ||
544 | assist_config: &AssistConfig, | ||
545 | diagnostics_config: &DiagnosticsConfig, | ||
546 | resolve: bool, | ||
547 | frange: FileRange, | ||
548 | ) -> Cancelable<Vec<Assist>> { | ||
549 | let include_fixes = match &assist_config.allowed { | ||
550 | Some(it) => it.iter().any(|&it| it == AssistKind::None || it == AssistKind::QuickFix), | ||
551 | None => true, | ||
552 | }; | ||
553 | |||
554 | self.with_db(|db| { | ||
555 | let mut res = Assist::get(db, assist_config, resolve, frange); | ||
556 | ssr::add_ssr_assist(db, &mut res, resolve, frange); | ||
557 | |||
558 | if include_fixes { | ||
559 | res.extend( | ||
560 | diagnostics::diagnostics(db, diagnostics_config, resolve, frange.file_id) | ||
561 | .into_iter() | ||
562 | .filter_map(|it| it.fix) | ||
563 | .filter(|it| it.target.intersect(frange.range).is_some()), | ||
564 | ); | ||
565 | } | ||
566 | res | ||
567 | }) | ||
532 | } | 568 | } |
533 | 569 | ||
534 | /// Returns the edit required to rename reference at the position to the new | 570 | /// Returns the edit required to rename reference at the position to the new |