Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions apps/oxlint/src/lsp/error_with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,28 @@ pub fn message_to_lsp_diagnostic(
.and_then(|url| url.parse().ok())
.map(|href| CodeDescription { href });

let diagnostic_message = match &message.error.help {
Some(help) => {
let main_msg = &message.error.message;
let mut msg = String::with_capacity(main_msg.len() + help.len() + 7);
msg.push_str(main_msg);
msg.push_str("\nhelp: ");
msg.push_str(help);
msg
}
None => message.error.message.to_string(),
};
let mut diagnostic_message = String::with_capacity(
message.error.message.len()
+ message.error.help.as_ref().map_or(0, |h| h.len() + 7) // "help: " prefix
+ message.error.note.as_ref().map_or(0, |n| n.len() + 7), // "note: " prefix
);

diagnostic_message.push_str(&message.error.message);
if let Some(help) = &message.error.help {
diagnostic_message.push_str("\nhelp: ");
diagnostic_message.push_str(help);
}

if let Some(note) = &message.error.note {
diagnostic_message.push_str("\nnote: ");
diagnostic_message.push_str(note);
}

// 1) Use `fixed_content.message` if it exists
// 2) Try to parse the report diagnostic message
// 3) Fallback to "Fix this problem"
let alternative_fix_title: Cow<'static, str> =
if let Some(code) = diagnostic_message.split(':').next() {
if let Some(code) = message.error.message.split(':').next() {
format!("Fix this {code} problem").into()
} else {
std::borrow::Cow::Borrowed("Fix this problem")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ File URI: file://<variable>/fixtures/lsp/cross_module/dep-a.ts

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import."
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import.\nnote: These paths form a cycle:\n╭──▶ ./dep-b.ts (fixtures/lsp/cross_module/dep-b.ts)\n│ ⬇ imports\n│ ./dep-a.ts (fixtures/lsp/cross_module/dep-a.ts)\n╰─────────╯ imports the current file"
range: Range { start: Position { line: 1, character: 18 }, end: Position { line: 1, character: 30 } }
related_information[0].message: ""
related_information[0].location.uri: "file://<variable>/fixtures/lsp/cross_module/dep-a.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ File URI: file://<variable>/fixtures/lsp/cross_module_extended_config/dep-a.ts

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import."
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import.\nnote: These paths form a cycle:\n╭──▶ ./dep-b.ts (fixtures/lsp/cross_module_extended_config/dep-b.ts)\n│ ⬇ imports\n│ ./dep-a.ts (fixtures/lsp/cross_module_extended_config/dep-a.ts)\n╰─────────╯ imports the current file"
range: Range { start: Position { line: 1, character: 18 }, end: Position { line: 1, character: 30 } }
related_information[0].message: ""
related_information[0].location.uri: "file://<variable>/fixtures/lsp/cross_module_extended_config/dep-a.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ File URI: file://<variable>/fixtures/lsp/cross_module_nested_config/folder/folde

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import."
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import.\nnote: These paths form a cycle:\n╭──▶ ./folder-dep-b.ts (fixtures/lsp/cross_module_nested_config/folder/folder-dep-b.ts)\n│ ⬇ imports\n│ ./folder-dep-a.ts (fixtures/lsp/cross_module_nested_config/folder/folder-dep-a.ts)\n╰─────────╯ imports the current file"
range: Range { start: Position { line: 1, character: 18 }, end: Position { line: 1, character: 37 } }
related_information[0].message: ""
related_information[0].location.uri: "file://<variable>/fixtures/lsp/cross_module_nested_config/folder/folder-dep-a.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ File URI: file://<variable>/fixtures/lsp/ts_path_alias/deep/src/dep-a.ts

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import."
message: "Dependency cycle detected\nhelp: Refactor to remove the cycle. Consider extracting shared code into a separate module that both files can import.\nnote: These paths form a cycle:\n╭──▶ @/dep-b (fixtures/lsp/ts_path_alias/deep/src/dep-b.ts)\n│ ⬇ imports\n│ ./dep-a.ts (fixtures/lsp/ts_path_alias/deep/src/dep-a.ts)\n╰─────────╯ imports the current file"
range: Range { start: Position { line: 1, character: 18 }, end: Position { line: 1, character: 27 } }
related_information[0].message: ""
related_information[0].location.uri: "file://<variable>/fixtures/lsp/ts_path_alias/deep/src/dep-a.ts"
Expand Down
Loading