pub fn extract_prefix(content: &str, position: Position, range: Range) -> StringExpand description
Extracts the prefix text from content at a position within a range.
This function finds the text from the start of the range up to the cursor position, excluding any quote characters.
§Arguments
content- Full document contentposition- Cursor position (LSP Position, 0-based line, UTF-16 character offset)range- Range containing the token (name, version, etc.)
§Returns
The prefix string typed so far, with quotes and extra whitespace removed.
§Examples
use deps_core::completion::extract_prefix;
use tower_lsp_server::ls_types::{Position, Range};
let content = r#"serde = "1.0""#;
let position = Position { line: 0, character: 11 }; // After "1."
let range = Range {
start: Position { line: 0, character: 9 },
end: Position { line: 0, character: 13 },
};
let prefix = extract_prefix(content, position, range);
assert_eq!(prefix, "1.");