TestTranslatePositionErrorPropagationColumn tests column mapping for error propagation transforms. This is a REGRESSION TEST for the issue where hovering on `extractUserID` in Dingo shows hover info for `tmp` instead, because column positions differ: - Dingo: `userID := extractUserID(r)?` → extract
(t *testing.T)
| 414 | // |
| 415 | // The test verifies that column positions are correctly mapped for transformed lines. |
| 416 | func TestTranslatePositionErrorPropagationColumn(t *testing.T) { |
| 417 | // Realistic error propagation example |
| 418 | // Dingo line: " userID := extractUserID(r)?\n" |
| 419 | // Go line: " tmp, err := extractUserID(r)\n" |
| 420 | // |
| 421 | // Character positions (1-indexed): |
| 422 | // Dingo: extractUserID starts at col 12 (after tab + "userID := ") |
| 423 | // Go: extractUserID starts at col 14 (after tab + "tmp, err := ") |
| 424 | dingoSrc := "\tuserID := extractUserID(r)?\n" |
| 425 | goSrc := "\ttmp, err := extractUserID(r)\n" |
| 426 | |
| 427 | // Error propagation expands 1 dingo line to 5 go lines typically, |
| 428 | // but for this test we simplify to just the first line mapping |
| 429 | mappings := []sourcemap.LineMapping{ |
| 430 | {DingoLine: 1, GoLineStart: 1, GoLineEnd: 1, Kind: "error_prop"}, |
| 431 | } |
| 432 | |
| 433 | // Column mapping for the function call expression |
| 434 | // Dingo: "\tuserID := extractUserID(r)?" - extractUserID at col 12 (1-indexed) |
| 435 | // Go: "\ttmp, err := extractUserID(r)" - extractUserID at col 14 (1-indexed) |
| 436 | // Offset = 14 - 12 = +2 (Go has 2 more leading chars due to "tmp, err" vs "userID") |
| 437 | columnMappings := []sourcemap.ColumnMapping{ |
| 438 | { |
| 439 | DingoLine: 1, |
| 440 | DingoCol: 12, // 1-indexed position of 'e' in extractUserID |
| 441 | GoLine: 1, |
| 442 | GoCol: 14, // 1-indexed position of 'e' in extractUserID |
| 443 | Length: 13, // length of "extractUserID" |
| 444 | Kind: "error_prop", |
| 445 | }, |
| 446 | } |
| 447 | |
| 448 | reader := createMockReaderWithColumns(t, dingoSrc, goSrc, mappings, columnMappings) |
| 449 | defer reader.Close() |
| 450 | |
| 451 | goPath := "/test/file.go" |
| 452 | dingoPath := "/test/file.dingo" |
| 453 | |
| 454 | cache := &mockSourceMapGetter{ |
| 455 | readers: map[string]*dmap.Reader{ |
| 456 | goPath: reader, |
| 457 | }, |
| 458 | } |
| 459 | |
| 460 | translator := NewTranslator(cache) |
| 461 | dingoURI := lspuri.File(dingoPath) |
| 462 | |
| 463 | // Test: Position on 'extractUserID' in Dingo (col 12, 0-indexed = 11) |
| 464 | // In Dingo: "\tuserID := extractUserID(r)?" |
| 465 | // ^ ^ |
| 466 | // 0 11 (0-indexed) |
| 467 | dingoPos := protocol.Position{Line: 0, Character: 11} |
| 468 | |
| 469 | newURI, newPos, err := translator.TranslatePosition(dingoURI, dingoPos, DingoToGo) |
| 470 | if err != nil { |
| 471 | t.Fatalf("TranslatePosition failed: %v", err) |
| 472 | } |
| 473 |
nothing calls this directly
no test coverage detected