Class ProjectStructureContextProvider

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class ProjectStructureContextProvider extends AbstractProjectContextProvider
Provides a source-root-aware map of a project's Java structure.

Unlike a raw filesystem walk, this provider uses the IntelliJ project model (ProjectRootManager.getContentSourceRoots() + ProjectFileIndex) so the ASI sees the logical layout the IDE sees: each configured source root, labelled as production or test, with its package/type tree. All model and VFS access runs inside a ReadAction because context is assembled on a background thread.

Author:
anahata
  • Constructor Details

    • ProjectStructureContextProvider

      public ProjectStructureContextProvider(Projects projectsToolkit, String projectPath)
      Constructs a new project structure context provider.
      Parameters:
      projectsToolkit - The parent Projects toolkit.
      projectPath - The absolute path to the project.
  • Method Details

    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).

      Renders each content source root (flagged main/test) and its package/type tree, built from the IntelliJ project model inside a read action.

      Parameters:
      ragMessage - The message to be augmented with context.
      Throws:
      Exception - if an error occurs during context generation.
    • appendTree

      private void appendTree(com.intellij.openapi.vfs.VirtualFile dir, StringBuilder sb, String indent, int depth)
      Recursively renders a source-root subtree as Markdown: directories (packages) as folders and .java files as types, skipping build-output and hidden dirs and capping recursion to keep the context lean.

      Must be called inside a read action.

      Parameters:
      dir - the current directory node.
      sb - the Markdown accumulator.
      indent - the current indentation prefix.
      depth - the current recursion depth.