Skip to content

Commit

Permalink
feat: support code edits perferences (#4155)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet authored Nov 7, 2024
1 parent 926108b commit d7142f9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/ai-native/src/browser/ai-core.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,19 @@ export class AINativeBrowserContribution
},
],
});
registry.registerSettingSection(AI_NATIVE_SETTING_GROUP_ID, {
title: localize('preference.ai.native.codeEdits.title'),
preferences: [
{
id: AINativeSettingSectionsId.CodeEditsLintErrors,
localized: 'preference.ai.native.codeEdits.lintErrors',
},
{
id: AINativeSettingSectionsId.CodeEditsLineChange,
localized: 'preference.ai.native.codeEdits.lineChange',
},
],
});
}

if (this.aiNativeConfigService.capabilities.supportsInlineChat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Autowired, INJECTOR_TOKEN, Injectable, Injector, Optional } from '@opensumi/di';
import { PreferenceService } from '@opensumi/ide-core-browser';
import {
AIServiceType,
CodeEditsRT,
Expand Down Expand Up @@ -63,6 +64,9 @@ export abstract class BaseCodeEditsSource extends Disposable {
@Autowired(IAIReporter)
private aiReporter: IAIReporter;

@Autowired(PreferenceService)
protected preferenceService: PreferenceService;

private cancellationTokenSource = new CancellationTokenSource();
private readonly relationID = observableValue<string | undefined>(this, undefined);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@opensumi/di';
import { ECodeEditsSourceTyping, IDisposable } from '@opensumi/ide-core-common';
import { AINativeSettingSectionsId, ECodeEditsSourceTyping, IDisposable } from '@opensumi/ide-core-common';
import { ICursorPositionChangedEvent, Position } from '@opensumi/ide-monaco';

import { BaseCodeEditsSource } from './base';
Expand Down Expand Up @@ -30,7 +30,9 @@ export class LineChangeCodeEditsSource extends BaseCodeEditsSource {

private lastEditTime: number | null = null;
protected doTrigger(position: Position) {
if (!position) {
const isLineChangeEnabled = this.preferenceService.getValid(AINativeSettingSectionsId.CodeEditsLineChange, false);

if (!isLineChangeEnabled || !position) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Autowired, Injectable } from '@opensumi/di';
import { ECodeEditsSourceTyping, Event, FRAME_THREE, IDisposable } from '@opensumi/ide-core-common';
import {
AINativeSettingSectionsId,
ECodeEditsSourceTyping,
Event,
FRAME_THREE,
IDisposable,
} from '@opensumi/ide-core-common';
import { ICursorPositionChangedEvent, IPosition, Position } from '@opensumi/ide-monaco';
import { URI } from '@opensumi/ide-monaco/lib/browser/monaco-api';
import { IWorkspaceService } from '@opensumi/ide-workspace';
Expand Down Expand Up @@ -85,7 +91,9 @@ export class LintErrorCodeEditsSource extends BaseCodeEditsSource {
}

protected async doTrigger(position: Position) {
if (!this.model) {
const isLintErrorsEnabled = this.preferenceService.getValid(AINativeSettingSectionsId.CodeEditsLintErrors, false);

if (!isLintErrorsEnabled || !this.model) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/ai-native/src/browser/preferences/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,13 @@ export const aiNativePreferenceSchema: PreferenceSchema = {
type: 'boolean',
default: false,
},
[AINativeSettingSectionsId.CodeEditsLintErrors]: {
type: 'boolean',
default: false,
},
[AINativeSettingSectionsId.CodeEditsLineChange]: {
type: 'boolean',
default: false,
},
},
};
6 changes: 6 additions & 0 deletions packages/core-common/src/settings/ai-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export enum AINativeSettingSectionsId {
IntelligentCompletionsDebounceTime = 'ai.native.intelligentCompletions.debounceTime',
IntelligentCompletionsCacheEnabled = 'ai.native.intelligentCompletions.cache.enabled',
IntelligentCompletionsAlwaysVisible = 'ai.native.intelligentCompletions.alwaysVisible',

/**
* Code edits settings
*/
CodeEditsLintErrors = 'ai.native.codeEdits.lintErrors',
CodeEditsLineChange = 'ai.native.codeEdits.lineChange',
}
export const AI_NATIVE_SETTING_GROUP_ID = 'AI-Native';
export const AI_NATIVE_SETTING_GROUP_TITLE = 'AI Native';
4 changes: 4 additions & 0 deletions packages/i18n/src/common/en-US.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,10 @@ export const localizationBundle = {
'preference.ai.native.intelligentCompletions.debounceTime': 'Debounce time for intelligent completions',
'preference.ai.native.intelligentCompletions.cache.enabled': 'Whether to enable cache for intelligent completions',
'preference.ai.native.intelligentCompletions.alwaysVisible': 'Whether to always show intelligent completions',

'preference.ai.native.codeEdits.title': 'Code Edits',
'preference.ai.native.codeEdits.lintErrors': 'Whether to enable intelligent rewriting of Lint Errors',
'preference.ai.native.codeEdits.lineChange': 'Whether to enable intelligent rewriting of Line Change',
// #endregion AI Native

// #endregion merge editor
Expand Down
4 changes: 4 additions & 0 deletions packages/i18n/src/common/zh-CN.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,10 @@ export const localizationBundle = {
'preference.ai.native.intelligentCompletions.debounceTime': '智能补全的延迟时间(毫秒)',
'preference.ai.native.intelligentCompletions.cache.enabled': '是否启用智能补全的缓存',
'preference.ai.native.intelligentCompletions.alwaysVisible': '是否总是展示智能补全',

'preference.ai.native.codeEdits.title': '智能改写',
'preference.ai.native.codeEdits.lintErrors': '是否开启对 Lint Error 类型的智能改写',
'preference.ai.native.codeEdits.lineChange': '是否开启对 Line Change 类型的智能改写',
// #endregion AI Native

'webview.webviewTagUnavailable': '非 Electron 环境不支持 webview 标签,请使用 iframe 标签',
Expand Down

0 comments on commit d7142f9

Please sign in to comment.