Mountain/Command/LanguageFeature/
completions.rs1use CommonLibrary::{
6 Error::CommonError::CommonError,
7 LanguageFeature::{
8 DTO::{CompletionContextDTO::CompletionContextDTO, PositionDTO::PositionDTO},
9 LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
10 },
11};
12use log::debug;
13use serde_json::Value;
14use tauri::{AppHandle, Wry};
15use url::Url;
16
17use super::{invoke_provider::invoke_provider, validation::validate_language_feature_request};
18
19pub(super) async fn provide_completions_impl(
22 application_handle:AppHandle<Wry>,
23 uri:String,
24 position:Value,
25 context:Value,
26) -> Result<Value, String> {
27 debug!("[Language Feature] Providing completions for: {} at {:?}", uri, position);
28
29 validate_language_feature_request("completions", &uri, &position)?;
30
31 let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
32
33 let position_dto:PositionDTO =
34 serde_json::from_value(position.clone()).map_err(|error| format!("Failed to parse position: {}", error))?;
35
36 let context_dto:CompletionContextDTO =
37 serde_json::from_value(context.clone()).map_err(|error| format!("Failed to parse context: {}", error))?;
38
39 invoke_provider(application_handle, |provider| {
40 async move {
41 let result = provider
43 .ProvideCompletions(document_uri, position_dto, context_dto, None)
44 .await?;
45 Ok(serde_json::to_value(result)?)
46 }
47 })
48 .await
49}