Class ProjectFilesContextProvider

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class ProjectFilesContextProvider extends BasicContextProvider
Provides a real-time view of a project's file and folder structure. This provider injects a Markdown-formatted tree of the project into the AI's prompt augmentation (RAG) message.
Author:
anahata
  • Field Details

    • projectsToolkit

      private final Projects projectsToolkit
      The parent Projects toolkit.
    • projectPath

      private final String projectPath
      The absolute path to the project directory.
  • Constructor Details

    • ProjectFilesContextProvider

      public ProjectFilesContextProvider(Projects projectsToolkit, String projectPath)
      Constructs a new files provider for a specific project.
      Parameters:
      projectsToolkit - The parent Projects toolkit.
      projectPath - The absolute path to the project.
  • Method Details

    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Injects the project's file tree into the RAG message.

      Implementation details: Fetches the current file structural data from the Projects toolkit and generates a Markdown tree. It distinguishes between root files and source-group folders for clarity.

      Parameters:
      ragMessage - The target RAG message.
      Throws:
      Exception - if project files cannot be retrieved.
    • setProviding

      public void setProviding(boolean enabled)
      Toggles providing status and triggers a UI refresh.

      Implementation details: Notifies the IDE that the project icon should be redrawn to reflect the new context state.

      Parameters:
      enabled - New state.
    • generateMarkdown

      private String generateMarkdown(ProjectFiles files)
      Generates a Markdown string representing the project file tree.

      Implementation details: This method splits the output into the Root Directory (flat list) and Source Folders (hierarchical tree). It resolves the relative path for each top-level source folder to provide context for the AI.

      Parameters:
      files - The project files data.
      Returns:
      A Markdown-formatted string.
    • formatSourceFolder

      private String formatSourceFolder(SourceFolder folder, String indent, String basePath, String relPath)
      Recursively formats a source folder and its contents into a Markdown tree.

      Implementation details: Displays the folder name (or display name) followed by an optional relative path in parentheses for top-level groups.

      Parameters:
      folder - The source folder to format.
      indent - The current indentation level.
      basePath - The base path of the project.
      relPath - Optional relative path for display next to the folder.
      Returns:
      A Markdown-formatted string for the folder.
    • formatProjectFile

      private String formatProjectFile(ProjectFile file, String indent)
      Formats a project file into a Markdown list item.

      Implementation details: Includes the file name and any IDE-level annotations (e.g., Git status flags) extracted from the annotated name.

      Parameters:
      file - The project file to format.
      indent - The current indentation string.
      Returns:
      A Markdown-formatted string for the file.