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

Method highlight_this

src/highlight/mod.rs:161–196  ·  view source on GitHub ↗

Highlight all `$this` references within the same class body.

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

Source from the content-addressed store, hash-verified

159
160 /// Highlight all `$this` references within the same class body.
161 fn highlight_this(
162 &self,
163 symbol_map: &SymbolMap,
164 content: &str,
165 cursor_offset: u32,
166 uri: &str,
167 ) -> Vec<DocumentHighlight> {
168 let ctx_classes: Vec<std::sync::Arc<crate::types::ClassInfo>> = self
169 .uri_classes_index
170 .read()
171 .get(uri)
172 .cloned()
173 .unwrap_or_default();
174 let current_class = crate::util::find_class_at_offset(&ctx_classes, cursor_offset);
175 let (class_start, class_end) = match current_class {
176 Some(cc) => (cc.start_offset, cc.end_offset),
177 None => (0, u32::MAX),
178 };
179
180 let mut highlights = Vec::new();
181
182 for span in &symbol_map.spans {
183 if span.start < class_start || span.start > class_end {
184 continue;
185 }
186 if let SymbolKind::SelfStaticParent(SelfStaticParentKind::This) = &span.kind {
187 highlights.push(DocumentHighlight {
188 range: byte_range_to_lsp_range(content, span.start as usize, span.end as usize),
189 kind: Some(DocumentHighlightKind::READ),
190 });
191 }
192 }
193
194 highlights.sort_by(cmp_highlight_range);
195 highlights
196 }
197
198 /// Highlight all occurrences of a class/interface/trait/enum name
199 /// (by FQN) in the file.

Callers 1

Calls 4

find_class_at_offsetFunction · 0.85
byte_range_to_lsp_rangeFunction · 0.85
pushMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected