import * as vscode from "vscode"
import { t } from "./shims/i18n"

export class AutocompleteCodeActionProvider implements vscode.CodeActionProvider {
  public readonly providedCodeActionKinds = {
    quickfix: vscode.CodeActionKind.QuickFix,
  }

  public provideCodeActions(
    document: vscode.TextDocument,
    range: vscode.Range | vscode.Selection,
    _context: vscode.CodeActionContext,
    _token: vscode.CancellationToken,
  ): vscode.ProviderResult<(vscode.CodeAction | vscode.Command)[]> {
    const action = new vscode.CodeAction(
      t("kilocode:autocomplete.codeAction.title"),
      this.providedCodeActionKinds["quickfix"],
    )
    action.command = {
      command: "kilo-code.new.autocomplete.generateSuggestions",
      title: "",
      arguments: [document.uri, range],
    }

    return [action]
  }

  public async resolveCodeAction(
    codeAction: vscode.CodeAction,
    token: vscode.CancellationToken,
  ): Promise<vscode.CodeAction> {
    if (token.isCancellationRequested) {
      return codeAction
    }
    return codeAction
  }
}
