@theia/ai-code-completion 1.46.0-next.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/lib/browser/ai-code-completion-frontend-module.d.ts +4 -0
- package/lib/browser/ai-code-completion-frontend-module.d.ts.map +1 -0
- package/lib/browser/ai-code-completion-frontend-module.js +40 -0
- package/lib/browser/ai-code-completion-frontend-module.js.map +1 -0
- package/lib/browser/ai-code-completion-preference.d.ts +6 -0
- package/lib/browser/ai-code-completion-preference.d.ts.map +1 -0
- package/lib/browser/ai-code-completion-preference.js +53 -0
- package/lib/browser/ai-code-completion-preference.js.map +1 -0
- package/lib/browser/ai-code-frontend-application-contribution.d.ts +14 -0
- package/lib/browser/ai-code-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/ai-code-frontend-application-contribution.js +100 -0
- package/lib/browser/ai-code-frontend-application-contribution.js.map +1 -0
- package/lib/browser/ai-code-inline-completion-provider.d.ts +9 -0
- package/lib/browser/ai-code-inline-completion-provider.d.ts.map +1 -0
- package/lib/browser/ai-code-inline-completion-provider.js +46 -0
- package/lib/browser/ai-code-inline-completion-provider.js.map +1 -0
- package/lib/browser/code-completion-agent.d.ts +27 -0
- package/lib/browser/code-completion-agent.d.ts.map +1 -0
- package/lib/browser/code-completion-agent.js +181 -0
- package/lib/browser/code-completion-agent.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +26 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +55 -0
- package/src/browser/ai-code-completion-frontend-module.ts +39 -0
- package/src/browser/ai-code-completion-preference.ts +53 -0
- package/src/browser/ai-code-frontend-application-contribution.ts +99 -0
- package/src/browser/ai-code-inline-completion-provider.ts +53 -0
- package/src/browser/code-completion-agent.ts +204 -0
- package/src/package.spec.ts +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<div align='center'>
|
|
2
|
+
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
+
|
|
7
|
+
<h2>ECLIPSE THEIA - AI Code Completion</h2>
|
|
8
|
+
|
|
9
|
+
<hr />
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
The `@theia/ai-code-completion` extension contributes Ai based code completion.
|
|
16
|
+
The user can separately enable code completion items as well as inline code completion.
|
|
17
|
+
|
|
18
|
+
## Additional Information
|
|
19
|
+
|
|
20
|
+
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
21
|
+
- [Theia - Website](https://theia-ide.org/)
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
26
|
+
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
27
|
+
|
|
28
|
+
## Trademark
|
|
29
|
+
|
|
30
|
+
"Theia" is a trademark of the Eclipse Foundation
|
|
31
|
+
<https://www.eclipse.org/theia>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-completion-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAQ/D,wBAaG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const core_1 = require("@theia/core");
|
|
19
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
20
|
+
const code_completion_agent_1 = require("./code-completion-agent");
|
|
21
|
+
const ai_code_frontend_application_contribution_1 = require("./ai-code-frontend-application-contribution");
|
|
22
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
23
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
24
|
+
const ai_code_completion_preference_1 = require("./ai-code-completion-preference");
|
|
25
|
+
const ai_code_inline_completion_provider_1 = require("./ai-code-inline-completion-provider");
|
|
26
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
27
|
+
bind(core_1.ILogger).toDynamicValue(ctx => {
|
|
28
|
+
const parentLogger = ctx.container.get(core_1.ILogger);
|
|
29
|
+
return parentLogger.child('code-completion-agent');
|
|
30
|
+
}).inSingletonScope().whenTargetNamed('code-completion-agent');
|
|
31
|
+
bind(code_completion_agent_1.CodeCompletionAgentImpl).toSelf().inSingletonScope();
|
|
32
|
+
bind(code_completion_agent_1.CodeCompletionAgent).toService(code_completion_agent_1.CodeCompletionAgentImpl);
|
|
33
|
+
bind(ai_core_1.Agent).toService(code_completion_agent_1.CodeCompletionAgentImpl);
|
|
34
|
+
bind(ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider).toSelf().inSingletonScope();
|
|
35
|
+
bind(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution).toSelf().inSingletonScope();
|
|
36
|
+
bind(browser_1.FrontendApplicationContribution).to(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution);
|
|
37
|
+
bind(browser_1.KeybindingContribution).toService(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution);
|
|
38
|
+
bind(browser_1.PreferenceContribution).toConstantValue({ schema: ai_code_completion_preference_1.AICodeCompletionPreferencesSchema });
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=ai-code-completion-frontend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-completion-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,sCAAsC;AACtC,4DAA+D;AAC/D,mEAAuF;AACvF,2GAAgG;AAChG,qDAA0H;AAC1H,4CAAuC;AACvC,mFAAoF;AACpF,6FAAuF;AAEvF,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,cAAO,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC/B,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAU,cAAO,CAAC,CAAC;QACzD,OAAO,YAAY,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC;IAC/D,IAAI,CAAC,+CAAuB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC1D,IAAI,CAAC,2CAAmB,CAAC,CAAC,SAAS,CAAC,+CAAuB,CAAC,CAAC;IAC7D,IAAI,CAAC,eAAK,CAAC,CAAC,SAAS,CAAC,+CAAuB,CAAC,CAAC;IAC/C,IAAI,CAAC,oEAA+B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAClE,IAAI,CAAC,6EAAiC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACpE,IAAI,CAAC,yCAA+B,CAAC,CAAC,EAAE,CAAC,6EAAiC,CAAC,CAAC;IAC5E,IAAI,CAAC,gCAAsB,CAAC,CAAC,SAAS,CAAC,6EAAiC,CAAC,CAAC;IAC1E,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,iEAAiC,EAAE,CAAC,CAAC;AAChG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
|
|
2
|
+
export declare const PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = "ai-features.codeCompletion.automaticCodeCompletion";
|
|
3
|
+
export declare const PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = "ai-features.codeCompletion.excludedFileExtensions";
|
|
4
|
+
export declare const PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = "ai-features.codeCompletion.maxContextLines";
|
|
5
|
+
export declare const AICodeCompletionPreferencesSchema: PreferenceSchema;
|
|
6
|
+
//# sourceMappingURL=ai-code-completion-preference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-completion-preference.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAG/F,eAAO,MAAM,0CAA0C,uDAAuD,CAAC;AAC/G,eAAO,MAAM,6CAA6C,sDAAsD,CAAC;AACjH,eAAO,MAAM,2CAA2C,+CAA+C,CAAC;AAExG,eAAO,MAAM,iCAAiC,EAAE,gBA6B/C,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AICodeCompletionPreferencesSchema = exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = void 0;
|
|
19
|
+
const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
|
|
20
|
+
exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = 'ai-features.codeCompletion.automaticCodeCompletion';
|
|
21
|
+
exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = 'ai-features.codeCompletion.excludedFileExtensions';
|
|
22
|
+
exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = 'ai-features.codeCompletion.maxContextLines';
|
|
23
|
+
exports.AICodeCompletionPreferencesSchema = {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
[exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE]: {
|
|
27
|
+
title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
description: 'Automatically trigger AI completions inline within any (Monaco) editor while editing.\
|
|
30
|
+
\n\
|
|
31
|
+
Alternatively, you can manually trigger the code via the command "Trigger Inline Suggestion" or the default shortcut "SHIFT+Space".',
|
|
32
|
+
default: false
|
|
33
|
+
},
|
|
34
|
+
[exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS]: {
|
|
35
|
+
title: 'Excluded File Extensions',
|
|
36
|
+
type: 'array',
|
|
37
|
+
description: 'Specify file extensions (e.g., .md, .txt) where AI completions should be disabled.',
|
|
38
|
+
items: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
},
|
|
41
|
+
default: []
|
|
42
|
+
},
|
|
43
|
+
[exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES]: {
|
|
44
|
+
title: 'Maximum Context Lines',
|
|
45
|
+
type: 'number',
|
|
46
|
+
description: 'The maximum number of lines used as context, distributed among the lines before and after the cursor position (prefix and suffix).\
|
|
47
|
+
Set this to -1 to use the full file as context without any line limit and 0 to only use the current line.',
|
|
48
|
+
default: -1,
|
|
49
|
+
minimum: -1
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=ai-code-completion-preference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-completion-preference.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAGhF,wFAA2F;AAE9E,QAAA,0CAA0C,GAAG,oDAAoD,CAAC;AAClG,QAAA,6CAA6C,GAAG,mDAAmD,CAAC;AACpG,QAAA,2CAA2C,GAAG,4CAA4C,CAAC;AAE3F,QAAA,iCAAiC,GAAqB;IAC/D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,kDAA0C,CAAC,EAAE;YAC1C,KAAK,EAAE,+CAAyB;YAChC,IAAI,EAAE,SAAS;YACf,WAAW,EAAE;;gJAEuH;YACpI,OAAO,EAAE,KAAK;SACjB;QACD,CAAC,qDAA6C,CAAC,EAAE;YAC7C,KAAK,EAAE,0BAA0B;YACjC,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,oFAAoF;YACjG,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;aACjB;YACD,OAAO,EAAE,EAAE;SACd;QACD,CAAC,mDAA2C,CAAC,EAAE;YAC3C,KAAK,EAAE,uBAAuB;YAC9B,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE;sHAC6F;YAC1G,OAAO,EAAE,CAAC,CAAC;YACX,OAAO,EAAE,CAAC,CAAC;SACd;KACJ;CACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, PreferenceService } from '@theia/core/lib/browser';
|
|
2
|
+
import { AIActivationService } from '@theia/ai-core/lib/browser';
|
|
3
|
+
import { Disposable } from '@theia/core';
|
|
4
|
+
export declare class AIFrontendApplicationContribution implements FrontendApplicationContribution, KeybindingContribution {
|
|
5
|
+
private inlineCodeCompletionProvider;
|
|
6
|
+
protected readonly preferenceService: PreferenceService;
|
|
7
|
+
protected readonly activationService: AIActivationService;
|
|
8
|
+
private toDispose;
|
|
9
|
+
onDidInitializeLayout(): void;
|
|
10
|
+
protected handlePreferences(): void;
|
|
11
|
+
registerKeybindings(keybindings: KeybindingRegistry): void;
|
|
12
|
+
protected handleInlineCompletions(): Disposable;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ai-code-frontend-application-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEzI,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,qBACa,iCAAkC,YAAW,+BAA+B,EAAE,sBAAsB;IAE7G,OAAO,CAAC,4BAA4B,CAAkC;IAGtE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IAE1D,OAAO,CAAC,SAAS,CAAiC;IAElD,qBAAqB,IAAI,IAAI;IAM7B,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAmBnC,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAQ1D,SAAS,CAAC,uBAAuB,IAAI,UAAU;CA0BlD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AIFrontendApplicationContribution = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const monaco = require("@theia/monaco-editor-core");
|
|
21
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
22
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
|
+
const browser_2 = require("@theia/ai-core/lib/browser");
|
|
24
|
+
const core_1 = require("@theia/core");
|
|
25
|
+
const ai_code_inline_completion_provider_1 = require("./ai-code-inline-completion-provider");
|
|
26
|
+
const ai_code_completion_preference_1 = require("./ai-code-completion-preference");
|
|
27
|
+
const languages_1 = require("@theia/monaco-editor-core/esm/vs/editor/common/languages");
|
|
28
|
+
let AIFrontendApplicationContribution = class AIFrontendApplicationContribution {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.toDispose = new Map();
|
|
31
|
+
}
|
|
32
|
+
onDidInitializeLayout() {
|
|
33
|
+
this.preferenceService.ready.then(() => {
|
|
34
|
+
this.handlePreferences();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
handlePreferences() {
|
|
38
|
+
const handler = () => this.handleInlineCompletions();
|
|
39
|
+
this.toDispose.set('inlineCompletions', handler());
|
|
40
|
+
this.preferenceService.onPreferenceChanged(event => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
|
|
43
|
+
|| event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
|
|
44
|
+
(_a = this.toDispose.get('inlineCompletions')) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
45
|
+
this.toDispose.set('inlineCompletions', handler());
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this.activationService.onDidChangeActiveStatus(change => {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = this.toDispose.get('inlineCompletions')) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
51
|
+
this.toDispose.set('inlineCompletions', handler());
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
registerKeybindings(keybindings) {
|
|
55
|
+
keybindings.registerKeybinding({
|
|
56
|
+
command: 'editor.action.inlineSuggest.trigger',
|
|
57
|
+
keybinding: 'Shift+Space',
|
|
58
|
+
when: '!editorReadonly && editorTextFocus'
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
handleInlineCompletions() {
|
|
62
|
+
if (!this.activationService.isActive) {
|
|
63
|
+
return core_1.Disposable.NULL;
|
|
64
|
+
}
|
|
65
|
+
const automatic = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, true);
|
|
66
|
+
const excludedExtensions = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS, []);
|
|
67
|
+
return monaco.languages.registerInlineCompletionsProvider({ scheme: 'file' }, {
|
|
68
|
+
provideInlineCompletions: (model, position, context, token) => {
|
|
69
|
+
if (!automatic && context.triggerKind === languages_1.InlineCompletionTriggerKind.Automatic) {
|
|
70
|
+
return { items: [] };
|
|
71
|
+
}
|
|
72
|
+
const fileName = model.uri.toString();
|
|
73
|
+
if (excludedExtensions.some(ext => fileName.endsWith(ext))) {
|
|
74
|
+
return { items: [] };
|
|
75
|
+
}
|
|
76
|
+
return this.inlineCodeCompletionProvider.provideInlineCompletions(model, position, context, token);
|
|
77
|
+
},
|
|
78
|
+
freeInlineCompletions: completions => {
|
|
79
|
+
this.inlineCodeCompletionProvider.freeInlineCompletions(completions);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
exports.AIFrontendApplicationContribution = AIFrontendApplicationContribution;
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, inversify_1.inject)(ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider),
|
|
87
|
+
tslib_1.__metadata("design:type", ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider)
|
|
88
|
+
], AIFrontendApplicationContribution.prototype, "inlineCodeCompletionProvider", void 0);
|
|
89
|
+
tslib_1.__decorate([
|
|
90
|
+
(0, inversify_1.inject)(browser_1.PreferenceService),
|
|
91
|
+
tslib_1.__metadata("design:type", Object)
|
|
92
|
+
], AIFrontendApplicationContribution.prototype, "preferenceService", void 0);
|
|
93
|
+
tslib_1.__decorate([
|
|
94
|
+
(0, inversify_1.inject)(browser_2.AIActivationService),
|
|
95
|
+
tslib_1.__metadata("design:type", browser_2.AIActivationService)
|
|
96
|
+
], AIFrontendApplicationContribution.prototype, "activationService", void 0);
|
|
97
|
+
exports.AIFrontendApplicationContribution = AIFrontendApplicationContribution = tslib_1.__decorate([
|
|
98
|
+
(0, inversify_1.injectable)()
|
|
99
|
+
], AIFrontendApplicationContribution);
|
|
100
|
+
//# sourceMappingURL=ai-code-frontend-application-contribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,oDAAoD;AAEpD,qDAAyI;AACzI,4DAAkE;AAClE,wDAAiE;AACjE,sCAAyC;AACzC,6FAAuF;AACvF,mFAA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AA,kBAAM,EAAC,oEAA+B,CAAC;sCACF,oEAA+B;uFAAC;AAGnD;IADlB,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;4EAC8B;AAGrC;IADlB,IAAA,kBAAM,EAAC,6BAAmB,CAAC;sCACU,6BAAmB;4EAAC;4CARjD,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAuE7C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
2
|
+
import { CodeCompletionAgent } from './code-completion-agent';
|
|
3
|
+
export declare class AICodeInlineCompletionsProvider implements monaco.languages.InlineCompletionsProvider {
|
|
4
|
+
protected readonly agent: CodeCompletionAgent;
|
|
5
|
+
private readonly agentService;
|
|
6
|
+
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
|
|
7
|
+
freeInlineCompletions(completions: monaco.languages.InlineCompletions<monaco.languages.InlineCompletion>): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ai-code-inline-completion-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-inline-completion-provider.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,qBACa,+BACT,YAAW,MAAM,CAAC,SAAS,CAAC,yBAAyB;IAErD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IAE9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAEtC,wBAAwB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EACjD,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAY1D,qBAAqB,CACjB,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,GACnF,IAAI;CAGV"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AICodeInlineCompletionsProvider = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const code_completion_agent_1 = require("./code-completion-agent");
|
|
22
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
23
|
+
let AICodeInlineCompletionsProvider = class AICodeInlineCompletionsProvider {
|
|
24
|
+
async provideInlineCompletions(model, position, context, token) {
|
|
25
|
+
if (!this.agentService.isEnabled(this.agent.id)) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return this.agent.provideInlineCompletions(model, position, context, token);
|
|
29
|
+
}
|
|
30
|
+
freeInlineCompletions(completions) {
|
|
31
|
+
// nothing to do
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.AICodeInlineCompletionsProvider = AICodeInlineCompletionsProvider;
|
|
35
|
+
tslib_1.__decorate([
|
|
36
|
+
(0, inversify_1.inject)(code_completion_agent_1.CodeCompletionAgent),
|
|
37
|
+
tslib_1.__metadata("design:type", Object)
|
|
38
|
+
], AICodeInlineCompletionsProvider.prototype, "agent", void 0);
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, inversify_1.inject)(ai_core_1.AgentService),
|
|
41
|
+
tslib_1.__metadata("design:type", Object)
|
|
42
|
+
], AICodeInlineCompletionsProvider.prototype, "agentService", void 0);
|
|
43
|
+
exports.AICodeInlineCompletionsProvider = AICodeInlineCompletionsProvider = tslib_1.__decorate([
|
|
44
|
+
(0, inversify_1.injectable)()
|
|
45
|
+
], AICodeInlineCompletionsProvider);
|
|
46
|
+
//# sourceMappingURL=ai-code-inline-completion-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-inline-completion-provider.js","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAIhF,4DAAkE;AAClE,mEAA8D;AAC9D,4CAA8C;AAGvC,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAOxC,KAAK,CAAC,wBAAwB,CAC1B,KAA+B,EAC/B,QAAyB,EACzB,OAAiD,EACjD,KAA+B;QAE/B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CACtC,KAAK,EACL,QAAQ,EACR,OAAO,EACP,KAAK,CACR,CAAC;IACN,CAAC;IAED,qBAAqB,CACjB,WAAkF;QAElF,gBAAgB;IACpB,CAAC;CACJ,CAAA;AA7BY,0EAA+B;AAGrB;IADlB,IAAA,kBAAM,EAAC,2CAAmB,CAAC;;8DACkB;AAE7B;IADhB,IAAA,kBAAM,EAAC,sBAAY,CAAC;;qEACuB;0CALnC,+BAA+B;IAD3C,IAAA,sBAAU,GAAE;GACA,+BAA+B,CA6B3C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Agent, AgentSpecificVariables, CommunicationRecordingService, LanguageModelRegistry, LanguageModelRequirement, PromptService, PromptTemplate } from '@theia/ai-core/lib/common';
|
|
2
|
+
import { ILogger, ProgressService } from '@theia/core';
|
|
3
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
4
|
+
import { PreferenceService } from '@theia/core/lib/browser';
|
|
5
|
+
export declare const CodeCompletionAgent: unique symbol;
|
|
6
|
+
export interface CodeCompletionAgent extends Agent {
|
|
7
|
+
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
|
|
8
|
+
}
|
|
9
|
+
export declare class CodeCompletionAgentImpl implements CodeCompletionAgent {
|
|
10
|
+
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
|
|
11
|
+
protected logger: ILogger;
|
|
12
|
+
protected languageModelRegistry: LanguageModelRegistry;
|
|
13
|
+
protected promptService: PromptService;
|
|
14
|
+
protected recordingService: CommunicationRecordingService;
|
|
15
|
+
protected progressService: ProgressService;
|
|
16
|
+
protected preferences: PreferenceService;
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
promptTemplates: PromptTemplate[];
|
|
21
|
+
languageModelRequirements: LanguageModelRequirement[];
|
|
22
|
+
readonly variables: string[];
|
|
23
|
+
readonly functions: string[];
|
|
24
|
+
readonly agentSpecificVariables: AgentSpecificVariables[];
|
|
25
|
+
readonly tags?: string[] | undefined;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=code-completion-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-completion-agent.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,EAAE,sBAAsB,EAAE,6BAA6B,EAC5D,qBAAqB,EAAwB,wBAAwB,EAAE,aAAa,EAAE,cAAc,EACvG,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAgB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,MAAM,WAAW,mBAAoB,SAAQ,KAAK;IAC9C,wBAAwB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAC/E,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAA;CACnJ;AAED,qBACa,uBAAwB,YAAW,mBAAmB;IACzD,wBAAwB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EACjD,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAkH1D,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAG1B,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGvD,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAGvC,SAAS,CAAC,gBAAgB,EAAE,6BAA6B,CAAC;IAG1D,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAG3C,SAAS,CAAC,WAAW,EAAE,iBAAiB,CAAC;IAEzC,EAAE,SAAqB;IACvB,IAAI,SAAqB;IACzB,WAAW,SAC2E;IACtF,eAAe,EAAE,cAAc,EAAE,CAa/B;IACF,yBAAyB,EAAE,wBAAwB,EAAE,CAKnD;IACF,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,CAKvD;IACF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACxC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CodeCompletionAgentImpl = exports.CodeCompletionAgent = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const common_1 = require("@theia/ai-core/lib/common");
|
|
21
|
+
const core_1 = require("@theia/core");
|
|
22
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
|
+
const ai_code_completion_preference_1 = require("./ai-code-completion-preference");
|
|
24
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
25
|
+
exports.CodeCompletionAgent = Symbol('CodeCompletionAgent');
|
|
26
|
+
let CodeCompletionAgentImpl = class CodeCompletionAgentImpl {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.id = 'Code Completion';
|
|
29
|
+
this.name = 'Code Completion';
|
|
30
|
+
this.description = 'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
31
|
+
this.promptTemplates = [
|
|
32
|
+
{
|
|
33
|
+
id: 'code-completion-prompt',
|
|
34
|
+
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
35
|
+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
36
|
+
You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
37
|
+
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
38
|
+
Finish the following code snippet.
|
|
39
|
+
|
|
40
|
+
{{prefix}}[[MARKER]]{{suffix}}
|
|
41
|
+
|
|
42
|
+
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
this.languageModelRequirements = [
|
|
46
|
+
{
|
|
47
|
+
purpose: 'code-completion',
|
|
48
|
+
identifier: 'openai/gpt-4o',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
this.variables = [];
|
|
52
|
+
this.functions = [];
|
|
53
|
+
this.agentSpecificVariables = [
|
|
54
|
+
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
55
|
+
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
56
|
+
{ name: 'prefix', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
57
|
+
{ name: 'suffix', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
async provideInlineCompletions(model, position, context, token) {
|
|
61
|
+
const progress = await this.progressService.showProgress({ text: 'Calculating AI code completion...', options: { location: 'window' } });
|
|
62
|
+
try {
|
|
63
|
+
const languageModel = await this.languageModelRegistry.selectLanguageModel({
|
|
64
|
+
agent: this.id,
|
|
65
|
+
...this.languageModelRequirements[0],
|
|
66
|
+
});
|
|
67
|
+
if (!languageModel) {
|
|
68
|
+
this.logger.error('No language model found for code-completion-agent');
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const maxContextLines = this.preferences.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES, -1);
|
|
72
|
+
let prefixStartLine = 1;
|
|
73
|
+
let suffixEndLine = model.getLineCount();
|
|
74
|
+
// if maxContextLines is -1, use the full file as context without any line limit
|
|
75
|
+
if (maxContextLines === 0) {
|
|
76
|
+
// Only the cursor line
|
|
77
|
+
prefixStartLine = position.lineNumber;
|
|
78
|
+
suffixEndLine = position.lineNumber;
|
|
79
|
+
}
|
|
80
|
+
else if (maxContextLines > 0) {
|
|
81
|
+
const linesBeforeCursor = position.lineNumber - 1;
|
|
82
|
+
const linesAfterCursor = model.getLineCount() - position.lineNumber;
|
|
83
|
+
// Allocate one more line to the prefix in case of an odd maxContextLines
|
|
84
|
+
const prefixLines = Math.min(Math.ceil(maxContextLines / 2), linesBeforeCursor);
|
|
85
|
+
const suffixLines = Math.min(Math.floor(maxContextLines / 2), linesAfterCursor);
|
|
86
|
+
prefixStartLine = Math.max(1, position.lineNumber - prefixLines);
|
|
87
|
+
suffixEndLine = Math.min(model.getLineCount(), position.lineNumber + suffixLines);
|
|
88
|
+
}
|
|
89
|
+
const prefix = model.getValueInRange({
|
|
90
|
+
startLineNumber: prefixStartLine,
|
|
91
|
+
startColumn: 1,
|
|
92
|
+
endLineNumber: position.lineNumber,
|
|
93
|
+
endColumn: position.column,
|
|
94
|
+
});
|
|
95
|
+
const suffix = model.getValueInRange({
|
|
96
|
+
startLineNumber: position.lineNumber,
|
|
97
|
+
startColumn: position.column,
|
|
98
|
+
endLineNumber: suffixEndLine,
|
|
99
|
+
endColumn: model.getLineMaxColumn(suffixEndLine),
|
|
100
|
+
});
|
|
101
|
+
const file = model.uri.toString(false);
|
|
102
|
+
const language = model.getLanguageId();
|
|
103
|
+
if (token.isCancellationRequested) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const prompt = await this.promptService
|
|
107
|
+
.getPrompt('code-completion-prompt', { prefix, suffix, file, language })
|
|
108
|
+
.then(p => p === null || p === void 0 ? void 0 : p.text);
|
|
109
|
+
if (!prompt) {
|
|
110
|
+
this.logger.error('No prompt found for code-completion-agent');
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
114
|
+
const sessionId = (0, core_1.generateUuid)();
|
|
115
|
+
const requestId = (0, core_1.generateUuid)();
|
|
116
|
+
const request = {
|
|
117
|
+
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
118
|
+
};
|
|
119
|
+
if (token.isCancellationRequested) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
this.recordingService.recordRequest({
|
|
123
|
+
agentId: this.id,
|
|
124
|
+
sessionId,
|
|
125
|
+
requestId,
|
|
126
|
+
request: prompt,
|
|
127
|
+
});
|
|
128
|
+
const response = await languageModel.request(request, token);
|
|
129
|
+
if (token.isCancellationRequested) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const completionText = await (0, common_1.getTextOfResponse)(response);
|
|
133
|
+
if (token.isCancellationRequested) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
this.recordingService.recordResponse({
|
|
137
|
+
agentId: this.id,
|
|
138
|
+
sessionId,
|
|
139
|
+
requestId,
|
|
140
|
+
response: completionText,
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
items: [{ insertText: completionText }],
|
|
144
|
+
enableForwardStability: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
progress.cancel();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl;
|
|
153
|
+
tslib_1.__decorate([
|
|
154
|
+
(0, inversify_1.inject)(core_1.ILogger),
|
|
155
|
+
(0, inversify_1.named)('code-completion-agent'),
|
|
156
|
+
tslib_1.__metadata("design:type", Object)
|
|
157
|
+
], CodeCompletionAgentImpl.prototype, "logger", void 0);
|
|
158
|
+
tslib_1.__decorate([
|
|
159
|
+
(0, inversify_1.inject)(common_1.LanguageModelRegistry),
|
|
160
|
+
tslib_1.__metadata("design:type", Object)
|
|
161
|
+
], CodeCompletionAgentImpl.prototype, "languageModelRegistry", void 0);
|
|
162
|
+
tslib_1.__decorate([
|
|
163
|
+
(0, inversify_1.inject)(common_1.PromptService),
|
|
164
|
+
tslib_1.__metadata("design:type", Object)
|
|
165
|
+
], CodeCompletionAgentImpl.prototype, "promptService", void 0);
|
|
166
|
+
tslib_1.__decorate([
|
|
167
|
+
(0, inversify_1.inject)(common_1.CommunicationRecordingService),
|
|
168
|
+
tslib_1.__metadata("design:type", Object)
|
|
169
|
+
], CodeCompletionAgentImpl.prototype, "recordingService", void 0);
|
|
170
|
+
tslib_1.__decorate([
|
|
171
|
+
(0, inversify_1.inject)(core_1.ProgressService),
|
|
172
|
+
tslib_1.__metadata("design:type", core_1.ProgressService)
|
|
173
|
+
], CodeCompletionAgentImpl.prototype, "progressService", void 0);
|
|
174
|
+
tslib_1.__decorate([
|
|
175
|
+
(0, inversify_1.inject)(browser_1.PreferenceService),
|
|
176
|
+
tslib_1.__metadata("design:type", Object)
|
|
177
|
+
], CodeCompletionAgentImpl.prototype, "preferences", void 0);
|
|
178
|
+
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl = tslib_1.__decorate([
|
|
179
|
+
(0, inversify_1.injectable)()
|
|
180
|
+
], CodeCompletionAgentImpl);
|
|
181
|
+
//# sourceMappingURL=code-completion-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-completion-agent.js","sourceRoot":"","sources":["../../src/browser/code-completion-agent.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,sDAGmC;AACnC,sCAAqE;AACrE,4DAAyE;AAEzE,mFAA8F;AAC9F,qDAA4D;AAE/C,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAO1D,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAA7B;QAyIH,OAAE,GAAG,iBAAiB,CAAC;QACvB,SAAI,GAAG,iBAAiB,CAAC;QACzB,gBAAW,GACP,iFAAiF,CAAC;QACtF,oBAAe,GAAqB;YAChC;gBACI,EAAE,EAAE,wBAAwB;gBAC5B,QAAQ,EAAE;;;;;;;;0EAQoD;aACjE;SACJ,CAAC;QACF,8BAAyB,GAA+B;YACpD;gBACI,OAAO,EAAE,iBAAiB;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AAK,CAAC,CAAC;YAC7D,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC;gBAChC,OAAO,SAAS,CAAC;YACrB,CAAC;YACD,MAAM,cAAc,GAAG,MAAM,IAAA,0BAAiB,EAAC,QAAQ,CAAC,CAAC;YACzD,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC;gBAChC,OAAO,SAAS,CAAC;YACrB,CAAC;YACD,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC;gBACjC,OAAO,EAAE,IAAI,CAAC,EAAE;gBAChB,SAAS;gBACT,SAAS;gBACT,QAAQ,EAAE,cAAc;aAC3B,CAAC,CAAC;YAEH,OAAO;gBACH,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;gBACvC,sBAAsB,EAAE,IAAI;aAC/B,CAAC;QACN,CAAC;gBAAS,CAAC;YACP,QAAQ,CAAC,MAAM,EAAE,CAAC;QACtB,CAAC;IACL,CAAC;CAsDJ,CAAA;AA1KY,0DAAuB;AAwHtB;IAFT,IAAA,kBAAM,EAAC,cAAO,CAAC;IACf,IAAA,iBAAK,EAAC,uBAAuB,CAAC;;uDACL;AAGhB;IADT,IAAA,kBAAM,EAAC,8BAAqB,CAAC;;sEACyB;AAG7C;IADT,IAAA,kBAAM,EAAC,sBAAa,CAAC;;8DACiB;AAG7B;IADT,IAAA,kBAAM,EAAC,sCAA6B,CAAC;;iEACoB;AAGhD;IADT,IAAA,kBAAM,EAAC,sBAAe,CAAC;sCACG,sBAAe;gEAAC;AAGjC;IADT,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;4DACe;kCAvIhC,uBAAuB;IADnC,IAAA,sBAAU,GAAE;GACA,uBAAuB,CA0KnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
/* note: this bogus test file is required so that
|
|
17
|
+
we are able to run mocha unit tests on this
|
|
18
|
+
package, without having any actual unit tests in it.
|
|
19
|
+
This way a coverage report will be generated,
|
|
20
|
+
showing 0% coverage, instead of no report.
|
|
21
|
+
This file can be removed once we have real unit
|
|
22
|
+
tests in place. */
|
|
23
|
+
describe('ai-code-completion package', () => {
|
|
24
|
+
it('support code coverage statistics', () => true);
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=package.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAEhF;;;;;;qBAMqB;AAErB,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAExC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theia/ai-code-completion",
|
|
3
|
+
"version": "1.46.0-next.241+4295c1a8c",
|
|
4
|
+
"description": "Theia - AI Core",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@theia/ai-core": "1.46.0-next.241+4295c1a8c",
|
|
7
|
+
"@theia/core": "1.46.0-next.241+4295c1a8c",
|
|
8
|
+
"@theia/filesystem": "1.46.0-next.241+4295c1a8c",
|
|
9
|
+
"@theia/monaco-editor-core": "1.83.101",
|
|
10
|
+
"@theia/output": "1.46.0-next.241+4295c1a8c",
|
|
11
|
+
"@theia/workspace": "1.46.0-next.241+4295c1a8c",
|
|
12
|
+
"minimatch": "^5.1.0",
|
|
13
|
+
"tslib": "^2.6.2"
|
|
14
|
+
},
|
|
15
|
+
"main": "lib/common",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"theiaExtensions": [
|
|
20
|
+
{
|
|
21
|
+
"frontend": "lib/browser/ai-code-completion-frontend-module"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"theia-extension"
|
|
26
|
+
],
|
|
27
|
+
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/eclipse-theia/theia.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/eclipse-theia/theia/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/eclipse-theia/theia",
|
|
36
|
+
"files": [
|
|
37
|
+
"lib",
|
|
38
|
+
"src"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "theiaext build",
|
|
42
|
+
"clean": "theiaext clean",
|
|
43
|
+
"compile": "theiaext compile",
|
|
44
|
+
"lint": "theiaext lint",
|
|
45
|
+
"test": "theiaext test",
|
|
46
|
+
"watch": "theiaext watch"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@theia/ext-scripts": "1.56.0"
|
|
50
|
+
},
|
|
51
|
+
"nyc": {
|
|
52
|
+
"extends": "../../configs/nyc.json"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "4295c1a8c8b5d23471f274265c798bac9e6baecc"
|
|
55
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ILogger } from '@theia/core';
|
|
18
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
19
|
+
import { CodeCompletionAgent, CodeCompletionAgentImpl } from './code-completion-agent';
|
|
20
|
+
import { AIFrontendApplicationContribution } from './ai-code-frontend-application-contribution';
|
|
21
|
+
import { FrontendApplicationContribution, KeybindingContribution, PreferenceContribution } from '@theia/core/lib/browser';
|
|
22
|
+
import { Agent } from '@theia/ai-core';
|
|
23
|
+
import { AICodeCompletionPreferencesSchema } from './ai-code-completion-preference';
|
|
24
|
+
import { AICodeInlineCompletionsProvider } from './ai-code-inline-completion-provider';
|
|
25
|
+
|
|
26
|
+
export default new ContainerModule(bind => {
|
|
27
|
+
bind(ILogger).toDynamicValue(ctx => {
|
|
28
|
+
const parentLogger = ctx.container.get<ILogger>(ILogger);
|
|
29
|
+
return parentLogger.child('code-completion-agent');
|
|
30
|
+
}).inSingletonScope().whenTargetNamed('code-completion-agent');
|
|
31
|
+
bind(CodeCompletionAgentImpl).toSelf().inSingletonScope();
|
|
32
|
+
bind(CodeCompletionAgent).toService(CodeCompletionAgentImpl);
|
|
33
|
+
bind(Agent).toService(CodeCompletionAgentImpl);
|
|
34
|
+
bind(AICodeInlineCompletionsProvider).toSelf().inSingletonScope();
|
|
35
|
+
bind(AIFrontendApplicationContribution).toSelf().inSingletonScope();
|
|
36
|
+
bind(FrontendApplicationContribution).to(AIFrontendApplicationContribution);
|
|
37
|
+
bind(KeybindingContribution).toService(AIFrontendApplicationContribution);
|
|
38
|
+
bind(PreferenceContribution).toConstantValue({ schema: AICodeCompletionPreferencesSchema });
|
|
39
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
|
|
18
|
+
import { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/browser/ai-core-preferences';
|
|
19
|
+
|
|
20
|
+
export const PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = 'ai-features.codeCompletion.automaticCodeCompletion';
|
|
21
|
+
export const PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = 'ai-features.codeCompletion.excludedFileExtensions';
|
|
22
|
+
export const PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = 'ai-features.codeCompletion.maxContextLines';
|
|
23
|
+
|
|
24
|
+
export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
[PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE]: {
|
|
28
|
+
title: AI_CORE_PREFERENCES_TITLE,
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
description: 'Automatically trigger AI completions inline within any (Monaco) editor while editing.\
|
|
31
|
+
\n\
|
|
32
|
+
Alternatively, you can manually trigger the code via the command "Trigger Inline Suggestion" or the default shortcut "SHIFT+Space".',
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
[PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS]: {
|
|
36
|
+
title: 'Excluded File Extensions',
|
|
37
|
+
type: 'array',
|
|
38
|
+
description: 'Specify file extensions (e.g., .md, .txt) where AI completions should be disabled.',
|
|
39
|
+
items: {
|
|
40
|
+
type: 'string'
|
|
41
|
+
},
|
|
42
|
+
default: []
|
|
43
|
+
},
|
|
44
|
+
[PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES]: {
|
|
45
|
+
title: 'Maximum Context Lines',
|
|
46
|
+
type: 'number',
|
|
47
|
+
description: 'The maximum number of lines used as context, distributed among the lines before and after the cursor position (prefix and suffix).\
|
|
48
|
+
Set this to -1 to use the full file as context without any line limit and 0 to only use the current line.',
|
|
49
|
+
default: -1,
|
|
50
|
+
minimum: -1
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
18
|
+
|
|
19
|
+
import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, PreferenceService } from '@theia/core/lib/browser';
|
|
20
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
21
|
+
import { AIActivationService } from '@theia/ai-core/lib/browser';
|
|
22
|
+
import { Disposable } from '@theia/core';
|
|
23
|
+
import { AICodeInlineCompletionsProvider } from './ai-code-inline-completion-provider';
|
|
24
|
+
import { PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS } from './ai-code-completion-preference';
|
|
25
|
+
import { InlineCompletionTriggerKind } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
|
|
26
|
+
|
|
27
|
+
@injectable()
|
|
28
|
+
export class AIFrontendApplicationContribution implements FrontendApplicationContribution, KeybindingContribution {
|
|
29
|
+
@inject(AICodeInlineCompletionsProvider)
|
|
30
|
+
private inlineCodeCompletionProvider: AICodeInlineCompletionsProvider;
|
|
31
|
+
|
|
32
|
+
@inject(PreferenceService)
|
|
33
|
+
protected readonly preferenceService: PreferenceService;
|
|
34
|
+
|
|
35
|
+
@inject(AIActivationService)
|
|
36
|
+
protected readonly activationService: AIActivationService;
|
|
37
|
+
|
|
38
|
+
private toDispose = new Map<string, Disposable>();
|
|
39
|
+
|
|
40
|
+
onDidInitializeLayout(): void {
|
|
41
|
+
this.preferenceService.ready.then(() => {
|
|
42
|
+
this.handlePreferences();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected handlePreferences(): void {
|
|
47
|
+
const handler = () => this.handleInlineCompletions();
|
|
48
|
+
|
|
49
|
+
this.toDispose.set('inlineCompletions', handler());
|
|
50
|
+
|
|
51
|
+
this.preferenceService.onPreferenceChanged(event => {
|
|
52
|
+
if (event.preferenceName === PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
|
|
53
|
+
|| event.preferenceName === PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
|
|
54
|
+
this.toDispose.get('inlineCompletions')?.dispose();
|
|
55
|
+
this.toDispose.set('inlineCompletions', handler());
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.activationService.onDidChangeActiveStatus(change => {
|
|
60
|
+
this.toDispose.get('inlineCompletions')?.dispose();
|
|
61
|
+
this.toDispose.set('inlineCompletions', handler());
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
registerKeybindings(keybindings: KeybindingRegistry): void {
|
|
66
|
+
keybindings.registerKeybinding({
|
|
67
|
+
command: 'editor.action.inlineSuggest.trigger',
|
|
68
|
+
keybinding: 'Shift+Space',
|
|
69
|
+
when: '!editorReadonly && editorTextFocus'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected handleInlineCompletions(): Disposable {
|
|
74
|
+
if (!this.activationService.isActive) {
|
|
75
|
+
return Disposable.NULL;
|
|
76
|
+
}
|
|
77
|
+
const automatic = this.preferenceService.get<boolean>(PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, true);
|
|
78
|
+
const excludedExtensions = this.preferenceService.get<string[]>(PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS, []);
|
|
79
|
+
|
|
80
|
+
return monaco.languages.registerInlineCompletionsProvider(
|
|
81
|
+
{ scheme: 'file' },
|
|
82
|
+
{
|
|
83
|
+
provideInlineCompletions: (model, position, context, token) => {
|
|
84
|
+
if (!automatic && context.triggerKind === InlineCompletionTriggerKind.Automatic) {
|
|
85
|
+
return { items: [] };
|
|
86
|
+
}
|
|
87
|
+
const fileName = model.uri.toString();
|
|
88
|
+
if (excludedExtensions.some(ext => fileName.endsWith(ext))) {
|
|
89
|
+
return { items: [] };
|
|
90
|
+
}
|
|
91
|
+
return this.inlineCodeCompletionProvider.provideInlineCompletions(model, position, context, token);
|
|
92
|
+
},
|
|
93
|
+
freeInlineCompletions: completions => {
|
|
94
|
+
this.inlineCodeCompletionProvider.freeInlineCompletions(completions);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
18
|
+
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { CodeCompletionAgent } from './code-completion-agent';
|
|
21
|
+
import { AgentService } from '@theia/ai-core';
|
|
22
|
+
|
|
23
|
+
@injectable()
|
|
24
|
+
export class AICodeInlineCompletionsProvider
|
|
25
|
+
implements monaco.languages.InlineCompletionsProvider {
|
|
26
|
+
@inject(CodeCompletionAgent)
|
|
27
|
+
protected readonly agent: CodeCompletionAgent;
|
|
28
|
+
@inject(AgentService)
|
|
29
|
+
private readonly agentService: AgentService;
|
|
30
|
+
|
|
31
|
+
async provideInlineCompletions(
|
|
32
|
+
model: monaco.editor.ITextModel,
|
|
33
|
+
position: monaco.Position,
|
|
34
|
+
context: monaco.languages.InlineCompletionContext,
|
|
35
|
+
token: monaco.CancellationToken
|
|
36
|
+
): Promise<monaco.languages.InlineCompletions | undefined> {
|
|
37
|
+
if (!this.agentService.isEnabled(this.agent.id)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return this.agent.provideInlineCompletions(
|
|
41
|
+
model,
|
|
42
|
+
position,
|
|
43
|
+
context,
|
|
44
|
+
token
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
freeInlineCompletions(
|
|
49
|
+
completions: monaco.languages.InlineCompletions<monaco.languages.InlineCompletion>
|
|
50
|
+
): void {
|
|
51
|
+
// nothing to do
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
Agent, AgentSpecificVariables, CommunicationRecordingService, getTextOfResponse,
|
|
19
|
+
LanguageModelRegistry, LanguageModelRequest, LanguageModelRequirement, PromptService, PromptTemplate
|
|
20
|
+
} from '@theia/ai-core/lib/common';
|
|
21
|
+
import { generateUuid, ILogger, ProgressService } from '@theia/core';
|
|
22
|
+
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
23
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
24
|
+
import { PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES } from './ai-code-completion-preference';
|
|
25
|
+
import { PreferenceService } from '@theia/core/lib/browser';
|
|
26
|
+
|
|
27
|
+
export const CodeCompletionAgent = Symbol('CodeCompletionAgent');
|
|
28
|
+
export interface CodeCompletionAgent extends Agent {
|
|
29
|
+
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position,
|
|
30
|
+
context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@injectable()
|
|
34
|
+
export class CodeCompletionAgentImpl implements CodeCompletionAgent {
|
|
35
|
+
async provideInlineCompletions(
|
|
36
|
+
model: monaco.editor.ITextModel,
|
|
37
|
+
position: monaco.Position,
|
|
38
|
+
context: monaco.languages.InlineCompletionContext,
|
|
39
|
+
token: monaco.CancellationToken
|
|
40
|
+
): Promise<monaco.languages.InlineCompletions | undefined> {
|
|
41
|
+
const progress = await this.progressService.showProgress(
|
|
42
|
+
{ text: 'Calculating AI code completion...', options: { location: 'window' } }
|
|
43
|
+
);
|
|
44
|
+
try {
|
|
45
|
+
const languageModel =
|
|
46
|
+
await this.languageModelRegistry.selectLanguageModel({
|
|
47
|
+
agent: this.id,
|
|
48
|
+
...this.languageModelRequirements[0],
|
|
49
|
+
});
|
|
50
|
+
if (!languageModel) {
|
|
51
|
+
this.logger.error(
|
|
52
|
+
'No language model found for code-completion-agent'
|
|
53
|
+
);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const maxContextLines = this.preferences.get<number>(PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES, -1);
|
|
58
|
+
|
|
59
|
+
let prefixStartLine = 1;
|
|
60
|
+
let suffixEndLine = model.getLineCount();
|
|
61
|
+
// if maxContextLines is -1, use the full file as context without any line limit
|
|
62
|
+
|
|
63
|
+
if (maxContextLines === 0) {
|
|
64
|
+
// Only the cursor line
|
|
65
|
+
prefixStartLine = position.lineNumber;
|
|
66
|
+
suffixEndLine = position.lineNumber;
|
|
67
|
+
} else if (maxContextLines > 0) {
|
|
68
|
+
const linesBeforeCursor = position.lineNumber - 1;
|
|
69
|
+
const linesAfterCursor = model.getLineCount() - position.lineNumber;
|
|
70
|
+
|
|
71
|
+
// Allocate one more line to the prefix in case of an odd maxContextLines
|
|
72
|
+
const prefixLines = Math.min(
|
|
73
|
+
Math.ceil(maxContextLines / 2),
|
|
74
|
+
linesBeforeCursor
|
|
75
|
+
);
|
|
76
|
+
const suffixLines = Math.min(
|
|
77
|
+
Math.floor(maxContextLines / 2),
|
|
78
|
+
linesAfterCursor
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
prefixStartLine = Math.max(1, position.lineNumber - prefixLines);
|
|
82
|
+
suffixEndLine = Math.min(model.getLineCount(), position.lineNumber + suffixLines);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const prefix = model.getValueInRange({
|
|
86
|
+
startLineNumber: prefixStartLine,
|
|
87
|
+
startColumn: 1,
|
|
88
|
+
endLineNumber: position.lineNumber,
|
|
89
|
+
endColumn: position.column,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const suffix = model.getValueInRange({
|
|
93
|
+
startLineNumber: position.lineNumber,
|
|
94
|
+
startColumn: position.column,
|
|
95
|
+
endLineNumber: suffixEndLine,
|
|
96
|
+
endColumn: model.getLineMaxColumn(suffixEndLine),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const file = model.uri.toString(false);
|
|
100
|
+
const language = model.getLanguageId();
|
|
101
|
+
|
|
102
|
+
if (token.isCancellationRequested) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const prompt = await this.promptService
|
|
106
|
+
.getPrompt('code-completion-prompt', { prefix, suffix, file, language })
|
|
107
|
+
.then(p => p?.text);
|
|
108
|
+
if (!prompt) {
|
|
109
|
+
this.logger.error('No prompt found for code-completion-agent');
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
114
|
+
const sessionId = generateUuid();
|
|
115
|
+
const requestId = generateUuid();
|
|
116
|
+
const request: LanguageModelRequest = {
|
|
117
|
+
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
118
|
+
};
|
|
119
|
+
if (token.isCancellationRequested) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
this.recordingService.recordRequest({
|
|
123
|
+
agentId: this.id,
|
|
124
|
+
sessionId,
|
|
125
|
+
requestId,
|
|
126
|
+
request: prompt,
|
|
127
|
+
});
|
|
128
|
+
const response = await languageModel.request(request, token);
|
|
129
|
+
if (token.isCancellationRequested) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const completionText = await getTextOfResponse(response);
|
|
133
|
+
if (token.isCancellationRequested) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
this.recordingService.recordResponse({
|
|
137
|
+
agentId: this.id,
|
|
138
|
+
sessionId,
|
|
139
|
+
requestId,
|
|
140
|
+
response: completionText,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
items: [{ insertText: completionText }],
|
|
145
|
+
enableForwardStability: true,
|
|
146
|
+
};
|
|
147
|
+
} finally {
|
|
148
|
+
progress.cancel();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@inject(ILogger)
|
|
153
|
+
@named('code-completion-agent')
|
|
154
|
+
protected logger: ILogger;
|
|
155
|
+
|
|
156
|
+
@inject(LanguageModelRegistry)
|
|
157
|
+
protected languageModelRegistry: LanguageModelRegistry;
|
|
158
|
+
|
|
159
|
+
@inject(PromptService)
|
|
160
|
+
protected promptService: PromptService;
|
|
161
|
+
|
|
162
|
+
@inject(CommunicationRecordingService)
|
|
163
|
+
protected recordingService: CommunicationRecordingService;
|
|
164
|
+
|
|
165
|
+
@inject(ProgressService)
|
|
166
|
+
protected progressService: ProgressService;
|
|
167
|
+
|
|
168
|
+
@inject(PreferenceService)
|
|
169
|
+
protected preferences: PreferenceService;
|
|
170
|
+
|
|
171
|
+
id = 'Code Completion';
|
|
172
|
+
name = 'Code Completion';
|
|
173
|
+
description =
|
|
174
|
+
'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
175
|
+
promptTemplates: PromptTemplate[] = [
|
|
176
|
+
{
|
|
177
|
+
id: 'code-completion-prompt',
|
|
178
|
+
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
179
|
+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
180
|
+
You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
181
|
+
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
182
|
+
Finish the following code snippet.
|
|
183
|
+
|
|
184
|
+
{{prefix}}[[MARKER]]{{suffix}}
|
|
185
|
+
|
|
186
|
+
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
languageModelRequirements: LanguageModelRequirement[] = [
|
|
190
|
+
{
|
|
191
|
+
purpose: 'code-completion',
|
|
192
|
+
identifier: 'openai/gpt-4o',
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
readonly variables: string[] = [];
|
|
196
|
+
readonly functions: string[] = [];
|
|
197
|
+
readonly agentSpecificVariables: AgentSpecificVariables[] = [
|
|
198
|
+
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
199
|
+
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
200
|
+
{ name: 'prefix', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
201
|
+
{ name: 'suffix', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
202
|
+
];
|
|
203
|
+
readonly tags?: string[] | undefined;
|
|
204
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
/* note: this bogus test file is required so that
|
|
18
|
+
we are able to run mocha unit tests on this
|
|
19
|
+
package, without having any actual unit tests in it.
|
|
20
|
+
This way a coverage report will be generated,
|
|
21
|
+
showing 0% coverage, instead of no report.
|
|
22
|
+
This file can be removed once we have real unit
|
|
23
|
+
tests in place. */
|
|
24
|
+
|
|
25
|
+
describe('ai-code-completion package', () => {
|
|
26
|
+
|
|
27
|
+
it('support code coverage statistics', () => true);
|
|
28
|
+
});
|