// Command query service for command completion (#453).
//
// Provides command discovery and argument completion for cmdline UI.
// Covers both user commands (named, :-invocable) and keybinding commands.

syntax = "proto3";
package reovim.v2;

service CommandService {
  // Search commands by name prefix (tab completion).
  //
  // Searches both user commands and keybinding commands.
  rpc SearchCommands(SearchCommandsRequest) returns (SearchCommandsResponse);

  // Complete arguments for a specific user command.
  //
  // Delegates to the command's complete() implementation.
  rpc CompleteArgs(CompleteArgsRequest) returns (CompleteArgsResponse);
}

message SearchCommandsRequest {
  // Prefix to search for (e.g., "wri" matches "write").
  string prefix = 1;
  // Command source filter.
  CommandSource source = 2;
}

enum CommandSource {
  // Search all command types.
  COMMAND_SOURCE_ALL = 0;
  // Search only user commands (named, :-invocable).
  COMMAND_SOURCE_USER = 1;
  // Search only keybinding commands.
  COMMAND_SOURCE_KEYBINDING = 2;
}

message SearchCommandsResponse {
  // Matching user commands.
  repeated UserCommandEntry user_commands = 1;
  // Matching keybinding commands.
  repeated KeybindingCommandEntry keybinding_commands = 2;
}

message UserCommandEntry {
  // Handler identifier (e.g., "write").
  string id = 1;
  // Command aliases (e.g., ["w", "write"]).
  repeated string names = 2;
  // Help text.
  string help = 3;
}

message KeybindingCommandEntry {
  // Command ID (module:name format, e.g., "motions:cursor-down").
  string id = 1;
  // User command aliases (may be empty for internal commands).
  repeated string names = 2;
  // Description.
  string description = 3;
}

message CompleteArgsRequest {
  // User command name (e.g., "colorscheme").
  string command = 1;
  // Partial argument input (e.g., "dar" for colorscheme completion).
  string partial = 2;
}

message CompleteArgsResponse {
  // Completion suggestions.
  repeated string completions = 1;
}
