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:
parent
9f6809a28d
commit
3cc8850a58
5 changed files with 91 additions and 2 deletions
26
crates/migrator/src/migrations/m_2025_05_08/settings.rs
Normal file
26
crates/migrator/src/migrations/m_2025_05_08/settings.rs
Normal 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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue