...

Source file src/golang.org/x/tools/go/analysis/diagnostic.go

Documentation: golang.org/x/tools/go/analysis

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package analysis
     6  
     7  import "go/token"
     8  
     9  // A Diagnostic is a message associated with a source location or range.
    10  //
    11  // An Analyzer may return a variety of diagnostics; the optional Category,
    12  // which should be a constant, may be used to classify them.
    13  // It is primarily intended to make it easy to look up documentation.
    14  //
    15  // If End is provided, the diagnostic is specified to apply to the range between
    16  // Pos and End.
    17  type Diagnostic struct {
    18  	Pos      token.Pos
    19  	End      token.Pos // optional
    20  	Category string    // optional
    21  	Message  string
    22  
    23  	// SuggestedFixes contains suggested fixes for a diagnostic which can be used to perform
    24  	// edits to a file that address the diagnostic.
    25  	// TODO(matloob): Should multiple SuggestedFixes be allowed for a diagnostic?
    26  	// Diagnostics should not contain SuggestedFixes that overlap.
    27  	// Experimental: This API is experimental and may change in the future.
    28  	SuggestedFixes []SuggestedFix // optional
    29  
    30  	// Experimental: This API is experimental and may change in the future.
    31  	Related []RelatedInformation // optional
    32  }
    33  
    34  // RelatedInformation contains information related to a diagnostic.
    35  // For example, a diagnostic that flags duplicated declarations of a
    36  // variable may include one RelatedInformation per existing
    37  // declaration.
    38  type RelatedInformation struct {
    39  	Pos     token.Pos
    40  	End     token.Pos // optional
    41  	Message string
    42  }
    43  
    44  // A SuggestedFix is a code change associated with a Diagnostic that a user can choose
    45  // to apply to their code. Usually the SuggestedFix is meant to fix the issue flagged
    46  // by the diagnostic.
    47  // TextEdits for a SuggestedFix should not overlap. TextEdits for a SuggestedFix
    48  // should not contain edits for other packages.
    49  // Experimental: This API is experimental and may change in the future.
    50  type SuggestedFix struct {
    51  	// A description for this suggested fix to be shown to a user deciding
    52  	// whether to accept it.
    53  	Message   string
    54  	TextEdits []TextEdit
    55  }
    56  
    57  // A TextEdit represents the replacement of the code between Pos and End with the new text.
    58  // Each TextEdit should apply to a single file. End should not be earlier in the file than Pos.
    59  // Experimental: This API is experimental and may change in the future.
    60  type TextEdit struct {
    61  	// For a pure insertion, End can either be set to Pos or token.NoPos.
    62  	Pos     token.Pos
    63  	End     token.Pos
    64  	NewText []byte
    65  }
    66  

View as plain text