You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

diagnostic.go 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // Experimental: This API is experimental and may change in the future.
  23. Related []RelatedInformation // optional
  24. }
  25. // RelatedInformation contains information related to a diagnostic.
  26. // For example, a diagnostic that flags duplicated declarations of a
  27. // variable may include one RelatedInformation per existing
  28. // declaration.
  29. type RelatedInformation struct {
  30. Pos token.Pos
  31. End token.Pos
  32. Message string
  33. }
  34. // A SuggestedFix is a code change associated with a Diagnostic that a user can choose
  35. // to apply to their code. Usually the SuggestedFix is meant to fix the issue flagged
  36. // by the diagnostic.
  37. // TextEdits for a SuggestedFix should not overlap. TextEdits for a SuggestedFix
  38. // should not contain edits for other packages.
  39. // Experimental: This API is experimental and may change in the future.
  40. type SuggestedFix struct {
  41. // A description for this suggested fix to be shown to a user deciding
  42. // whether to accept it.
  43. Message string
  44. TextEdits []TextEdit
  45. }
  46. // A TextEdit represents the replacement of the code between Pos and End with the new text.
  47. // Each TextEdit should apply to a single file. End should not be earlier in the file than Pos.
  48. // Experimental: This API is experimental and may change in the future.
  49. type TextEdit struct {
  50. // For a pure insertion, End can either be set to Pos or token.NoPos.
  51. Pos token.Pos
  52. End token.Pos
  53. NewText []byte
  54. }