Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] AI 模块的代码补全 API 调整 #3853

Closed
Ricbet opened this issue Jul 15, 2024 · 2 comments
Closed

[FEATURE] AI 模块的代码补全 API 调整 #3853

Ricbet opened this issue Jul 15, 2024 · 2 comments
Assignees
Labels
🎨 feature feature required

Comments

@Ricbet
Copy link
Member

Ricbet commented Jul 15, 2024

如果你的需求与问题相关,请在下面描述一下(Is your feature request related to a problem? Please describe.)

现在AI 模块下的所有功能都是设计在 contribution 下的。
唯独代码补全的 api 是写在 back service 里的,也不好拓展,这是当初的设计缺陷,现在应该需要调整到 contribution 下

考虑到兼容性,目前在 back service 里的 requestCompletion 方法还是会保留,不会弃用
同时也会保留参数的传入类型和参数个数,尽可能保持一致,降低迁移成本

描述你预期的功能表现(Describe the solution you'd like)

可能会提供以下 API

registerInlineCompletionFeature(registry: IInlineCompletionRegistry): void;
interface IInlineCompletionRegistry {
 xxxx
}
@Ricbet
Copy link
Member Author

Ricbet commented Jul 17, 2024

API 设计

registerIntelligentCompletionFeature(registry: IIntelligentCompletionRegistry): void;
/**
* editor: 当前编辑器
* position: 当前光标位置
* requestBean: 补全请求参数
* @returns: IIntelligentCompletionsResult
*/
interface IIntelligentCompletionRegistry {
  provideIntelligentCompletions(editor: ICodeEditor, position: IPosition, requestBean: IAICompletionOption, token: CancellationToken): MaybePromise<IIntelligentCompletionsResult>;
}
export interface IIntelligentCompletionsResult {
  readonly items: IInlineCompletionItem[]
}

export interface IInlineCompletionItem {
  /**
   * 补全的内容
   */
  content: string;
  /**
   * 表示当前行之前需要再补全几行
   * 最大值为 3
   */
  aboveRadius?: number;
  /**
   * 表示当前行之后需要再补全几行
   * 最大值为 3
   */
  belowRadius?: number;
}

暂定这些接口。

集成方只需要返回 IInlineCompletionItem 列表即可。

这里有两个新字段是 aboveRadiusbelowRadius。由集成方决定此次补全的代码结果所需要的范围有多大。

默认情况下,只传 content 字段时,则与现在的代码补全交互一致,会在光标之后补全代码内容
如果传递了 aboveRadius 或 belowRadius 字段,则会在 opensumi 内部自己去计算是要展示 "多行补全" 还是展示 "智能重写"

@Ricbet
Copy link
Member Author

Ricbet commented Aug 19, 2024

API 设计调整

aboveRadius belowRadius 字段的意义表达不明,不能很好的区分传统智能补全和多行补全。

所以将这两个字段删除,改成用 enableMultiLine 开关去配置。
例如

return {
  items: [
    {
      insertText: 'xxx',
      range // 要补全的范围可以通过 range 去控制,替换了上述的 aboveRadius 和 belowRadius
    },
  ],
  enableMultiLine: true // 表明这个补全内容是多行补全,如果为 false 则与传统补全一致
};

注: 开启了 enableMultiLine 之后必须传递 range 字段

@Ricbet Ricbet closed this as completed Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

No branches or pull requests

1 participant