CommonLibrary/LanguageFeature/ProvideOnTypeFormatting.rs
1//! # ProvideOnTypeFormatting Effect
2//!
3//! Defines the `ActionEffect` for requesting on-type formatting edits from a
4//! language feature provider.
5
6use std::sync::Arc;
7
8use serde_json::Value;
9use url::Url;
10
11use super::{
12 DTO::{PositionDTO::PositionDTO, TextEditDTO::TextEditDTO},
13 LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
14};
15use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
16
17/// Creates an effect that, when executed, will request on-type formatting
18/// edits.
19pub fn ProvideOnTypeFormatting(
20 DocumentURI:Url,
21
22 PositionDTO:PositionDTO,
23
24 Character:String,
25
26 OptionsDTO:Value,
27) -> ActionEffect<Arc<dyn LanguageFeatureProviderRegistry>, CommonError, Option<Vec<TextEditDTO>>> {
28 ActionEffect::New(Arc::new(move |Registry:Arc<dyn LanguageFeatureProviderRegistry>| {
29 let DocumentURIClone = DocumentURI.clone();
30 let CharacterClone = Character.clone();
31 let OptionsDTOClone = OptionsDTO.clone();
32
33 Box::pin(async move {
34 Registry
35 .ProvideOnTypeFormattingEdits(DocumentURIClone, PositionDTO, CharacterClone, OptionsDTOClone)
36 .await
37 })
38 }))
39}