Repository navigation
Feat: Pre-fill derive topics from the scope at point; add learning tests to the TDD menu - #521
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5682e93c12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| (when-let* ((scope (ai-code--current-qualified-scope-name))) | ||
| (if buffer-file-name | ||
| (format "%s (%s)" scope | ||
| (file-relative-name buffer-file-name (ai-code--git-root))) |
There was a problem hiding this comment.
Normalize the file before computing the topic path
When a repository is opened through a directory symlink, ai-code--git-root returns the canonical file-truename, while buffer-file-name can retain the symlinked path. Relativizing those two different path namespaces produces a value such as ../../repo-alias/src/Service.java instead of src/Service.java, so accepting the pre-filled topic sends the AI a misleading path outside the reported repository root. Normalize the visited file with buffer-file-truename or file-truename before calling file-relative-name.
Useful? React with 👍 / 👎.
Two follow-ups to #517 that make topic-based derivation quicker to reach from code.
Pre-fill the topic from the scope at point. Every derive command in
ai-code-doc.elstarts by asking for a topic, and when you invoke one from a source file the topic you want is usually the function or class you are standing in, so typing it by hand is busywork. The newai-code--topic-at-pointreusesai-code--current-qualified-scope-name(Tree-sitter first, thenwhich-function) and, inprog-modebuffers, returns something likeService.run (src/Service.java), with the path relative to the Git root (just the scope name when the buffer visits no file). The two topic readers use it differently:ai-code--read-document-topic): an empty topic there means "whole repository", so silently pre-filling would change the default. It first asksScope document to "Service.run (src/Service.java)"?—nkeeps the whole-repo document without reading a topic,ypre-fills the topic for editing.ai-code--read-unit-test-topic): the topic is required anyway, so it is pre-filled directly with no extra question.Outside
prog-mode, or when no scope is found, both prompts behave exactly as before.Learning tests in
C-c a t.ai-code-derive-topic-unit-testswas only reachable from the architecture menu (C-c a A), but test-related actions are naturally looked for in the TDD menu.ai-code-tdd-cyclenow ends with6. Learning tests (Derive unit tests as a tutorial for a topic), which dispatches to the same command; theC-c a Aentry stays. In Magit buffersC-c a tkeeps its existing hunk-based path, so the option is not offered there.Verification.
test/test_ai-code-doc.el(accepting and declining the scope question, no offer outsideprog-mode, unit test topic pre-fill) and one intest/test_ai-code-agile.el(last TDD choice and its dispatch).emacs -batch -L . --eval '(setq package-user-dir (expand-file-name "no-such-elpa" temporary-file-directory) native-comp-enable-subr-trampolines nil)' -l ert --eval "(mapc #'load-file (file-expand-wildcards \"test/test_*.el\"))" -f ert-run-tests-batch-and-exit→ 1586 tests, 0 unexpected, 13 skipped. Disabling subr trampolines is only a local workaround for native-comp errors whencl-letfstubscompleting-read/read-string.checkdocon the touched files add no new warnings (the helper useswhen-let*to avoid thewhen-letobsolescence warning in newer Emacs).Known caveat, left alone on purpose: with behavior auto-presets enabled,
ai-code-tdd-cyclemaps to thetdd-devpreset, so a learning-test prompt started fromC-c a talso picks up+tdd.README.orgis not updated for either change yet.