diff --git a/Cargo.lock b/Cargo.lock
index dcf953a4f0724e..c1dd9a9c52e29e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3509,6 +3509,7 @@ dependencies = [
"ruff_diagnostics",
"ruff_formatter",
"ruff_linter",
+ "ruff_markdown",
"ruff_notebook",
"ruff_python_ast",
"ruff_python_codegen",
diff --git a/crates/ruff_server/Cargo.toml b/crates/ruff_server/Cargo.toml
index 06cc0c68156605..ac23cf6416991a 100644
--- a/crates/ruff_server/Cargo.toml
+++ b/crates/ruff_server/Cargo.toml
@@ -17,6 +17,7 @@ ruff_db = { workspace = true }
ruff_diagnostics = { workspace = true }
ruff_formatter = { workspace = true }
ruff_linter = { workspace = true }
+ruff_markdown = { workspace = true }
ruff_notebook = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_python_codegen = { workspace = true }
diff --git a/crates/ruff_server/src/edit/text_document.rs b/crates/ruff_server/src/edit/text_document.rs
index e5d00ff0cf1761..b78f1c031c3686 100644
--- a/crates/ruff_server/src/edit/text_document.rs
+++ b/crates/ruff_server/src/edit/text_document.rs
@@ -27,6 +27,7 @@ pub struct TextDocument {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum LanguageId {
Python,
+ Markdown,
Other,
}
@@ -34,6 +35,7 @@ impl From<&str> for LanguageId {
fn from(language_id: &str) -> Self {
match language_id {
"python" => Self::Python,
+ "markdown" => Self::Markdown,
_ => Self::Other,
}
}
diff --git a/crates/ruff_server/src/fix.rs b/crates/ruff_server/src/fix.rs
index 0c910f67553d9e..ab6a527f97287a 100644
--- a/crates/ruff_server/src/fix.rs
+++ b/crates/ruff_server/src/fix.rs
@@ -1,5 +1,6 @@
use std::borrow::Cow;
+use ruff_python_ast::SourceType;
use rustc_hash::FxHashMap;
use crate::{
@@ -53,7 +54,9 @@ pub(crate) fn fix_all(
None
};
- let source_type = query.source_type();
+ let SourceType::Python(source_type) = query.source_type() else {
+ return Ok(Fixes::default());
+ };
// We need to iteratively apply all safe fixes onto a single file and then
// create a diff between the modified file and the original source to use as a single workspace
diff --git a/crates/ruff_server/src/format.rs b/crates/ruff_server/src/format.rs
index 38455514a99352..e8e8efbf5ca578 100644
--- a/crates/ruff_server/src/format.rs
+++ b/crates/ruff_server/src/format.rs
@@ -5,7 +5,8 @@ use std::process::{Command, Stdio};
use anyhow::Context;
use ruff_formatter::{FormatOptions, PrintedRange};
-use ruff_python_ast::PySourceType;
+use ruff_markdown::{MarkdownResult, format_code_blocks};
+use ruff_python_ast::{PySourceType, SourceType};
use ruff_python_formatter::{FormatModuleError, PyFormatOptions, format_module_source};
use ruff_source_file::LineIndex;
use ruff_text_size::TextRange;
@@ -30,7 +31,7 @@ pub(crate) enum FormatBackend {
pub(crate) fn format(
document: &TextDocument,
- source_type: PySourceType,
+ source_type: SourceType,
formatter_settings: &FormatterSettings,
path: &Path,
backend: FormatBackend,
@@ -44,58 +45,103 @@ pub(crate) fn format(
/// Format using the built-in Ruff formatter.
fn format_internal(
document: &TextDocument,
- source_type: PySourceType,
+ source_type: SourceType,
formatter_settings: &FormatterSettings,
path: &Path,
) -> crate::Result