settings: Migration for fixing duplicated agent keys (#30237)

As a byproduct, this fixes bug where it's impossible to change Agent
profile

Closes #30000 

Release Notes:

- N/A
This commit is contained in:
Oleksiy Syvokon 2025-05-08 15:38:19 +03:00 committed by GitHub
parent 9f6809a28d
commit 3cc8850a58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 91 additions and 2 deletions

View file

@ -0,0 +1,26 @@
use std::ops::Range;
use tree_sitter::{Query, QueryMatch};
use crate::{MigrationPatterns, patterns::SETTINGS_DUPLICATED_AGENT_PATTERN};
pub const SETTINGS_PATTERNS: MigrationPatterns =
&[(SETTINGS_DUPLICATED_AGENT_PATTERN, comment_duplicated_agent)];
fn comment_duplicated_agent(
contents: &str,
mat: &QueryMatch,
query: &Query,
) -> Option<(Range<usize>, String)> {
let pair_ix = query.capture_index_for_name("pair1")?;
let mut range = mat.nodes_for_capture_index(pair_ix).next()?.byte_range();
// Include the comma into the commented region
let rtext = &contents[range.end..];
if let Some(comma_index) = rtext.find(',') {
range.end += comma_index + 1;
}
let value = contents[range.clone()].to_string();
let commented_value = format!("/* Duplicated key auto-commented: {value} */");
Some((range, commented_value))
}