|
1 | 1 | use tower_lsp_server::lsp_types::{ |
2 | | - CodeAction, CodeActionKind, Diagnostic, NumberOrString, Position, Range, TextEdit, Uri, |
3 | | - WorkspaceEdit, |
| 2 | + CodeAction, CodeActionKind, Position, Range, TextEdit, Uri, WorkspaceEdit, |
4 | 3 | }; |
5 | 4 |
|
6 | 5 | use crate::linter::error_with_position::{DiagnosticReport, FixedContent, PossibleFixContent}; |
7 | 6 |
|
8 | 7 | pub const CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC: CodeActionKind = |
9 | 8 | CodeActionKind::new("source.fixAll.oxc"); |
10 | 9 |
|
11 | | -// TODO: Would be better if we had exact rule name from the diagnostic instead of having to parse it. |
12 | | -fn get_rule_name(diagnostic: &Diagnostic) -> Option<String> { |
13 | | - if let Some(NumberOrString::String(code)) = &diagnostic.code { |
14 | | - let open_paren = code.chars().position(|c| c == '(')?; |
15 | | - let close_paren = code.chars().position(|c| c == ')')?; |
16 | | - |
17 | | - return Some(code[(open_paren + 1)..close_paren].to_string()); |
18 | | - } |
19 | | - |
20 | | - None |
21 | | -} |
22 | | - |
23 | 10 | fn fix_content_to_code_action( |
24 | 11 | fixed_content: &FixedContent, |
25 | 12 | uri: &Uri, |
@@ -123,7 +110,7 @@ pub fn apply_all_fix_code_action<'a>( |
123 | 110 | } |
124 | 111 |
|
125 | 112 | pub fn ignore_this_line_code_action(report: &DiagnosticReport, uri: &Uri) -> CodeAction { |
126 | | - let rule_name = get_rule_name(&report.diagnostic); |
| 113 | + let rule_name = report.rule_name.as_ref(); |
127 | 114 |
|
128 | 115 | // TODO: This CodeAction doesn't support disabling multiple rules by name for a given line. |
129 | 116 | // To do that, we need to read `report.diagnostic.range.start.line` and check if a disable comment already exists. |
@@ -168,7 +155,7 @@ pub fn ignore_this_line_code_action(report: &DiagnosticReport, uri: &Uri) -> Cod |
168 | 155 | } |
169 | 156 |
|
170 | 157 | pub fn ignore_this_rule_code_action(report: &DiagnosticReport, uri: &Uri) -> CodeAction { |
171 | | - let rule_name = get_rule_name(&report.diagnostic); |
| 158 | + let rule_name = report.rule_name.as_ref(); |
172 | 159 |
|
173 | 160 | CodeAction { |
174 | 161 | title: rule_name.as_ref().map_or_else( |
|
0 commit comments