Skip to content

refactor: use Imenu as symbol completion source - #484

Draft
tninja wants to merge 1 commit into
mainfrom
agent/imenu-symbol-completion
Draft

refactor: use Imenu as symbol completion source#484
tninja wants to merge 1 commit into
mainfrom
agent/imenu-symbol-completion

Conversation

@tninja

@tninja tninja commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Summary

Refactor @file#symbol completion so Imenu is the canonical symbol-discovery layer, including when the target buffer is using a Tree-sitter major mode.

This keeps the user-facing improvements from #483 (qualified names, source order, header/line annotations) while removing the package-level file-wide Tree-sitter symbol scanner.

Why

#483 treated Imenu and Tree-sitter as alternative symbol providers. In Emacs, Tree-sitter major modes already expose their structural symbol index through Imenu (treesit-simple-imenu / imenu-create-index-function). Bypassing that abstraction makes ai-code-interface.el maintain a second cross-language symbol-discovery implementation and its own function/method/constructor node-type registry.

There is one important nuance: Tree-sitter-backed Imenu indexes are often grouped into flat categories such as Class and Function, so Imenu alone does not always preserve the enclosing-type path needed for Bar.baz.

Changes

  • Use imenu--make-index-alist as the single source of which symbols exist and their source positions.
  • Preserve semantic Imenu hierarchy when a mode provides it, without treating grouping categories such as Class / Function as name prefixes.
  • Restore file-definition order from Imenu entry positions rather than alphabetically sorting candidates.
  • For an active Tree-sitter parser, enrich each Imenu-discovered position locally with its enclosing type path, so flat indexes still produce names such as Bar.baz and Outer.Inner.run.
  • Use the existing semantic-scope machinery to enrich declaration headers; non-Tree-sitter modes fall back to the source line.
  • Remove the file-wide Tree-sitter AST walk and function-node registry introduced by feat(treesit): symbol-level @# completion with qualified names #483.
  • Replace provider-specific completion tests with tests for Imenu discovery, flat Tree-sitter Imenu qualification, nested qualification, source ordering, special Imenu entries, and completion annotations.

Design

The abstraction is now:

major mode (Tree-sitter / regexp / LSP / mode-specific) -> Imenu -> ai-code symbol discovery

with Tree-sitter used only as position-local enrichment when an active parser can provide metadata that the Imenu representation omitted.

In particular, this PR does not scan the file-wide Tree-sitter AST to rediscover symbols and does not maintain a new cross-language function/method node-type table.

Validation

  • Full ERT suite passes on both push and pull-request workflows.
  • Build/melpazoid checks pass on both push and pull-request workflows.
  • Codex review's flat Tree-sitter Imenu concern was addressed with regressions for Bar.baz and Outer.Inner.run.
  • Branch is squashed to one commit with only the five intended source/test files changed.

tninja commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a436a330d

ℹ️ 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".

Comment thread ai-code-input.el
@tninja
tninja force-pushed the agent/imenu-symbol-completion branch from 18fe046 to 0d77b36 Compare August 17, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant