summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/api/suggestions.ts
blob: f75f6e06362b79d765d3f0f0e697c106025b0aeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * @license
 * Copyright 2023 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import {CommentRange, NumericChangeId, RevisionPatchSetNum} from './rest-api';

export declare interface SuggestionsPluginApi {
  /**
   * Must only be called once. You cannot register twice. You cannot unregister.
   */
  register(provider: SuggestionsProvider): void;
}

export declare interface SuggestCodeRequest {
  prompt: string;
  changeNumber: NumericChangeId;
  patchsetNumber: RevisionPatchSetNum;
  filePath: string;
  range?: CommentRange;
  lineNumber?: Number;
}

export declare interface SuggestionsProvider {
  /**
   * Gerrit calls this method when ...
   * - ... user types a comment draft
   */
  suggestCode(commentData: SuggestCodeRequest): Promise<SuggestCodeResponse>;
}

declare interface SuggestCodeResponse {
  responseCode: ResponseCode;
  suggestions: Suggestion[];
}

export declare interface Suggestion {
  replacement: string;
  newRange?: CommentRange;
}

export enum ResponseCode {
  OK = 'OK',
  ERROR = 'ERROR',
}