Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 0590322

Browse files
committed
Improve Comment function with multiple locations support
- Change ResolvedLocation to handle Vec<SymbolDef> instead of single SymbolDef - Support multiple locations in ResolvedComment (locations: Vec<FileRange>) - Simplify execution logic by removing unnecessary interpreter evaluation - Add field-level documentation and FIXME for future content elements - Suppress dead_code warnings for unimplemented GitDiff exclude fields - Update test to show multiple symbol definitions working correctly - More robust and practical for real IDE integration scenarios FIXME: Content should be content elements (addressed in next phase)
1 parent bff8a71 commit 0590322

File tree

2 files changed

+59
-16
lines changed

2 files changed

+59
-16
lines changed

server/src/ide.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ impl<U: IpcClient> DialectFunction<U> for Search {
236236
#[derive(Deserialize)]
237237
pub struct GitDiff {
238238
pub range: String,
239+
240+
#[expect(dead_code)]
239241
pub exclude_unstaged: Option<bool>,
242+
243+
#[expect(dead_code)]
240244
pub exclude_staged: Option<bool>,
241245
}
242246

@@ -271,22 +275,31 @@ impl<U: IpcClient> DialectFunction<U> for GitDiff {
271275
/// - `{"comment": {"location": {"search": {"path": "src/", "regex": "fn main"}}, "icon": "warning", "content": ["Entry point"]}}`
272276
#[derive(Deserialize)]
273277
pub struct Comment {
278+
/// Location for the comment.
274279
pub location: ResolvedLocation,
280+
281+
/// Optional icon.
275282
pub icon: Option<String>,
283+
284+
/// Optional content.
285+
///
286+
/// FIXME: These should be content elements.
276287
pub content: Vec<String>,
277288
}
278289

290+
/// We accept either symbols or file ranges.
279291
#[derive(Deserialize)]
280292
#[serde(untagged)]
281293
pub enum ResolvedLocation {
282294
FileRange(FileRange),
283-
SymbolDef(SymbolDef),
284295
SearchResults(Vec<FileRange>),
296+
SymbolDefs(Vec<SymbolDef>),
285297
}
286298

299+
/// The fully normalized struct that we send over IPC.
287300
#[derive(Serialize)]
288301
pub struct ResolvedComment {
289-
pub location: FileRange,
302+
pub locations: Vec<FileRange>,
290303
pub icon: Option<String>,
291304
pub content: Vec<String>,
292305
}
@@ -298,22 +311,21 @@ impl<U: IpcClient> DialectFunction<U> for Comment {
298311

299312
async fn execute(
300313
self,
301-
interpreter: &mut DialectInterpreter<U>,
314+
_interpreter: &mut DialectInterpreter<U>,
302315
) -> anyhow::Result<Self::Output> {
303-
// Normalize different location types to FileRange
304-
let file_range = match self.location {
305-
ResolvedLocation::FileRange(range) => range,
306-
ResolvedLocation::SymbolDef(def) => def.defined_at,
307-
ResolvedLocation::SearchResults(mut results) => {
308-
if results.is_empty() {
309-
return Err(anyhow::anyhow!("Location resolved to empty search results"));
310-
}
311-
results.remove(0)
312-
}
316+
// Normalize different location types to a Vec<FileRange>
317+
let locations = match self.location {
318+
ResolvedLocation::FileRange(range) => vec![range],
319+
ResolvedLocation::SymbolDefs(def) => def.iter().map(|d| d.defined_at.clone()).collect(),
320+
ResolvedLocation::SearchResults(results) => results,
313321
};
314322

323+
if locations.is_empty() {
324+
return Err(anyhow::anyhow!("Location resolved to empty search results"));
325+
}
326+
315327
Ok(ResolvedComment {
316-
location: file_range,
328+
locations,
317329
icon: self.icon,
318330
content: self.content,
319331
})

server/src/ide/test.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,39 @@ async fn test_comment_function_with_symbol_def() {
692692

693693
// Should normalize SymbolDef to its definedAt FileRange
694694
expect![[r#"
695-
Err(
696-
Error("data did not match any variant of untagged enum ResolvedLocation", line: 0, column: 0),
695+
Ok(
696+
Object {
697+
"content": Array [
698+
String("This function needs better error handling"),
699+
],
700+
"icon": String("warning"),
701+
"locations": Array [
702+
Object {
703+
"content": String("fn validateToken(token: &str) -> bool {"),
704+
"end": Object {
705+
"column": Number(13),
706+
"line": Number(42),
707+
},
708+
"path": String("src/auth.rs"),
709+
"start": Object {
710+
"column": Number(0),
711+
"line": Number(42),
712+
},
713+
},
714+
Object {
715+
"content": String("pub fn validateToken(token: String) -> Result<(), Error> {"),
716+
"end": Object {
717+
"column": Number(13),
718+
"line": Number(15),
719+
},
720+
"path": String("src/utils.rs"),
721+
"start": Object {
722+
"column": Number(0),
723+
"line": Number(15),
724+
},
725+
},
726+
],
727+
},
697728
)
698729
"#]]
699730
.assert_debug_eq(&result);

0 commit comments

Comments
 (0)