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

Method handle_code_lens

src/code_lens.rs:32–112  ·  view source on GitHub ↗

Handle a `textDocument/codeLens` request. Returns a code lens for each method in the file that overrides a parent class method or implements an interface method.

(&self, uri: &str, content: &str)

Source from the content-addressed store, hash-verified

30 /// Returns a code lens for each method in the file that overrides
31 /// a parent class method or implements an interface method.
32 pub fn handle_code_lens(&self, uri: &str, content: &str) -> Option<Vec<CodeLens>> {
33 let classes = {
34 let map = self.uri_classes_index.read();
35 map.get(uri)?.clone()
36 };
37
38 let mut lenses = Vec::new();
39
40 for class in &classes {
41 let class_fqn = class.fqn();
42
43 for method in &class.methods {
44 // Skip synthetic/stub methods with no real source position.
45 if method.name_offset == 0 {
46 continue;
47 }
48
49 // Skip virtual methods (injected via @method tags, not
50 // actually declared in source).
51 if method.is_virtual {
52 continue;
53 }
54
55 if let Some(proto) =
56 self.find_prototype(class, &class_fqn, &method.name, uri, content)
57 {
58 let pos = offset_to_position(content, method.name_offset as usize);
59 let range = Range {
60 start: Position {
61 line: pos.line,
62 character: 0,
63 },
64 end: Position {
65 line: pos.line,
66 character: 0,
67 },
68 };
69
70 let icon = if proto.is_interface { "◆" } else { "↑" };
71 let title = format!("{} {}::{}", icon, proto.ancestor_name, method.name);
72
73 // Build a URI with a fragment encoding the target
74 // line and column so that `vscode.open` jumps to the
75 // right position. This avoids the `instanceof`
76 // constraint errors that `editor.action.goToLocations`
77 // and `editor.action.showReferences` trigger when
78 // called from an LSP server without a companion
79 // extension to convert plain JSON into VS Code class
80 // instances.
81 let fragment = format!(
82 "L{},{}",
83 proto.position.line + 1,
84 proto.position.character + 1
85 );
86 let mut target_uri: Url = match proto.file_uri.parse() {
87 Ok(u) => u,
88 Err(_) => continue,
89 };

Callers 5

code_lensMethod · 0.80
get_code_lensesFunction · 0.80
cross_file_parent_classFunction · 0.80
empty_file_returns_noneFunction · 0.80

Calls 8

offset_to_positionFunction · 0.85
cloneMethod · 0.80
fqnMethod · 0.80
find_prototypeMethod · 0.80
pushMethod · 0.80
getMethod · 0.45
parseMethod · 0.45
is_emptyMethod · 0.45

Tested by 3

cross_file_parent_classFunction · 0.64
empty_file_returns_noneFunction · 0.64