Mountain/Command/LanguageFeature.rs
1//! # LanguageFeature (Command)
2//!
3//! RESPONSIBILITIES:
4//! - Defines Tauri command handlers for language feature requests from Sky
5//! frontend
6//! - Bridges Monaco Editor language requests to
7//! `LanguageFeatureProviderRegistry`
8//! - Provides type-safe parameter handling and validation for LSP features
9//! - Implements hover, code actions, document highlights, completions,
10//! definition, references
11//! - Uses generic `InvokeProvider` helper to reduce boilerplate
12//!
13//! ARCHITECTURAL ROLE:
14//! - Command layer that exposes language features via Tauri IPC (`#[command]`)
15//! - Delegates to Environment's
16//! [`LanguageFeatureProvider`](crate::Environment::LanguageFeatureProvider)
17//! via DI with `Require()` trait
18//! - Translates between frontend JSON parameters and Rust DTO types
19//! - Error strings returned directly to frontend for display
20//!
21//! COMMAND REFERENCE (Tauri IPC):
22//! - [`MountainProvideHover`]: Show hover information at cursor position
23//! - [`MountainProvideCodeActions`]: Get quick fixes and refactorings for a code range
24//! - [`MountainProvideDocumentHighlights`]: Find symbol occurrences in document
25//! - [`MountainProvideCompletions`]: Get code completion suggestions with context
26//! - [`MountainProvideDefinition`]: Jump to symbol definition location
27//! - [`MountainProvideReferences`]: Find all references to a symbol
28//!
29//! ERROR HANDLING:
30//! - Returns `Result<Value, String>` where errors sent directly to frontend
31//! - Validates URI non-empty and position format (line/character numbers)
32//! - JSON serialization errors converted to strings
33//! - Provider errors (CommonError) converted to strings via `map_err(|Error|
34//! Error.to_string())`
35//!
36//! PERFORMANCE:
37//! - Each command is async and non-blocking
38//! - Provider lookup is O(1) via `Require()` from DI container
39//! - URI parsing and DTO deserialization adds minimal overhead
40//!
41//! VS CODE REFERENCE:
42//! - `vs/workbench/api/common/extHostLanguageFeatures.ts` - ext host language
43//! features API
44//! - `vs/workbench/services/languageFeatures/common/languageFeaturesService.ts`
45//! - service layer
46//! - `vs/workbench/contrib/hover/browser/hover.ts` - hover implementation
47//! - `vs/workbench/contrib/completion/browser/completion.ts` - completion
48//! widget
49//! - `vs/workbench/contrib/definition/browser/definition.ts` - go to definition
50//! - `vs/workbench/contrib/references/browser/references.ts` - find references
51//!
52//! TODO:
53//! - Implement more language features: document symbols, formatting, rename,
54//! signature help
55//! - Add cancellation token support for long-running operations
56//! - Implement request deduplication for identical concurrent requests
57//! - Add request caching for repeated symbol lookups
58//! - Support workspace symbol search
59//! - Add semantic tokens for syntax highlighting
60//! - Implement code lens provider
61//! - Add inlay hints support
62//! - Support linked editing range
63//! - Add call hierarchy and type hierarchy
64//! - Implement document color and color presentation
65//! - Add folding range provider
66//! - Support selection range provider
67//!
68//! MODULE STRUCTURE:
69//! - [`validation.rs`](validation.rs) - request validation helper
70//! - [`invoke_provider.rs`](invoke_provider.rs) - generic provider invoker
71//! - Individual command modules for each language feature (containing impls
72//! only)
73
74use log::debug;
75use serde_json::Value;
76use tauri::{AppHandle, Wry, command};
77use url::Url;
78
79use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
80
81// Private submodules containing implementation (without #[command] attributes)
82#[path = "LanguageFeature/validation.rs"]
83mod validation;
84#[path = "LanguageFeature/invoke_provider.rs"]
85mod invoke_provider;
86#[path = "LanguageFeature/hover.rs"]
87mod hover;
88#[path = "LanguageFeature/code_actions.rs"]
89mod code_actions;
90#[path = "LanguageFeature/highlights.rs"]
91mod highlights;
92#[path = "LanguageFeature/completions.rs"]
93mod completions;
94#[path = "LanguageFeature/definition.rs"]
95mod definition;
96#[path = "LanguageFeature/references.rs"]
97mod references;
98
99/// Provides hover information at cursor position
100#[command]
101pub async fn MountainProvideHover(
102 application_handle:AppHandle<Wry>,
103 uri:String,
104 position:Value,
105) -> Result<Value, String> {
106 debug!("[Language Feature] Providing hover for: {} at {:?}", uri, position);
107 hover::provide_hover_impl(application_handle, uri, position).await
108}
109
110/// Provides code actions (quick fixes and refactorings) for a code range
111#[command]
112pub async fn MountainProvideCodeActions(
113 application_handle:AppHandle<Wry>,
114 uri:String,
115 position:Value,
116 context:Value,
117) -> Result<Value, String> {
118 debug!("[Language Feature] Providing code actions for: {} at {:?}", uri, position);
119 code_actions::provide_code_actions_impl(application_handle, uri, position, context).await
120}
121
122/// Finds symbol occurrences (document highlights) in a document
123#[command]
124pub async fn MountainProvideDocumentHighlights(
125 application_handle:AppHandle<Wry>,
126 uri:String,
127 position:Value,
128) -> Result<Value, String> {
129 debug!(
130 "[Language Feature] Providing document highlights for: {} at {:?}",
131 uri, position
132 );
133 highlights::provide_document_highlights_impl(application_handle, uri, position).await
134}
135
136/// Provides code completion suggestions
137#[command]
138pub async fn MountainProvideCompletions(
139 application_handle:AppHandle<Wry>,
140 uri:String,
141 position:Value,
142 context:Value,
143) -> Result<Value, String> {
144 debug!("[Language Feature] Providing completions for: {} at {:?}", uri, position);
145 completions::provide_completions_impl(application_handle, uri, position, context).await
146}
147
148/// Provides go-to-definition functionality
149#[command]
150pub async fn MountainProvideDefinition(
151 application_handle:AppHandle<Wry>,
152 uri:String,
153 position:Value,
154) -> Result<Value, String> {
155 debug!("[Language Feature] Providing definition for: {} at {:?}", uri, position);
156 definition::provide_definition_impl(application_handle, uri, position).await
157}
158
159/// Finds all references to a symbol
160#[command]
161pub async fn MountainProvideReferences(
162 application_handle:AppHandle<Wry>,
163 uri:String,
164 position:Value,
165 context:Value,
166) -> Result<Value, String> {
167 debug!("[Language Feature] Providing references for: {} at {:?}", uri, position);
168 references::provide_references_impl(application_handle, uri, position, context).await
169}