fix(mobile): detect files directly under path roots

This commit is contained in:
Brennan Benson
2026-08-03 20:20:23 -07:00
parent 7c1af0be05
commit f45a8cb7a1
2 changed files with 16 additions and 1 deletions
@@ -74,6 +74,21 @@ describe('detectFilePathSegments', () => {
expect(detectFilePathSegments('/repo/src/index.ts')).toEqual([
{ type: 'file', value: '/repo/src/index.ts', path: '/repo/src/index.ts' }
])
expect(detectFilePathSegments('/root.ts')).toEqual([
{ type: 'file', value: '/root.ts', path: '/root.ts' }
])
})
it('detects files directly under explicit Windows and relative roots', () => {
expect(detectFilePathSegments(String.raw`C:\root.ts`)).toEqual([
{ type: 'file', value: String.raw`C:\root.ts`, path: String.raw`C:\root.ts` }
])
expect(detectFilePathSegments('./root.ts')).toEqual([
{ type: 'file', value: './root.ts', path: 'root.ts' }
])
expect(detectFilePathSegments('../root.ts')).toEqual([
{ type: 'file', value: '../root.ts', path: '../root.ts' }
])
})
it('detects paths with :line and :line:col suffixes', () => {
@@ -87,7 +87,7 @@ const EXTENSION_SET = new Set<string>(FILE_EXTENSIONS)
// alternatives cover Windows drives, UNC, and POSIX absolute roots; the optional
// tail captures agent-style :line(:col) citations.
const CANDIDATE_PATTERN =
/(?:[A-Za-z]:[\\/]|\\\\|[\\/])?(?:\.{1,2}[\\/])?(?:[\w.@~+-]+[\\/])+[\w.@+-]+\.[A-Za-z0-9]+(?::[1-9]\d*(?::[1-9]\d*)?)?/g
/(?:(?:[A-Za-z]:[\\/]|\\\\|[\\/]|\.{1,2}[\\/])(?:[\w.@~+-]+[\\/])*|(?:[\w.@~+-]+[\\/])+)[\w.@+-]+\.[A-Za-z0-9]+(?::[1-9]\d*(?::[1-9]\d*)?)?/g
// A path candidate in chat prose is short; a much longer run can't hold one worth
// linkifying but can push CANDIDATE_PATTERN into super-linear backtracking, so we