* claim: #2757 * fix(params): autocomplete offers a parameter for any part of its name (#2757) Typing `side` now offers `cab_side_thickness`: parameters match the word anywhere in their name, after those that start with it, both in the expression boxes and in parameters.complete. Functions, constants and units still match from the start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
@@ -348,11 +348,16 @@ fn complete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let text = str_(p, "prefix").unwrap_or("");
|
||||
// The identifier being typed: trailing letters, digits and underscores.
|
||||
let word: String = text.chars().rev().take_while(|c| c.is_alphanumeric() || *c == '_').collect::<Vec<_>>().into_iter().rev().collect();
|
||||
let starts = |n: &str| word.is_empty() || n.to_ascii_lowercase().starts_with(&word.to_ascii_lowercase());
|
||||
let lower = word.to_ascii_lowercase();
|
||||
let starts = |n: &str| word.is_empty() || n.to_ascii_lowercase().starts_with(&lower);
|
||||
// A parameter matches wherever the word appears in its name (`side` finds
|
||||
// `cab_side_thickness`, #2757); functions, constants and units match from the start.
|
||||
let within = |n: &str| word.is_empty() || n.to_ascii_lowercase().contains(&lower);
|
||||
let mut out: Vec<Value> = Vec::new();
|
||||
let mut rows: Vec<solidcraft_doc::ParamRow> = s.doc.param_rows().into_iter().filter(|r| starts(&r.name)).collect();
|
||||
// Favourites, then user parameters, then the rest.
|
||||
rows.sort_by_key(|r| (!r.favorite, r.source != "user"));
|
||||
let mut rows: Vec<solidcraft_doc::ParamRow> = s.doc.param_rows().into_iter().filter(|r| within(&r.name)).collect();
|
||||
// Names that start with the word, then the rest; within each, favourites, then user
|
||||
// parameters, then the others.
|
||||
rows.sort_by_key(|r| (!starts(&r.name), !r.favorite, r.source != "user"));
|
||||
for r in rows.into_iter().take(200) {
|
||||
let v = r.value.map(|v| format!("{v:.4} {}", r.unit).trim().to_string()).unwrap_or_else(|| "error".into());
|
||||
let mut detail = format!("{} = {v}", r.expression);
|
||||
|
||||
Reference in New Issue
Block a user