MCPcopy
hub / github.com/MadAppGang/dingo / translateUsingLineDirectives

Function translateUsingLineDirectives

pkg/lsp/translator.go:480–514  ·  view source on GitHub ↗

translateUsingLineDirectives translates a Go line to Dingo line using //line directives Returns (dingoLine, found) where found indicates if a directive-based translation was used

(goPath string, goLine int)

Source from the content-addressed store, hash-verified

478// translateUsingLineDirectives translates a Go line to Dingo line using //line directives
479// Returns (dingoLine, found) where found indicates if a directive-based translation was used
480func translateUsingLineDirectives(goPath string, goLine int) (int, bool) {
481 entries, err := parseLineDirectives(goPath)
482 if err != nil || len(entries) == 0 {
483 return goLine, false
484 }
485
486 // Find the last directive that affects this line
487 // //line directives affect the NEXT line, so we look for directive at goLine-1 or earlier
488 var activeEntry *lineDirectiveEntry
489 for i := range entries {
490 if entries[i].goLine < goLine {
491 activeEntry = &entries[i]
492 } else {
493 break
494 }
495 }
496
497 if activeEntry == nil {
498 return goLine, false
499 }
500
501 // Calculate Dingo line:
502 // If directive is at Go line D and sets Dingo line to L,
503 // then Go line D+1 → Dingo line L
504 // So Go line G → Dingo line L + (G - D - 1)
505 dingoLine := activeEntry.dingoLine + (goLine - activeEntry.goLine - 1)
506 if dingoLine < 1 {
507 dingoLine = 1
508 }
509
510 log.Printf("[LSP Translator] LineDirective: Go line %d → Dingo line %d (directive at Go line %d sets Dingo line %d)",
511 goLine, dingoLine, activeEntry.goLine, activeEntry.dingoLine)
512
513 return dingoLine, true
514}

Callers 1

TranslatePositionMethod · 0.85

Calls 2

parseLineDirectivesFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected