@@ -19,12 +19,6 @@ class RuboCopDiagnostic
19
19
T ::Hash [ Symbol , Integer ] ,
20
20
)
21
21
22
- # Cache cops to attach URLs to diagnostics. Only built-in cops for now.
23
- COP_TO_DOC_URL = T . let (
24
- RuboCop ::Cop ::Registry . global . to_h ,
25
- T ::Hash [ String , [ T . class_of ( RuboCop ::Cop ::Base ) ] ] ,
26
- )
27
-
28
22
sig { params ( offense : RuboCop ::Cop ::Offense , uri : URI ::Generic ) . void }
29
23
def initialize ( offense , uri )
30
24
@offense = offense
@@ -53,16 +47,6 @@ def to_lsp_code_action
53
47
54
48
sig { returns ( Interface ::Diagnostic ) }
55
49
def to_lsp_diagnostic
56
- severity = RUBOCOP_TO_LSP_SEVERITY [ @offense . severity . name ]
57
- message = @offense . message
58
-
59
- message += "\n \n This offense is not auto-correctable.\n " unless @offense . correctable?
60
-
61
- cop = COP_TO_DOC_URL [ @offense . cop_name ] &.first
62
- if cop &.documentation_url
63
- code_description = { href : cop . documentation_url }
64
- end
65
-
66
50
Interface ::Diagnostic . new (
67
51
message : message ,
68
52
source : "RuboCop" ,
@@ -88,6 +72,24 @@ def to_lsp_diagnostic
88
72
89
73
private
90
74
75
+ sig { returns ( String ) }
76
+ def message
77
+ message = @offense . message
78
+ message += "\n \n This offense is not auto-correctable.\n " unless @offense . correctable?
79
+ message
80
+ end
81
+
82
+ sig { returns ( T . nilable ( Integer ) ) }
83
+ def severity
84
+ RUBOCOP_TO_LSP_SEVERITY [ @offense . severity . name ]
85
+ end
86
+
87
+ sig { returns ( T . nilable ( Interface ::CodeDescription ) ) }
88
+ def code_description
89
+ doc_url = RuboCopRunner . find_cop_by_name ( @offense . cop_name ) &.documentation_url
90
+ Interface ::CodeDescription . new ( href : doc_url ) if doc_url
91
+ end
92
+
91
93
sig { returns ( T ::Array [ Interface ::TextEdit ] ) }
92
94
def offense_replacements
93
95
@offense . corrector . as_replacements . map do |range , replacement |
0 commit comments