diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-19 10:51:32 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-19 10:51:32 +0300 |
| commit | 4c057d02a11a81579836e451e74c0e7ebb1649ea (patch) | |
| tree | 8b97a063ae6488628386f47e8fea874adaa9d424 /internal/ui/fileref_test.go | |
| parent | 8ec2807ece746b001e3d64a1db990ce239a98801 (diff) | |
Support "@ path" file reference (space after @) when file exists
Extend the `o` open-file feature so a reference written with a space
after the @ ("@ path/to/file.txt") is also recognized. Because "@ word"
is common in prose (e.g. "meet @ 5pm"), the spaced form is only treated
as a file reference when the resolved path actually exists on disk. The
original no-space "@path" form keeps precedence and its existing
behavior (opened as-is, so a not-yet-existing file can be created).
Adds fileRefSpacedRegex, a fileExists guard, and unit tests covering the
existing/missing/prose/precedence cases.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/ui/fileref_test.go')
| -rw-r--r-- | internal/ui/fileref_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/ui/fileref_test.go b/internal/ui/fileref_test.go index 662f5ab..1ab9c06 100644 --- a/internal/ui/fileref_test.go +++ b/internal/ui/fileref_test.go @@ -50,6 +50,37 @@ func TestResolveFileRefPathTilde(t *testing.T) { } } +// TestExtractFileRefSpaced verifies the "@ path" form: a space after the @ is +// only treated as a file reference when the resolved path exists on disk, so +// ordinary "@ word" prose does not false-match. +func TestExtractFileRefSpaced(t *testing.T) { + dir := t.TempDir() + existing := filepath.Join(dir, "real.txt") + if err := os.WriteFile(existing, []byte("hi"), 0o644); err != nil { + t.Fatalf("write temp file: %v", err) + } + missing := filepath.Join(dir, "nope.txt") + + cases := []struct { + name string + text string + want string + }{ + {"spaced existing file", "please open @ " + existing, existing}, + {"spaced missing file", "please open @ " + missing, ""}, + {"spaced prose not a file", "let's meet @ 5pm today", ""}, + {"no-space form still wins", "@main.go and @ " + existing, "main.go"}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if got := extractFileRef(tc.text); got != tc.want { + t.Fatalf("extractFileRef(%q) = %q, want %q", tc.text, got, tc.want) + } + }) + } +} + // TestFindTaskFileRefFallsBackToAnnotations verifies that the description is // scanned first and annotations are used only when the description has no // reference. |
