Auto merge of #40851 - oli-obk:multisugg, r=jonathandturner
Minimize single span suggestions into a label changes ``` 14 | println!("☃{}", tup[0]); | ^^^^^^ | help: to access tuple elements, use tuple indexing syntax as shown | println!("☃{}", tup.0); ``` into ``` 14 | println!("☃{}", tup[0]); | ^^^^^^ to access tuple elements, use `tup.0` ``` Also makes suggestions explicit in the backend in preparation of adding multiple suggestions to a single diagnostic. Currently that's already possible, but results in a full help message + modified code snippet per suggestion, and has no rate limit (might show 100+ suggestions).
This commit is contained in:
commit
33535afda4
20 changed files with 155 additions and 92 deletions
|
@ -22,8 +22,9 @@
|
|||
use codemap::{CodeMap, FilePathMapping};
|
||||
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
|
||||
use errors::registry::Registry;
|
||||
use errors::{DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion, CodeMapper};
|
||||
use errors::{Level, DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion, CodeMapper};
|
||||
use errors::emitter::Emitter;
|
||||
use errors::snippet::Style;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::io::{self, Write};
|
||||
|
@ -153,12 +154,21 @@ impl Diagnostic {
|
|||
fn from_diagnostic_builder(db: &DiagnosticBuilder,
|
||||
je: &JsonEmitter)
|
||||
-> Diagnostic {
|
||||
let sugg = db.suggestion.as_ref().map(|sugg| {
|
||||
SubDiagnostic {
|
||||
level: Level::Help,
|
||||
message: vec![(sugg.msg.clone(), Style::NoStyle)],
|
||||
span: MultiSpan::new(),
|
||||
render_span: Some(RenderSpan::Suggestion(sugg.clone())),
|
||||
}
|
||||
});
|
||||
let sugg = sugg.as_ref();
|
||||
Diagnostic {
|
||||
message: db.message(),
|
||||
code: DiagnosticCode::map_opt_string(db.code.clone(), je),
|
||||
level: db.level.to_str(),
|
||||
spans: DiagnosticSpan::from_multispan(&db.span, je),
|
||||
children: db.children.iter().map(|c| {
|
||||
children: db.children.iter().chain(sugg).map(|c| {
|
||||
Diagnostic::from_sub_diagnostic(c, je)
|
||||
}).collect(),
|
||||
rendered: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue