Skip to content

annotate-snippet emitter: Include suggestions in output #61809

Open
@phansch

Description

@phansch
Member

Part of #59346

In order for the new AnnotateSnippetEmitterWriter to include suggestions in the output, we essentially have to pass &db.suggestions to emit_messages_default and deal with a couple of edge-cases.

Relevant FIXME:

// FIXME(#59346): Collect suggestions (see emitter.rs)
let suggestions: &[_] = &[];

emitter.rs equivalent:

if let Some((sugg, rest)) = db.suggestions.split_first() {
if rest.is_empty() &&
// don't display multi-suggestions as labels
sugg.substitutions.len() == 1 &&
// don't display multipart suggestions as labels
sugg.substitutions[0].parts.len() == 1 &&
// don't display long messages as labels
sugg.msg.split_whitespace().count() < 10 &&
// don't display multiline suggestions as labels
!sugg.substitutions[0].parts[0].snippet.contains('\n') &&
// when this style is set we want the suggestion to be a message, not inline
sugg.style != SuggestionStyle::HideCodeAlways &&
// trivial suggestion for tooling's sake, never shown
sugg.style != SuggestionStyle::CompletelyHidden
{
let substitution = &sugg.substitutions[0].parts[0].snippet.trim();
let msg = if substitution.len() == 0 || sugg.style.hide_inline() {
// This substitution is only removal or we explicitly don't want to show the
// code inline, don't show it
format!("help: {}", sugg.msg)
} else {
format!("help: {}: `{}`", sugg.msg, substitution)
};
primary_span.push_span_label(sugg.substitutions[0].parts[0].span, msg);
} else {
// if there are multiple suggestions, print them all in full
// to be consistent. We could try to figure out if we can
// make one (or the first one) inline, but that would give
// undue importance to a semi-random suggestion
suggestions = &db.suggestions;
}
}

  • The tricky part is figuring out the first half of the conditional. We probably need it in the new emitter, too. Is it enough to just copy it over? Maybe extract that code so that the code is shared in both emitters?
  • Otherwise it's just passing &db.suggestions through
  • Should take into account the MAX_SUGGESTIONS value somewhere (add a UI test for this)

This issue has been assigned to @phansch via this comment.

Activity

phansch

phansch commented on Jun 13, 2019

@phansch
Author
changed the title [-]annotate_snippet emitter: Include suggestions in output[/-] [+]annotate-snippet emitter: Include suggestions in output[/+] on Jun 13, 2019
phansch

phansch commented on Jun 13, 2019

@phansch
Author
added
E-help-wantedCall for participation: Help is requested to fix this issue.
on Jun 13, 2019
phansch

phansch commented on Aug 31, 2019

@phansch
MemberAuthor

@rustbot claim

self-assigned this
on Aug 31, 2019
added 4 commits that reference this issue on Sep 1, 2019

Rollup merge of rust-lang#64058 - phansch:refactor_out_method, r=este…

be8d0cb

Rollup merge of rust-lang#64058 - phansch:refactor_out_method, r=este…

dd8d419

Rollup merge of rust-lang#64058 - phansch:refactor_out_method, r=este…

aa63cd9

Rollup merge of rust-lang#64058 - phansch:refactor_out_method, r=este…

586aeb4

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @crlf0710@phansch@rustbot

      Issue actions

        annotate-snippet emitter: Include suggestions in output · Issue #61809 · rust-lang/rust