MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / tokenize_content_for_display

Function tokenize_content_for_display

atomic-repository/src/semantic_regen.rs:394–421  ·  view source on GitHub ↗

Tokenize file content into FileOps for display purposes. This is the **on-the-fly fallback** — when `diff`/`log`/`blame` needs semantic data but the SEMANTIC section hasn't been regenerated yet, this function tokenizes the content directly without persisting to redb. This is the same tokenization pipeline used during `record`, but standalone and stateless. # Arguments `path` - File path (for t

(path: &str, content: &[u8], encoding: Encoding)

Source from the content-addressed store, hash-verified

392/// assert!(ops.line_count() > 0);
393/// ```
394pub fn tokenize_content_for_display(path: &str, content: &[u8], encoding: Encoding) -> FileOps {
395 let placeholder_change_id = NodeId::new(0);
396 let mut builder = CrdtChangeBuilder::new(placeholder_change_id);
397
398 let enc = if encoding == Encoding::Binary {
399 None
400 } else {
401 Some(encoding)
402 };
403
404 builder.add_file_with_content(path, content, enc);
405
406 let result = builder.finish();
407 let (file_ops_list, _, _) = result.into_parts();
408
409 // Extract the single FileOps for this file
410 file_ops_list
411 .into_iter()
412 .next()
413 .map(|builder_ops| builder_ops.into_change_ops())
414 .unwrap_or_else(|| {
415 FileOps::create(
416 TrunkId::new(placeholder_change_id, 0),
417 path.to_string(),
418 Some(encoding),
419 )
420 })
421}
422
423/// Detect the encoding of file content.
424///

Callers 6

test_tokenize_multi_lineFunction · 0.85

Calls 6

add_file_with_contentMethod · 0.80
into_change_opsMethod · 0.80
finishMethod · 0.45
into_partsMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45

Tested by 6

test_tokenize_multi_lineFunction · 0.68