diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 26 | ||||
-rw-r--r-- | crates/ra_ide/src/display.rs | 13 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 5 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 6 |
5 files changed, 29 insertions, 29 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 6eafdc8f6..0f8522021 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -4,6 +4,7 @@ use std::any::Any; | |||
4 | 4 | ||
5 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; | 5 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; |
6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; | 6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; |
7 | use stdx::format_to; | ||
7 | 8 | ||
8 | pub use hir_def::diagnostics::UnresolvedModule; | 9 | pub use hir_def::diagnostics::UnresolvedModule; |
9 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; | 10 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; |
@@ -37,12 +38,11 @@ pub struct MissingFields { | |||
37 | 38 | ||
38 | impl Diagnostic for MissingFields { | 39 | impl Diagnostic for MissingFields { |
39 | fn message(&self) -> String { | 40 | fn message(&self) -> String { |
40 | use std::fmt::Write; | 41 | let mut buf = String::from("Missing structure fields:\n"); |
41 | let mut message = String::from("Missing structure fields:\n"); | ||
42 | for field in &self.missed_fields { | 42 | for field in &self.missed_fields { |
43 | writeln!(message, "- {}", field).unwrap(); | 43 | format_to!(buf, "- {}", field); |
44 | } | 44 | } |
45 | message | 45 | buf |
46 | } | 46 | } |
47 | fn source(&self) -> InFile<SyntaxNodePtr> { | 47 | fn source(&self) -> InFile<SyntaxNodePtr> { |
48 | InFile { file_id: self.file, value: self.field_list.into() } | 48 | InFile { file_id: self.file, value: self.field_list.into() } |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 7e9547340..027e5a8f8 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -7,7 +7,6 @@ mod traits; | |||
7 | mod method_resolution; | 7 | mod method_resolution; |
8 | mod macros; | 8 | mod macros; |
9 | 9 | ||
10 | use std::fmt::Write; | ||
11 | use std::sync::Arc; | 10 | use std::sync::Arc; |
12 | 11 | ||
13 | use hir_def::{ | 12 | use hir_def::{ |
@@ -26,6 +25,7 @@ use ra_syntax::{ | |||
26 | algo, | 25 | algo, |
27 | ast::{self, AstNode}, | 26 | ast::{self, AstNode}, |
28 | }; | 27 | }; |
28 | use stdx::format_to; | ||
29 | 29 | ||
30 | use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResult}; | 30 | use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResult}; |
31 | 31 | ||
@@ -63,7 +63,7 @@ fn infer(ra_fixture: &str) -> String { | |||
63 | fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | 63 | fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { |
64 | let (db, file_id) = TestDB::with_single_file(content); | 64 | let (db, file_id) = TestDB::with_single_file(content); |
65 | 65 | ||
66 | let mut acc = String::new(); | 66 | let mut buf = String::new(); |
67 | 67 | ||
68 | let mut infer_def = |inference_result: Arc<InferenceResult>, | 68 | let mut infer_def = |inference_result: Arc<InferenceResult>, |
69 | body_source_map: Arc<BodySourceMap>| { | 69 | body_source_map: Arc<BodySourceMap>| { |
@@ -106,15 +106,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
106 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) | 106 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) |
107 | }; | 107 | }; |
108 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; | 108 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; |
109 | writeln!( | 109 | format_to!( |
110 | acc, | 110 | buf, |
111 | "{}{} '{}': {}", | 111 | "{}{} '{}': {}\n", |
112 | macro_prefix, | 112 | macro_prefix, |
113 | range, | 113 | range, |
114 | ellipsize(text, 15), | 114 | ellipsize(text, 15), |
115 | ty.display(&db) | 115 | ty.display(&db) |
116 | ) | 116 | ); |
117 | .unwrap(); | ||
118 | } | 117 | } |
119 | if include_mismatches { | 118 | if include_mismatches { |
120 | mismatches.sort_by_key(|(src_ptr, _)| { | 119 | mismatches.sort_by_key(|(src_ptr, _)| { |
@@ -123,15 +122,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
123 | for (src_ptr, mismatch) in &mismatches { | 122 | for (src_ptr, mismatch) in &mismatches { |
124 | let range = src_ptr.value.range(); | 123 | let range = src_ptr.value.range(); |
125 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; | 124 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; |
126 | writeln!( | 125 | format_to!( |
127 | acc, | 126 | buf, |
128 | "{}{}: expected {}, got {}", | 127 | "{}{}: expected {}, got {}\n", |
129 | macro_prefix, | 128 | macro_prefix, |
130 | range, | 129 | range, |
131 | mismatch.expected.display(&db), | 130 | mismatch.expected.display(&db), |
132 | mismatch.actual.display(&db), | 131 | mismatch.actual.display(&db), |
133 | ) | 132 | ); |
134 | .unwrap(); | ||
135 | } | 133 | } |
136 | } | 134 | } |
137 | }; | 135 | }; |
@@ -158,8 +156,8 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
158 | infer_def(infer, source_map); | 156 | infer_def(infer, source_map); |
159 | } | 157 | } |
160 | 158 | ||
161 | acc.truncate(acc.trim_end().len()); | 159 | buf.truncate(buf.trim_end().len()); |
162 | acc | 160 | buf |
163 | } | 161 | } |
164 | 162 | ||
165 | fn visit_module( | 163 | fn visit_module( |
diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index c395057a7..722092de9 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs | |||
@@ -6,12 +6,13 @@ mod navigation_target; | |||
6 | mod structure; | 6 | mod structure; |
7 | mod short_label; | 7 | mod short_label; |
8 | 8 | ||
9 | use std::fmt::{Display, Write}; | 9 | use std::fmt::Display; |
10 | 10 | ||
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
12 | ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, | 12 | ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, |
13 | SyntaxKind::{ATTR, COMMENT}, | 13 | SyntaxKind::{ATTR, COMMENT}, |
14 | }; | 14 | }; |
15 | use stdx::format_to; | ||
15 | 16 | ||
16 | pub use function_signature::FunctionSignature; | 17 | pub use function_signature::FunctionSignature; |
17 | pub use navigation_target::NavigationTarget; | 18 | pub use navigation_target::NavigationTarget; |
@@ -78,18 +79,18 @@ pub(crate) fn rust_code_markup_with_doc( | |||
78 | doc: Option<&str>, | 79 | doc: Option<&str>, |
79 | mod_path: Option<&str>, | 80 | mod_path: Option<&str>, |
80 | ) -> String { | 81 | ) -> String { |
81 | let mut markup = "```rust\n".to_owned(); | 82 | let mut buf = "```rust\n".to_owned(); |
82 | 83 | ||
83 | if let Some(mod_path) = mod_path { | 84 | if let Some(mod_path) = mod_path { |
84 | if !mod_path.is_empty() { | 85 | if !mod_path.is_empty() { |
85 | write!(markup, "{}\n", mod_path).unwrap(); | 86 | format_to!(buf, "{}\n", mod_path); |
86 | } | 87 | } |
87 | } | 88 | } |
88 | write!(markup, "{}\n```", code).unwrap(); | 89 | format_to!(buf, "{}\n```", code); |
89 | 90 | ||
90 | if let Some(doc) = doc { | 91 | if let Some(doc) = doc { |
91 | write!(markup, "\n\n{}", doc).unwrap(); | 92 | format_to!(buf, "\n\n{}", doc); |
92 | } | 93 | } |
93 | 94 | ||
94 | markup | 95 | buf |
95 | } | 96 | } |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 27459be8c..75cf2dae5 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Fully type-check project and print various stats, like the number of type | 1 | //! Fully type-check project and print various stats, like the number of type |
2 | //! errors. | 2 | //! errors. |
3 | 3 | ||
4 | use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; | 4 | use std::{collections::HashSet, path::Path, time::Instant}; |
5 | 5 | ||
6 | use hir::{ | 6 | use hir::{ |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 7 | db::{AstDatabase, DefDatabase, HirDatabase}, |
@@ -13,6 +13,7 @@ use itertools::Itertools; | |||
13 | use ra_db::SourceDatabaseExt; | 13 | use ra_db::SourceDatabaseExt; |
14 | use ra_syntax::AstNode; | 14 | use ra_syntax::AstNode; |
15 | use rand::{seq::SliceRandom, thread_rng}; | 15 | use rand::{seq::SliceRandom, thread_rng}; |
16 | use stdx::format_to; | ||
16 | 17 | ||
17 | use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; | 18 | use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; |
18 | 19 | ||
@@ -128,7 +129,7 @@ pub fn analysis_stats( | |||
128 | let original_file = src.file_id.original_file(db); | 129 | let original_file = src.file_id.original_file(db); |
129 | let path = db.file_relative_path(original_file); | 130 | let path = db.file_relative_path(original_file); |
130 | let syntax_range = src.value.syntax().text_range(); | 131 | let syntax_range = src.value.syntax().text_range(); |
131 | write!(msg, " ({:?} {})", path, syntax_range).unwrap(); | 132 | format_to!(msg, " ({:?} {})", path, syntax_range); |
132 | } | 133 | } |
133 | if verbosity.is_spammy() { | 134 | if verbosity.is_spammy() { |
134 | bar.println(msg.to_string()); | 135 | bar.println(msg.to_string()); |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 1033d6de9..12f8ca297 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -3,7 +3,6 @@ | |||
3 | //! `ra_ide` crate. | 3 | //! `ra_ide` crate. |
4 | 4 | ||
5 | use std::{ | 5 | use std::{ |
6 | fmt::Write as _, | ||
7 | io::Write as _, | 6 | io::Write as _, |
8 | process::{self, Stdio}, | 7 | process::{self, Stdio}, |
9 | }; | 8 | }; |
@@ -28,6 +27,7 @@ use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; | |||
28 | use rustc_hash::FxHashMap; | 27 | use rustc_hash::FxHashMap; |
29 | use serde::{Deserialize, Serialize}; | 28 | use serde::{Deserialize, Serialize}; |
30 | use serde_json::to_value; | 29 | use serde_json::to_value; |
30 | use stdx::format_to; | ||
31 | 31 | ||
32 | use crate::{ | 32 | use crate::{ |
33 | cargo_target_spec::CargoTargetSpec, | 33 | cargo_target_spec::CargoTargetSpec, |
@@ -46,11 +46,11 @@ use crate::{ | |||
46 | pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> { | 46 | pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> { |
47 | let _p = profile("handle_analyzer_status"); | 47 | let _p = profile("handle_analyzer_status"); |
48 | let mut buf = world.status(); | 48 | let mut buf = world.status(); |
49 | writeln!(buf, "\n\nrequests:").unwrap(); | 49 | format_to!(buf, "\n\nrequests:"); |
50 | let requests = world.latest_requests.read(); | 50 | let requests = world.latest_requests.read(); |
51 | for (is_last, r) in requests.iter() { | 51 | for (is_last, r) in requests.iter() { |
52 | let mark = if is_last { "*" } else { " " }; | 52 | let mark = if is_last { "*" } else { " " }; |
53 | writeln!(buf, "{}{:4} {:<36}{}ms", mark, r.id, r.method, r.duration.as_millis()).unwrap(); | 53 | format_to!(buf, "{}{:4} {:<36}{}ms", mark, r.id, r.method, r.duration.as_millis()); |
54 | } | 54 | } |
55 | Ok(buf) | 55 | Ok(buf) |
56 | } | 56 | } |