completion_system.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <memory>
  5. #include <unordered_map> // For std::unordered_map
  6. #include "lumacs/minibuffer_mode.hpp" // For MinibufferMode enum
  7. #include "lumacs/minibuffer_mode_hash.hpp" // For MinibufferMode hash specialization
  8. #include "lumacs/completion_common.hpp" // For CompletionCandidate struct
  9. namespace lumacs {
  10. // Forward declaration
  11. class EditorCore;
  12. /// @brief Interface for a completion source.
  13. /// Different minibuffer modes will use different implementations of this interface.
  14. class ICompletionSource {
  15. public:
  16. virtual ~ICompletionSource() = default;
  17. /// @brief Retrieves completion candidates based on the current input.
  18. /// @param input_text The current text entered by the user in the minibuffer.
  19. /// @return A vector of matching completion candidates.
  20. virtual std::vector<CompletionCandidate> get_candidates(const std::string& input_text) = 0;
  21. };
  22. /// @brief Manages various completion sources and provides candidates for the minibuffer.
  23. class CompletionSystem {
  24. public:
  25. explicit CompletionSystem(EditorCore& core);
  26. /// @brief Registers a completion source for a specific minibuffer mode.
  27. void register_source(MinibufferMode mode, std::unique_ptr<ICompletionSource> source);
  28. /// @brief Retrieves completion candidates for a given mode and input.
  29. std::vector<CompletionCandidate> get_candidates_for_mode(MinibufferMode mode, const std::string& input_text);
  30. private:
  31. [[maybe_unused]] EditorCore& core_; // Reserved for future use
  32. std::unordered_map<MinibufferMode, std::unique_ptr<ICompletionSource>> sources_;
  33. };
  34. } // namespace lumacs