MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / highlight_variable

Method highlight_variable

src/highlight/mod.rs:101–158  ·  view source on GitHub ↗

Highlight all occurrences of a variable within the same scope.

(
        &self,
        symbol_map: &SymbolMap,
        content: &str,
        var_name: &str,
        cursor_offset: u32,
    )

Source from the content-addressed store, hash-verified

99
100 /// Highlight all occurrences of a variable within the same scope.
101 fn highlight_variable(
102 &self,
103 symbol_map: &SymbolMap,
104 content: &str,
105 var_name: &str,
106 cursor_offset: u32,
107 ) -> Vec<DocumentHighlight> {
108 let scope_start = symbol_map.find_variable_scope(var_name, cursor_offset);
109 let mut highlights = Vec::new();
110 let mut seen_offsets = std::collections::HashSet::new();
111
112 // Collect from symbol spans.
113 for span in &symbol_map.spans {
114 if let SymbolKind::Variable { name } = &span.kind {
115 if name != var_name {
116 continue;
117 }
118 let span_scope = symbol_map.find_variable_scope(name, span.start);
119 if span_scope != scope_start {
120 continue;
121 }
122 seen_offsets.insert(span.start);
123
124 let kind = if symbol_map.var_def_kind_at(name, span.start).is_some() {
125 DocumentHighlightKind::WRITE
126 } else {
127 DocumentHighlightKind::READ
128 };
129
130 highlights.push(DocumentHighlight {
131 range: byte_range_to_lsp_range(content, span.start as usize, span.end as usize),
132 kind: Some(kind),
133 });
134 }
135 }
136
137 // Include var_def sites that may not have a matching Variable span
138 // (e.g. parameters, foreach bindings).
139 for def in &symbol_map.var_defs {
140 if def.name == var_name
141 && def.scope_start == scope_start
142 && seen_offsets.insert(def.offset)
143 {
144 let end_offset = def.offset + 1 + def.name.len() as u32;
145 highlights.push(DocumentHighlight {
146 range: byte_range_to_lsp_range(
147 content,
148 def.offset as usize,
149 end_offset as usize,
150 ),
151 kind: Some(DocumentHighlightKind::WRITE),
152 });
153 }
154 }
155
156 highlights.sort_by(cmp_highlight_range);
157 highlights
158 }

Callers 1

Calls 5

byte_range_to_lsp_rangeFunction · 0.85
find_variable_scopeMethod · 0.80
var_def_kind_atMethod · 0.80
pushMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected