completion_system.hpp 1.6 KB

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