Skip to main content

extract_feature_prefix

Function extract_feature_prefix 

Source
pub fn extract_feature_prefix(content: &str, position: Position) -> String
Expand description

Extracts the partial feature name typed at the cursor position.

Scans backwards from the cursor on the current line to find the start of the feature string being typed. Handles both inline and multi-line arrays.

Returns an empty string when the cursor is not inside a quoted string (e.g. right after [ or between , and the next ").

ยงExamples

// Cursor inside: features = ["derive", "std", "ser|"]
let content = r#"serde = { version = "1", features = ["derive", "std", "ser"] }"#;
// cursor_char = index after "ser" inside the last quoted element
let ser_start = content.find(r#""ser""#).unwrap() + 1; // skip opening quote
let pos = Position { line: 0, character: (ser_start + "ser".len()) as u32 };
let prefix = extract_feature_prefix(content, pos);
assert_eq!(prefix, "ser");