1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//! rust-analyzer Integration: LSP-based code intelligence for mutations
//!
//! This module provides integration with [rust-analyzer](https://rust-analyzer.github.io/)
//! via the Language Server Protocol (LSP). It enables semantic-aware code transformations
//! that require type information beyond what pure AST analysis can provide.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ rust-analyzer Integration │
//! ├─────────────────────────────────────────────────────────────────┤
//! │ │
//! │ ┌──────────────┐ LSP Protocol ┌──────────────────────┐ │
//! │ │ ryo-mutations│◄──────────────────►│ rust-analyzer │ │
//! │ │ │ │ │ │
//! │ │ - Mutations │ textDocument/ │ - Type inference │ │
//! │ │ - PureFile │ inlayHint │ - Semantic tokens │ │
//! │ │ │ textDocument/ │ - Code actions │ │
//! │ │ │ codeAction │ - Diagnostics │ │
//! │ └──────────────┘ └──────────────────────┘ │
//! │ │ │ │
//! │ ▼ ▼ │
//! │ ┌──────────────────────────────────────────────────────────┐ │
//! │ │ Enriched Mutations │ │
//! │ │ │ │
//! │ │ - CloneOnCopy with accurate Copy detection │ │
//! │ │ - (v0.1.0) AddExplicitType / FillMatchArms / │ │
//! │ │ AddMissingFields are NOT YET shipped — type-inference │ │
//! │ │ infrastructure required │ │
//! │ └──────────────────────────────────────────────────────────┘ │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # LSP Endpoints Used
//!
//! ## InlayHints (`textDocument/inlayHint`)
//!
//! Provides type information that the compiler infers but isn't written in code:
//!
//! | Hint Kind | Example | Use Case |
//! |-----------|---------|----------|
//! | Type | `let x: i32 = ...` | Add explicit type annotations |
//! | Parameter | `foo(/* name: */ value)` | Parameter name completion |
//! | Chaining | `.map(...): Vec<_>` | Method chain type tracking |
//!
//! ## CodeAction (`textDocument/codeAction`)
//!
//! rust-analyzer "assists" that can be converted to Mutations:
//!
//! | Assist | Mutation | Description |
//! |--------|----------|-------------|
//! | `fill_match_arms` | _(deferred — needs type inference)_ | Add missing match arms |
//! | `add_missing_fields` | _(deferred — needs type inference)_ | Add missing struct fields |
//! | `inline_type_alias` | `InlineTypeAliasMutation` | Expand type alias |
//! | `extract_type_alias` | `ExtractTypeAliasMutation` | Create type alias |
//! | `add_explicit_type` | _(deferred — needs type inference)_ | Add type annotation |
//! | `replace_if_let_with_match` | `IfLetToMatchMutation` | Convert if let to match |
//! | `replace_match_with_if_let` | `MatchToIfLetMutation` | Convert match to if let |
//!
//! `fill_match_arms` / `add_missing_fields` / `add_explicit_type` derivations
//! were removed in v0.1.0 because their AST-level apply paths required
//! type-inference infrastructure that has not yet landed; they will return
//! when that infrastructure is in place.
//!
//! ## Hover (`textDocument/hover`)
//!
//! Type information and documentation for symbols.
//!
//! ## SemanticTokens (`textDocument/semanticTokens`)
//!
//! Token classification for semantic highlighting:
//! - Variable modifiers: `mutable`, `consuming`, `reference`
//! - Type modifiers: `copy`, `associated`
//!
//! # Usage
//!
//! ```rust,ignore
//! use ryo_mutations::analyzer::{AnalyzerClient, InlayHintQuery};
//!
//! // Connect to rust-analyzer
//! let client = AnalyzerClient::new("/path/to/project")?;
//!
//! // Get type hints for a file
//! let hints = client.inlay_hints("src/lib.rs")?;
//!
//! // Use hints to enrich mutations
//! for hint in hints.type_hints() {
//! if hint.is_copy_type() {
//! // Can safely apply CloneOnCopy mutation
//! }
//! }
//!
//! // Get available code actions at a position
//! let actions = client.code_actions("src/lib.rs", line, column)?;
//!
//! // Convert to mutations
//! for action in actions {
//! if let Some(mutation) = action.to_mutation() {
//! println!("Available: {}", mutation.describe());
//! }
//! }
//! ```
//!
//! # Relationship with Clippy Integration
//!
//! | Feature | Clippy | rust-analyzer |
//! |---------|--------|---------------|
//! | Type info | No | Yes (InlayHints) |
//! | Lint fixes | Yes (suggestions) | Yes (CodeActions) |
//! | Refactoring | Limited | Extensive (assists) |
//! | Batch apply | Yes | Per-file |
//!
//! For best results, combine both:
//! - Use Clippy for lint-driven transformations
//! - Use rust-analyzer for semantic-aware refactoring
//!
//! # Performance Considerations
//!
//! - rust-analyzer startup can take several seconds for large projects
//! - InlayHints are computed lazily, request only needed ranges
//! - Consider caching results for repeated operations
//!
//! # Future Extensions
//!
//! - [ ] Workspace-wide rename with type checking
//! - [ ] Automatic import resolution
//! - [ ] Trait implementation scaffolding
//! - [ ] Lifetime inference and annotation
pub use ;
pub use ;
use Path;
/// Known rust-analyzer assist IDs that map to mutations
/// Common Copy types for heuristic detection
/// Client for communicating with rust-analyzer
///
/// This is a lightweight wrapper that can use an existing LSP connection
/// or spawn a new rust-analyzer instance.