Execute the resolved formatting strategy and return `TextEdit`s. This is the main entry point called by the `formatting()` handler.
(
strategy: &FormattingStrategy,
content: &str,
file_path: &Path,
config: &FormattingConfig,
php_version: crate::types::PhpVersion,
)
| 265 | /// |
| 266 | /// This is the main entry point called by the `formatting()` handler. |
| 267 | pub(crate) fn execute_strategy( |
| 268 | strategy: &FormattingStrategy, |
| 269 | content: &str, |
| 270 | file_path: &Path, |
| 271 | config: &FormattingConfig, |
| 272 | php_version: crate::types::PhpVersion, |
| 273 | ) -> Result<Option<Vec<TextEdit>>, String> { |
| 274 | match strategy { |
| 275 | FormattingStrategy::Disabled => Ok(None), |
| 276 | FormattingStrategy::External(tools) => { |
| 277 | let edits = run_external_pipeline(tools, content, file_path, config)?; |
| 278 | if edits.is_empty() { |
| 279 | Ok(None) |
| 280 | } else { |
| 281 | Ok(Some(edits)) |
| 282 | } |
| 283 | } |
| 284 | FormattingStrategy::BuiltIn => { |
| 285 | let mago_version = to_mago_php_version(php_version); |
| 286 | let formatted = format_with_mago(content, mago_version)?; |
| 287 | let edits = compute_edits(content, &formatted); |
| 288 | if edits.is_empty() { |
| 289 | Ok(None) |
| 290 | } else { |
| 291 | Ok(Some(edits)) |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /// Run a single tool on the content and return the formatted string. |
| 298 | fn run_tool( |