fix(read/edit): make compact line prefix unambiguous for tab-indented files (#613)
This commit is contained in:
committed by
GitHub
parent
84fcc7f7e0
commit
08cc6f3287
51
src/utils/file.test.ts
Normal file
51
src/utils/file.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { afterEach, describe, expect, mock, test } from 'bun:test'
|
||||
|
||||
async function importFileModuleWithKillswitchEnabled(
|
||||
killswitchEnabled: boolean,
|
||||
) {
|
||||
mock.module('../services/analytics/growthbook.js', () => ({
|
||||
getFeatureValue_CACHED_MAY_BE_STALE: () => killswitchEnabled,
|
||||
}))
|
||||
|
||||
return import(`./file.js?ts=${Date.now()}-${Math.random()}`)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
describe('addLineNumbers', () => {
|
||||
test('uses unambiguous arrow compact prefix and preserves leading tabs', async () => {
|
||||
const { addLineNumbers } = await importFileModuleWithKillswitchEnabled(false)
|
||||
|
||||
const result = addLineNumbers({
|
||||
content: '\tfirst\n\t\tsecond',
|
||||
startLine: 41,
|
||||
})
|
||||
|
||||
expect(result).toBe('41→\tfirst\n42→\t\tsecond')
|
||||
})
|
||||
|
||||
test('keeps padded arrow format when compact mode is disabled', async () => {
|
||||
const { addLineNumbers } = await importFileModuleWithKillswitchEnabled(true)
|
||||
|
||||
const result = addLineNumbers({
|
||||
content: 'alpha\nbeta',
|
||||
startLine: 1,
|
||||
})
|
||||
|
||||
expect(result).toBe(' 1→alpha\n 2→beta')
|
||||
})
|
||||
})
|
||||
|
||||
describe('stripLineNumberPrefix', () => {
|
||||
test('strips compact arrow, padded arrow, and legacy tab prefixes', async () => {
|
||||
const { stripLineNumberPrefix } = await importFileModuleWithKillswitchEnabled(
|
||||
false,
|
||||
)
|
||||
|
||||
expect(stripLineNumberPrefix('41→\tfirst')).toBe('\tfirst')
|
||||
expect(stripLineNumberPrefix(' 2→beta')).toBe('beta')
|
||||
expect(stripLineNumberPrefix('7\t\tlegacy-tab')).toBe('\tlegacy-tab')
|
||||
})
|
||||
})
|
||||
@@ -267,7 +267,7 @@ export async function suggestPathUnderCwd(
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to use the compact line-number prefix format (`N\t` instead of
|
||||
* Whether to use the compact line-number prefix format (`N→` instead of
|
||||
* ` N→`). The padded-arrow format costs 9 bytes/line overhead; at
|
||||
* 1.35B Read calls × 132 lines avg this is 2.18% of fleet uncached input
|
||||
* (bq-queries/read_line_prefix_overhead_verify.sql).
|
||||
@@ -303,7 +303,7 @@ export function addLineNumbers({
|
||||
|
||||
if (isCompactLinePrefixEnabled()) {
|
||||
return lines
|
||||
.map((line, index) => `${index + startLine}\t${line}`)
|
||||
.map((line, index) => `${index + startLine}→${line}`)
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user