aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs2
-rw-r--r--crates/ide/src/lib.rs6
-rw-r--r--crates/ide/src/syntax_highlighting/inject.rs10
3 files changed, 15 insertions, 3 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 9a883acb9..1c911a8b2 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -725,7 +725,7 @@ fn test_fn() {
725 expect![[r#" 725 expect![[r#"
726 [ 726 [
727 Diagnostic { 727 Diagnostic {
728 message: "unresolved macro call", 728 message: "unresolved macro `foo::bar!`",
729 range: 5..8, 729 range: 5..8,
730 severity: Error, 730 severity: Error,
731 fix: None, 731 fix: None,
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index b24c664ba..99e45633e 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -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>> {
diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs
index 04fafd244..855c7fba8 100644
--- a/crates/ide/src/syntax_highlighting/inject.rs
+++ b/crates/ide/src/syntax_highlighting/inject.rs
@@ -90,6 +90,13 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
90 "edition2021", 90 "edition2021",
91]; 91];
92 92
93fn is_rustdoc_fence_token(token: &str) -> bool {
94 if RUSTDOC_FENCE_TOKENS.contains(&token) {
95 return true;
96 }
97 token.starts_with('E') && token.len() == 5 && token[1..].parse::<u32>().is_ok()
98}
99
93/// Injection of syntax highlighting of doctests. 100/// Injection of syntax highlighting of doctests.
94pub(super) fn doc_comment( 101pub(super) fn doc_comment(
95 hl: &mut Highlights, 102 hl: &mut Highlights,
@@ -174,8 +181,7 @@ pub(super) fn doc_comment(
174 is_codeblock = !is_codeblock; 181 is_codeblock = !is_codeblock;
175 // Check whether code is rust by inspecting fence guards 182 // Check whether code is rust by inspecting fence guards
176 let guards = &line[idx + RUSTDOC_FENCE.len()..]; 183 let guards = &line[idx + RUSTDOC_FENCE.len()..];
177 let is_rust = 184 let is_rust = guards.split(',').all(|sub| is_rustdoc_fence_token(sub.trim()));
178 guards.split(',').all(|sub| RUSTDOC_FENCE_TOKENS.contains(&sub.trim()));
179 is_doctest = is_codeblock && is_rust; 185 is_doctest = is_codeblock && is_rust;
180 continue; 186 continue;
181 } 187 }