diagnostic.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package analysis
  2. import "go/token"
  3. // A Diagnostic is a message associated with a source location or range.
  4. //
  5. // An Analyzer may return a variety of diagnostics; the optional Category,
  6. // which should be a constant, may be used to classify them.
  7. // It is primarily intended to make it easy to look up documentation.
  8. //
  9. // If End is provided, the diagnostic is specified to apply to the range between
  10. // Pos and End.
  11. type Diagnostic struct {
  12. Pos token.Pos
  13. End token.Pos // optional
  14. Category string // optional
  15. Message string
  16. // SuggestedFixes contains suggested fixes for a diagnostic which can be used to perform
  17. // edits to a file that address the diagnostic.
  18. // TODO(matloob): Should multiple SuggestedFixes be allowed for a diagnostic?
  19. // Diagnostics should not contain SuggestedFixes that overlap.
  20. // Experimental: This API is experimental and may change in the future.
  21. SuggestedFixes []SuggestedFix // optional
  22. }
  23. // A SuggestedFix is a code change associated with a Diagnostic that a user can choose
  24. // to apply to their code. Usually the SuggestedFix is meant to fix the issue flagged
  25. // by the diagnostic.
  26. // TextEdits for a SuggestedFix should not overlap. TextEdits for a SuggestedFix
  27. // should not contain edits for other packages.
  28. // Experimental: This API is experimental and may change in the future.
  29. type SuggestedFix struct {
  30. // A description for this suggested fix to be shown to a user deciding
  31. // whether to accept it.
  32. Message string
  33. TextEdits []TextEdit
  34. }
  35. // A TextEdit represents the replacement of the code between Pos and End with the new text.
  36. // Each TextEdit should apply to a single file. End should not be earlier in the file than Pos.
  37. // Experimental: This API is experimental and may change in the future.
  38. type TextEdit struct {
  39. // For a pure insertion, End can either be set to Pos or token.NoPos.
  40. Pos token.Pos
  41. End token.Pos
  42. NewText []byte
  43. }