Skip to main content

Mountain/Command/
LanguageFeature.rs

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