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

Function rebuild_docblock

src/code_actions/update_docblock.rs:1267–1359  ·  view source on GitHub ↗

Rebuild a docblock string from categorized lines.

(lines: &[DocLine], indent: &str)

Source from the content-addressed store, hash-verified

1265
1266/// Rebuild a docblock string from categorized lines.
1267fn rebuild_docblock(lines: &[DocLine], indent: &str) -> String {
1268 let mut result = String::new();
1269 let mut prev_was_param = false;
1270 let mut prev_was_text_or_empty = false;
1271
1272 for (i, line) in lines.iter().enumerate() {
1273 match line {
1274 DocLine::Open => {
1275 result.push_str("/**");
1276 result.push('\n');
1277 prev_was_param = false;
1278 prev_was_text_or_empty = false;
1279 }
1280 DocLine::Close => {
1281 result.push_str(indent);
1282 result.push_str(" */");
1283 prev_was_param = false;
1284 prev_was_text_or_empty = false;
1285 }
1286 DocLine::Text(text) => {
1287 // Add blank separator before text if preceded by tags.
1288 if prev_was_param {
1289 result.push_str(indent);
1290 result.push_str(" *\n");
1291 }
1292 result.push_str(indent);
1293 result.push_str(" * ");
1294 result.push_str(text);
1295 result.push('\n');
1296 prev_was_param = false;
1297 prev_was_text_or_empty = true;
1298 }
1299 DocLine::Empty => {
1300 result.push_str(indent);
1301 result.push_str(" *\n");
1302 prev_was_param = false;
1303 prev_was_text_or_empty = true;
1304 }
1305 DocLine::Param(text) => {
1306 // Add blank separator before first @param if preceded by text.
1307 if !prev_was_param && prev_was_text_or_empty {
1308 // Check if the previous line was already empty.
1309 let prev_empty = i > 0 && matches!(lines.get(i - 1), Some(DocLine::Empty));
1310 if !prev_empty {
1311 result.push_str(indent);
1312 result.push_str(" *\n");
1313 }
1314 }
1315 result.push_str(indent);
1316 result.push_str(" * ");
1317 result.push_str(text);
1318 result.push('\n');
1319 prev_was_param = true;
1320 prev_was_text_or_empty = false;
1321 }
1322 DocLine::Return(text) => {
1323 // Add blank separator before @return if preceded by @param.
1324 if prev_was_param {

Callers 1

build_updated_docblockFunction · 0.85

Calls 2

iterMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected