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

Method php_to_blade

src/blade/source_map.rs:57–133  ·  view source on GitHub ↗
(&self, pos: Position)

Source from the content-addressed store, hash-verified

55 }
56
57 pub fn php_to_blade(&self, pos: Position) -> Position {
58 if pos.line < super::PROLOGUE_LINES {
59 return Position {
60 line: 0,
61 character: 0,
62 };
63 }
64 let line = (pos.line - super::PROLOGUE_LINES) as usize;
65
66 if line >= self.adjustments.len() {
67 return Position {
68 line: line as u32,
69 character: pos.character,
70 };
71 }
72
73 let line_adj = &self.adjustments[line];
74 if line_adj.is_empty() {
75 return Position {
76 line: line as u32,
77 character: pos.character,
78 };
79 }
80
81 let mut best_idx = 0;
82 let mut best_b = 0;
83 let mut best_p = 0;
84
85 for (i, (b, p)) in line_adj.iter().enumerate() {
86 if *p <= pos.character {
87 best_idx = i;
88 best_b = *b;
89 best_p = *p;
90 } else {
91 break;
92 }
93 }
94
95 let mut char_offset = pos.character.saturating_sub(best_p);
96
97 if let Some((next_b, next_p)) = line_adj.get(best_idx + 1) {
98 let max_b_offset = next_b.saturating_sub(best_b);
99 let max_p_offset = next_p.saturating_sub(best_p);
100
101 if max_p_offset == 0 {
102 // PHP boilerplate mapped to zero-width Blade point?
103 // This shouldn't happen with our anchor strategy, but be safe.
104 return Position {
105 line: line as u32,
106 character: best_b,
107 };
108 }
109
110 if max_b_offset == 0 {
111 // PHP boilerplate mapped to a single Blade position.
112 // EVERYTHING in this PHP segment maps to best_b.
113 return Position {
114 line: line as u32,

Callers 3

runFunction · 0.80

Calls 3

iterMethod · 0.80
is_emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected