Skip to main content

symbol_path_at

Function symbol_path_at 

Source
pub fn symbol_path_at(symbols: &[LspSymbol], line: u32) -> Vec<String>
Expand description

LSP integration types and traits for editor clients. LSP integration types and traits for editor clients. LSP integration types and traits for editor clients. Returns the names of the symbols enclosing line, outermost first.

At each level the first symbol whose range contains line is entered, so the result reads like a breadcrumb trail: ["Editor", "render"] for a line inside the render method of Editor.

§Arguments

  • symbols - Top-level symbols of the document
  • line - Zero-based line number

§Returns

The chain of enclosing symbol names, empty when line is outside every symbol

§Example

use iced_code_editor::{LspPosition, LspRange, LspSymbol, symbol_path_at};

let range = |start, end| LspRange {
    start: LspPosition { line: start, character: 0 },
    end: LspPosition { line: end, character: 0 },
};
let symbols = vec![LspSymbol {
    name: "Editor".to_string(),
    range: range(0, 10),
    children: vec![LspSymbol {
        name: "render".to_string(),
        range: range(2, 5),
        children: Vec::new(),
    }],
}];

assert_eq!(symbol_path_at(&symbols, 3), ["Editor", "render"]);
assert_eq!(symbol_path_at(&symbols, 8), ["Editor"]);
assert!(symbol_path_at(&symbols, 11).is_empty());