@theia/ai-editor 0.0.1 → 1.63.0-next.52
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 +30 -0
- package/lib/browser/ai-code-action-provider.d.ts +16 -0
- package/lib/browser/ai-code-action-provider.d.ts.map +1 -0
- package/lib/browser/ai-code-action-provider.js +97 -0
- package/lib/browser/ai-code-action-provider.js.map +1 -0
- package/lib/browser/ai-editor-command-contribution.d.ts +7 -2
- package/lib/browser/ai-editor-command-contribution.d.ts.map +1 -1
- package/lib/browser/ai-editor-command-contribution.js +79 -9
- package/lib/browser/ai-editor-command-contribution.js.map +1 -1
- package/lib/browser/ai-editor-context-variable.d.ts +4 -0
- package/lib/browser/ai-editor-context-variable.d.ts.map +1 -1
- package/lib/browser/ai-editor-context-variable.js +67 -5
- package/lib/browser/ai-editor-context-variable.js.map +1 -1
- package/lib/browser/ai-editor-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-editor-frontend-module.js +8 -3
- package/lib/browser/ai-editor-frontend-module.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/ai-code-action-provider.ts +98 -0
- package/src/browser/ai-editor-command-contribution.ts +82 -8
- package/src/browser/ai-editor-context-variable.ts +85 -5
- package/src/browser/ai-editor-frontend-module.ts +9 -3
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 Editor</h2>
|
|
8
|
+
|
|
9
|
+
<hr />
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
The `@theia/ai-editor` extension brings AI-powered code actions and editor context interaction to Theia. It allows users to interact with AI directly in the editor for code explanations, fixes, and suggestions using AI agents.
|
|
16
|
+
|
|
17
|
+
## Additional Information
|
|
18
|
+
|
|
19
|
+
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
20
|
+
- [Theia - Website](https://theia-ide.org/)
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
25
|
+
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
26
|
+
|
|
27
|
+
## Trademark
|
|
28
|
+
|
|
29
|
+
"Theia" is a trademark of the Eclipse Foundation
|
|
30
|
+
<https://www.eclipse.org/theia>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
2
|
+
import { CommandService } from '@theia/core/lib/common/command';
|
|
3
|
+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
4
|
+
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
|
|
5
|
+
export declare const AI_EDITOR_SEND_TO_CHAT: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class AICodeActionProvider implements FrontendApplicationContribution {
|
|
9
|
+
protected readonly commandService: CommandService;
|
|
10
|
+
protected readonly monacoEditorService: MonacoEditorService;
|
|
11
|
+
protected readonly toDispose: DisposableCollection;
|
|
12
|
+
onStart(): void;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
protected registerCodeActionProvider(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ai-code-action-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-action-provider.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-action-provider.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAC;AAEtF,eAAO,MAAM,sBAAsB;;CAElC,CAAC;AAEF,qBACa,oBAAqB,YAAW,+BAA+B;IAGxE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAGlD,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAE5D,SAAS,CAAC,QAAQ,CAAC,SAAS,uBAA8B;IAE1D,OAAO,IAAI,IAAI;IAIf,OAAO,IAAI,IAAI;IAIf,SAAS,CAAC,0BAA0B,IAAI,IAAI;CAmD/C"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2025 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.AICodeActionProvider = exports.AI_EDITOR_SEND_TO_CHAT = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const command_1 = require("@theia/core/lib/common/command");
|
|
21
|
+
const disposable_1 = require("@theia/core/lib/common/disposable");
|
|
22
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
|
+
const monaco = require("@theia/monaco-editor-core");
|
|
24
|
+
const monaco_editor_service_1 = require("@theia/monaco/lib/browser/monaco-editor-service");
|
|
25
|
+
exports.AI_EDITOR_SEND_TO_CHAT = {
|
|
26
|
+
id: 'ai-editor.sendToChat',
|
|
27
|
+
};
|
|
28
|
+
let AICodeActionProvider = class AICodeActionProvider {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.toDispose = new disposable_1.DisposableCollection();
|
|
31
|
+
}
|
|
32
|
+
onStart() {
|
|
33
|
+
this.registerCodeActionProvider();
|
|
34
|
+
}
|
|
35
|
+
dispose() {
|
|
36
|
+
this.toDispose.dispose();
|
|
37
|
+
}
|
|
38
|
+
registerCodeActionProvider() {
|
|
39
|
+
const disposable = monaco.languages.registerCodeActionProvider('*', {
|
|
40
|
+
provideCodeActions: (model, range, context, token) => {
|
|
41
|
+
// Filter for error markers only
|
|
42
|
+
const errorMarkers = context.markers.filter(marker => marker.severity === monaco.MarkerSeverity.Error);
|
|
43
|
+
if (errorMarkers.length === 0) {
|
|
44
|
+
return { actions: [], dispose: () => { } };
|
|
45
|
+
}
|
|
46
|
+
const actions = [];
|
|
47
|
+
// Create code actions for each error marker: Fix with AI and Explain with AI
|
|
48
|
+
errorMarkers.forEach(marker => {
|
|
49
|
+
actions.push({
|
|
50
|
+
title: 'Fix with AI',
|
|
51
|
+
diagnostics: [marker],
|
|
52
|
+
isAI: true,
|
|
53
|
+
kind: 'quickfix',
|
|
54
|
+
command: {
|
|
55
|
+
id: exports.AI_EDITOR_SEND_TO_CHAT.id,
|
|
56
|
+
title: 'Fix with AI',
|
|
57
|
+
arguments: [{
|
|
58
|
+
prompt: `@Coder Help to fix this error: "${marker.message}"`
|
|
59
|
+
}]
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
actions.push({
|
|
63
|
+
title: 'Explain with AI',
|
|
64
|
+
diagnostics: [marker],
|
|
65
|
+
kind: 'quickfix',
|
|
66
|
+
isAI: true,
|
|
67
|
+
command: {
|
|
68
|
+
id: exports.AI_EDITOR_SEND_TO_CHAT.id,
|
|
69
|
+
title: 'Explain with AI',
|
|
70
|
+
arguments: [{
|
|
71
|
+
prompt: `@Architect Explain this error: "${marker.message}"`
|
|
72
|
+
}]
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
actions: actions,
|
|
78
|
+
dispose: () => { }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.toDispose.push(disposable);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.AICodeActionProvider = AICodeActionProvider;
|
|
86
|
+
tslib_1.__decorate([
|
|
87
|
+
(0, inversify_1.inject)(command_1.CommandService),
|
|
88
|
+
tslib_1.__metadata("design:type", Object)
|
|
89
|
+
], AICodeActionProvider.prototype, "commandService", void 0);
|
|
90
|
+
tslib_1.__decorate([
|
|
91
|
+
(0, inversify_1.inject)(monaco_editor_service_1.MonacoEditorService),
|
|
92
|
+
tslib_1.__metadata("design:type", monaco_editor_service_1.MonacoEditorService)
|
|
93
|
+
], AICodeActionProvider.prototype, "monacoEditorService", void 0);
|
|
94
|
+
exports.AICodeActionProvider = AICodeActionProvider = tslib_1.__decorate([
|
|
95
|
+
(0, inversify_1.injectable)()
|
|
96
|
+
], AICodeActionProvider);
|
|
97
|
+
//# sourceMappingURL=ai-code-action-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-code-action-provider.js","sourceRoot":"","sources":["../../src/browser/ai-code-action-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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B,KAAK,EAAE,aAAa;4BACpB,SAAS,EAAE,CAAC;oCACR,MAAM,EAAE,mCAAmC,MAAM,CAAC,OAAO,GAAG;iCAC/D,CAAC;yBACL;qBACJ,CAAC,CAAC;oBACH,OAAO,CAAC,IAAI,CAAC;wBACT,KAAK,EAAE,iBAAiB;wBACxB,WAAW,EAAE,CAAC,MAAM,CAAC;wBACrB,IAAI,EAAE,UAAU;wBAChB,IAAI,EAAE,IAAI;wBACV,OAAO,EAAE;4BACL,EAAE,EAAE,8BAAsB,CAAC,EAAE;4BAC7B,KAAK,EAAE,iBAAiB;4BACxB,SAAS,EAAE,CAAC;oCACR,MAAM,EAAE,mCAAmC,MAAM,CAAC,OAAO,GAAG;iCAC/D,CAAC;yBACL;qBACJ,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;gBACH,OAAO;oBACH,OAAO,EAAE,OAAO;oBAChB,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC;iBACrB,CAAC;YACN,CAAC;SACJ,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;CACJ,CAAA;AArEY,oDAAoB;AAGV;IADlB,IAAA,kBAAM,EAAC,wBAAc,CAAC;;4DAC2B;AAG/B;IADlB,IAAA,kBAAM,EAAC,2CAAmB,CAAC;sCACY,2CAAmB;iEAAC;+BANnD,oBAAoB;IADhC,IAAA,sBAAU,GAAE;GACA,oBAAoB,CAqEhC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { ChatService } from '@theia/ai-chat';
|
|
1
2
|
import { MenuContribution, MenuModelRegistry } from '@theia/core';
|
|
3
|
+
import { KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
|
|
2
4
|
import { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common';
|
|
3
5
|
import { MonacoCommandRegistry, MonacoEditorCommandHandler } from '@theia/monaco/lib/browser/monaco-command-registry';
|
|
4
|
-
import { ChatService } from '@theia/ai-chat';
|
|
5
6
|
export declare namespace AI_EDITOR_COMMANDS {
|
|
6
7
|
const AI_EDITOR_ASK_AI: Command;
|
|
8
|
+
const AI_EDITOR_SEND_TO_CHAT: Command;
|
|
7
9
|
}
|
|
8
|
-
export declare class AiEditorCommandContribution implements CommandContribution, MenuContribution {
|
|
10
|
+
export declare class AiEditorCommandContribution implements CommandContribution, MenuContribution, KeybindingContribution {
|
|
9
11
|
protected readonly monacoCommandRegistry: MonacoCommandRegistry;
|
|
10
12
|
protected readonly chatService: ChatService;
|
|
11
13
|
private askAiInputWidget;
|
|
@@ -13,6 +15,9 @@ export declare class AiEditorCommandContribution implements CommandContribution,
|
|
|
13
15
|
protected showInputWidgetHandler(): MonacoEditorCommandHandler;
|
|
14
16
|
private showInputWidget;
|
|
15
17
|
private cleanupInputWidget;
|
|
18
|
+
protected sendToChatHandler(): MonacoEditorCommandHandler;
|
|
19
|
+
private createNewChatSession;
|
|
16
20
|
registerMenus(menus: MenuModelRegistry): void;
|
|
21
|
+
registerKeybindings(registry: KeybindingRegistry): void;
|
|
17
22
|
}
|
|
18
23
|
//# sourceMappingURL=ai-editor-command-contribution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-editor-command-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ai-editor-command-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-editor-command-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ai-editor-command-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAqB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIvF,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,mDAAmD,CAAC;AAItH,yBAAiB,kBAAkB,CAAC;IACzB,MAAM,gBAAgB,EAAE,OAG9B,CAAC;IACK,MAAM,sBAAsB,EAAE,OAGpC,CAAC;CACL;AAED,qBACa,2BAA4B,YAAW,mBAAmB,EAAE,gBAAgB,EAAE,sBAAsB;IAG7G,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGhE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAE5C,OAAO,CAAC,gBAAgB,CAA+B;IAEvD,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAQjD,SAAS,CAAC,sBAAsB,IAAI,0BAA0B;IAmD9D,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,kBAAkB;IAO1B,SAAS,CAAC,iBAAiB,IAAI,0BAA0B;IAUzD,OAAO,CAAC,oBAAoB;IAO5B,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAO7C,mBAAmB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;CAO1D"}
|
|
@@ -17,29 +17,80 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AiEditorCommandContribution = exports.AI_EDITOR_COMMANDS = void 0;
|
|
19
19
|
const tslib_1 = require("tslib");
|
|
20
|
+
const ai_chat_1 = require("@theia/ai-chat");
|
|
21
|
+
const browser_1 = require("@theia/ai-core/lib/browser");
|
|
20
22
|
const nls_1 = require("@theia/core/lib/common/nls");
|
|
21
23
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
-
const
|
|
24
|
+
const browser_2 = require("@theia/editor/lib/browser");
|
|
23
25
|
const monaco_command_registry_1 = require("@theia/monaco/lib/browser/monaco-command-registry");
|
|
24
26
|
const ask_ai_input_widget_1 = require("./ask-ai-input-widget");
|
|
25
|
-
const ai_chat_1 = require("@theia/ai-chat");
|
|
26
27
|
var AI_EDITOR_COMMANDS;
|
|
27
28
|
(function (AI_EDITOR_COMMANDS) {
|
|
28
29
|
AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI = {
|
|
29
30
|
id: 'ai-editor.contextAction',
|
|
30
31
|
label: nls_1.nls.localize('theia/ai-editor/contextMenu', 'Ask AI [Experimental]')
|
|
31
32
|
};
|
|
33
|
+
AI_EDITOR_COMMANDS.AI_EDITOR_SEND_TO_CHAT = {
|
|
34
|
+
id: 'ai-editor.sendToChat',
|
|
35
|
+
label: nls_1.nls.localize('theia/ai-editor/sendToChat', 'Send to AI Chat [Experimental]')
|
|
36
|
+
};
|
|
32
37
|
})(AI_EDITOR_COMMANDS || (exports.AI_EDITOR_COMMANDS = AI_EDITOR_COMMANDS = {}));
|
|
33
38
|
;
|
|
34
39
|
let AiEditorCommandContribution = class AiEditorCommandContribution {
|
|
35
40
|
registerCommands(registry) {
|
|
36
41
|
registry.registerCommand(AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI);
|
|
42
|
+
registry.registerCommand(AI_EDITOR_COMMANDS.AI_EDITOR_SEND_TO_CHAT);
|
|
37
43
|
this.monacoCommandRegistry.registerHandler(AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.id, this.showInputWidgetHandler());
|
|
44
|
+
this.monacoCommandRegistry.registerHandler(AI_EDITOR_COMMANDS.AI_EDITOR_SEND_TO_CHAT.id, this.sendToChatHandler());
|
|
38
45
|
}
|
|
39
46
|
showInputWidgetHandler() {
|
|
40
47
|
return {
|
|
41
|
-
execute: (
|
|
42
|
-
|
|
48
|
+
execute: (editor, position) => {
|
|
49
|
+
let coordinates;
|
|
50
|
+
if (position) {
|
|
51
|
+
// Called from context menu - use provided position
|
|
52
|
+
coordinates = { x: position.x, y: position.y + 10 };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Called from keybinding - calculate position from cursor in editor
|
|
56
|
+
const cursorPosition = editor.getControl().getPosition();
|
|
57
|
+
if (cursorPosition) {
|
|
58
|
+
const editorNode = editor.getControl().getDomNode();
|
|
59
|
+
if (editorNode) {
|
|
60
|
+
const editorRect = editorNode.getBoundingClientRect();
|
|
61
|
+
const coordinatesInEditor = editor.getControl().getScrolledVisiblePosition(cursorPosition);
|
|
62
|
+
if (coordinatesInEditor) {
|
|
63
|
+
// Calculate screen coordinates from editor-relative coordinates
|
|
64
|
+
coordinates = {
|
|
65
|
+
x: editorRect.left + coordinatesInEditor.left,
|
|
66
|
+
y: editorRect.top + coordinatesInEditor.top + coordinatesInEditor.height + 5
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Fallback: center of editor viewport
|
|
71
|
+
coordinates = {
|
|
72
|
+
x: editorRect.left + editorRect.width / 2,
|
|
73
|
+
y: editorRect.top + editorRect.height / 2
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Ultimate fallback: center of screen
|
|
79
|
+
coordinates = {
|
|
80
|
+
x: window.innerWidth / 2,
|
|
81
|
+
y: window.innerHeight / 2
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Fallback if no cursor position available
|
|
87
|
+
coordinates = {
|
|
88
|
+
x: window.innerWidth / 2,
|
|
89
|
+
y: window.innerHeight / 2
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.showInputWidget(coordinates);
|
|
43
94
|
}
|
|
44
95
|
};
|
|
45
96
|
}
|
|
@@ -47,10 +98,7 @@ let AiEditorCommandContribution = class AiEditorCommandContribution {
|
|
|
47
98
|
this.cleanupInputWidget();
|
|
48
99
|
this.askAiInputWidget = new ask_ai_input_widget_1.AskAIInputWidget();
|
|
49
100
|
this.askAiInputWidget.onSubmit(event => {
|
|
50
|
-
|
|
51
|
-
this.chatService.sendRequest(session.id, {
|
|
52
|
-
text: `${event.userInput} #editorContext`
|
|
53
|
-
});
|
|
101
|
+
this.createNewChatSession(event.userInput);
|
|
54
102
|
});
|
|
55
103
|
this.askAiInputWidget.show(coordinates);
|
|
56
104
|
this.askAiInputWidget.onCancel(() => {
|
|
@@ -63,12 +111,34 @@ let AiEditorCommandContribution = class AiEditorCommandContribution {
|
|
|
63
111
|
this.askAiInputWidget = undefined;
|
|
64
112
|
}
|
|
65
113
|
}
|
|
114
|
+
sendToChatHandler() {
|
|
115
|
+
return {
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
+
execute: (_editor, ...args) => {
|
|
118
|
+
const prompt = args[0].prompt;
|
|
119
|
+
this.createNewChatSession(prompt);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
createNewChatSession(prompt) {
|
|
124
|
+
const session = this.chatService.createSession(ai_chat_1.ChatAgentLocation.Panel, { focus: true });
|
|
125
|
+
this.chatService.sendRequest(session.id, {
|
|
126
|
+
text: `${prompt} #editorContext`
|
|
127
|
+
});
|
|
128
|
+
}
|
|
66
129
|
registerMenus(menus) {
|
|
67
|
-
menus.registerMenuAction(
|
|
130
|
+
menus.registerMenuAction(browser_2.EditorContextMenu.NAVIGATION, {
|
|
68
131
|
commandId: AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.id,
|
|
69
132
|
label: AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.label
|
|
70
133
|
});
|
|
71
134
|
}
|
|
135
|
+
registerKeybindings(registry) {
|
|
136
|
+
registry.registerKeybinding({
|
|
137
|
+
command: AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.id,
|
|
138
|
+
keybinding: 'ctrlcmd+i',
|
|
139
|
+
when: `${browser_1.ENABLE_AI_CONTEXT_KEY} && editorFocus && !editorReadonly`
|
|
140
|
+
});
|
|
141
|
+
}
|
|
72
142
|
};
|
|
73
143
|
exports.AiEditorCommandContribution = AiEditorCommandContribution;
|
|
74
144
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-editor-command-contribution.js","sourceRoot":"","sources":["../../src/browser/ai-editor-command-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;;;;
|
|
1
|
+
{"version":3,"file":"ai-editor-command-contribution.js","sourceRoot":"","sources":["../../src/browser/ai-editor-command-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,4CAAgE;AAChE,wDAAmE;AAKnE,oDAAiD;AACjD,4DAAkE;AAClE,uDAA8D;AAC9D,+FAAsH;AAEtH,+DAAyD;AAEzD,IAAiB,kBAAkB,CASlC;AATD,WAAiB,kBAAkB;IAClB,mCAAgB,GAAY;QACrC,EAAE,EAAE,yBAAyB;QAC7B,KAAK,EAAE,SAAG,CAAC,QAAQ,CAAC,6BAA6B,EAAE,uBAAuB,CAAC;KAC9E,CAAC;IACW,yCAAsB,GAAY;QAC3C,EAAE,EAAE,sBAAsB;QAC1B,KAAK,EAAE,SAAG,CAAC,QAAQ,CAAC,4BAA4B,EAAE,gCAAgC,CAAC;KACtF,CAAC;AACN,CAAC,EATgB,kBAAkB,kCAAlB,kBAAkB,QASlC;AAAA,CAAC;AAGK,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAUpC,gBA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IAAA,kBAAM,EAAC,+CAAqB,CAAC;sCACY,+CAAqB;0EAAC;AAG7C;IADlB,IAAA,kBAAM,EAAC,qBAAW,CAAC;;gEACwB;sCANnC,2BAA2B;IADvC,IAAA,sBAAU,GAAE;GACA,2BAA2B,CA2HvC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AIVariable, AIVariableContext, AIVariableContribution, AIVariableResolutionRequest, AIVariableResolver, ResolvedAIContextVariable } from '@theia/ai-core';
|
|
2
2
|
import { FrontendVariableService } from '@theia/ai-core/lib/browser';
|
|
3
|
+
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
|
3
4
|
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
|
4
5
|
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
|
6
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
5
7
|
export declare const EDITOR_CONTEXT_VARIABLE: AIVariable;
|
|
6
8
|
export declare class EditorContextVariableContribution implements AIVariableContribution, AIVariableResolver {
|
|
7
9
|
protected readonly monacoEditors: MonacoEditorProvider;
|
|
@@ -9,5 +11,7 @@ export declare class EditorContextVariableContribution implements AIVariableCont
|
|
|
9
11
|
registerVariables(service: FrontendVariableService): void;
|
|
10
12
|
canResolve(request: AIVariableResolutionRequest, _: AIVariableContext): Promise<number>;
|
|
11
13
|
resolve(request: AIVariableResolutionRequest, _: AIVariableContext): Promise<ResolvedAIContextVariable | undefined>;
|
|
14
|
+
protected getDiagnosticContext(editor: MonacoEditor): Record<string, unknown>;
|
|
15
|
+
protected severityToString(severity: monaco.MarkerSeverity): string;
|
|
12
16
|
}
|
|
13
17
|
//# sourceMappingURL=ai-editor-context-variable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-editor-context-variable.d.ts","sourceRoot":"","sources":["../../src/browser/ai-editor-context-variable.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,iB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B,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAyD7E,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,GAAG,MAAM;CActE"}
|
|
@@ -21,6 +21,7 @@ const inversify_1 = require("@theia/core/shared/inversify");
|
|
|
21
21
|
const browser_1 = require("@theia/core/lib/browser");
|
|
22
22
|
const monaco_editor_provider_1 = require("@theia/monaco/lib/browser/monaco-editor-provider");
|
|
23
23
|
const workspace_service_1 = require("@theia/workspace/lib/browser/workspace-service");
|
|
24
|
+
const monaco = require("@theia/monaco-editor-core");
|
|
24
25
|
exports.EDITOR_CONTEXT_VARIABLE = {
|
|
25
26
|
id: 'editorContext',
|
|
26
27
|
description: 'Resolves editor specific context information',
|
|
@@ -59,10 +60,8 @@ let EditorContextVariableContribution = class EditorContextVariableContribution
|
|
|
59
60
|
const column = position ? position.column : 0;
|
|
60
61
|
// Get workspace-relative path
|
|
61
62
|
const workspaceRelativePath = uri ? await this.workspaceService.getWorkspaceRelativePath(uri) : '';
|
|
62
|
-
// Create
|
|
63
|
-
const
|
|
64
|
-
Metadata provided by the user:
|
|
65
|
-
${JSON.stringify({
|
|
63
|
+
// Create base context information
|
|
64
|
+
const baseContext = {
|
|
66
65
|
file: {
|
|
67
66
|
uri: workspaceRelativePath,
|
|
68
67
|
languageId,
|
|
@@ -81,13 +80,76 @@ let EditorContextVariableContribution = class EditorContextVariableContribution
|
|
|
81
80
|
column,
|
|
82
81
|
lineContent: position ? model.getLineContent(position.lineNumber) : ''
|
|
83
82
|
}
|
|
84
|
-
}
|
|
83
|
+
};
|
|
84
|
+
const diagnostics = await this.getDiagnosticContext(editor);
|
|
85
|
+
const fullContext = {
|
|
86
|
+
...baseContext,
|
|
87
|
+
diagnostics
|
|
88
|
+
};
|
|
89
|
+
const contextValue = JSON.stringify(fullContext, undefined, 2);
|
|
85
90
|
return {
|
|
86
91
|
variable: request.variable,
|
|
87
92
|
value: contextValue, // Simplified visible value
|
|
88
93
|
contextValue // Full detailed context for AI processing
|
|
89
94
|
};
|
|
90
95
|
}
|
|
96
|
+
getDiagnosticContext(editor) {
|
|
97
|
+
const model = editor.getControl().getModel();
|
|
98
|
+
if (!model) {
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
const markers = monaco.editor.getModelMarkers({ resource: model.uri });
|
|
102
|
+
if (markers.length === 0) {
|
|
103
|
+
return {
|
|
104
|
+
errorCount: 0,
|
|
105
|
+
warningCount: 0,
|
|
106
|
+
infoCount: 0,
|
|
107
|
+
hintCount: 0,
|
|
108
|
+
totalIssues: 0
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const issues = [];
|
|
112
|
+
const markerCounter = {
|
|
113
|
+
[monaco.MarkerSeverity.Error]: 0,
|
|
114
|
+
[monaco.MarkerSeverity.Warning]: 0,
|
|
115
|
+
[monaco.MarkerSeverity.Info]: 0,
|
|
116
|
+
[monaco.MarkerSeverity.Hint]: 0
|
|
117
|
+
};
|
|
118
|
+
markers.forEach(marker => {
|
|
119
|
+
markerCounter[marker.severity]++;
|
|
120
|
+
issues.push({
|
|
121
|
+
line: marker.startLineNumber,
|
|
122
|
+
column: marker.startColumn,
|
|
123
|
+
severity: this.severityToString(marker.severity),
|
|
124
|
+
message: marker.message,
|
|
125
|
+
source: marker.source
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
diagnosticCounts: {
|
|
130
|
+
errorCount: markerCounter[monaco.MarkerSeverity.Error],
|
|
131
|
+
warningCount: markerCounter[monaco.MarkerSeverity.Warning],
|
|
132
|
+
infoCount: markerCounter[monaco.MarkerSeverity.Info],
|
|
133
|
+
hintCount: markerCounter[monaco.MarkerSeverity.Hint]
|
|
134
|
+
},
|
|
135
|
+
totalIssues: markers.length,
|
|
136
|
+
issues
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
severityToString(severity) {
|
|
140
|
+
switch (severity) {
|
|
141
|
+
case monaco.MarkerSeverity.Error:
|
|
142
|
+
return 'error';
|
|
143
|
+
case monaco.MarkerSeverity.Warning:
|
|
144
|
+
return 'warning';
|
|
145
|
+
case monaco.MarkerSeverity.Info:
|
|
146
|
+
return 'info';
|
|
147
|
+
case monaco.MarkerSeverity.Hint:
|
|
148
|
+
return 'hint';
|
|
149
|
+
default:
|
|
150
|
+
return 'unknown';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
91
153
|
};
|
|
92
154
|
exports.EditorContextVariableContribution = EditorContextVariableContribution;
|
|
93
155
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-editor-context-variable.js","sourceRoot":"","sources":["../../src/browser/ai-editor-context-variable.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,qDAAuD;
|
|
1
|
+
{"version":3,"file":"ai-editor-context-variable.js","sourceRoot":"","sources":["../../src/browser/ai-editor-context-variable.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,qDAAuD;AAEvD,6FAAwF;AACxF,sFAAkF;AAClF,oDAAoD;AAEvC,QAAA,uBAAuB,GAAe;IAC/C,EAAE,EAAE,eAAe;IACnB,WAAW,EAAE,8CAA8C;IAC3D,IAAI,EAAE,eAAe;IACrB,KAAK,EAA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vB,MAAM,EAAE,MAAM,CAAC,MAAM;aACxB,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,OAAO;YACH,gBAAgB,EAAE;gBACd,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;gBACtD,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC;gBAC1D,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACpD,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;aACvD;YACD,WAAW,EAAE,OAAO,CAAC,MAAM;YAC3B,MAAM;SACT,CAAC;IACN,CAAC;IAES,gBAAgB,CAAC,QAA+B;QACtD,QAAQ,QAAQ,EAAE,CAAC;YACf,KAAK,MAAM,CAAC,cAAc,CAAC,KAAK;gBAC5B,OAAO,OAAO,CAAC;YACnB,KAAK,MAAM,CAAC,cAAc,CAAC,OAAO;gBAC9B,OAAO,SAAS,CAAC;YACrB,KAAK,MAAM,CAAC,cAAc,CAAC,IAAI;gBAC3B,OAAO,MAAM,CAAC;YAClB,KAAK,MAAM,CAAC,cAAc,CAAC,IAAI;gBAC3B,OAAO,MAAM,CAAC;YAClB;gBACI,OAAO,SAAS,CAAC;QACzB,CAAC;IACL,CAAC;CACJ,CAAA;AAzJY,8EAAiC;AAGvB;IADlB,IAAA,kBAAM,EAAC,6CAAoB,CAAC;sCACK,6CAAoB;wEAAC;AAGpC;IADlB,IAAA,kBAAM,EAAC,oCAAgB,CAAC;sCACY,oCAAgB;2EAAC;4CAN7C,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAyJ7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-editor-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ai-editor-frontend-module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-editor-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ai-editor-frontend-module.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,8BAA8B,CAAC;;AAKtC,wBAWG"}
|
|
@@ -15,16 +15,21 @@
|
|
|
15
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const
|
|
18
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
19
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
19
20
|
const common_1 = require("@theia/core/lib/common");
|
|
20
|
-
const
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
22
|
require("../../style/ask-ai-input.css");
|
|
23
|
+
const ai_code_action_provider_1 = require("./ai-code-action-provider");
|
|
24
|
+
const ai_editor_command_contribution_1 = require("./ai-editor-command-contribution");
|
|
22
25
|
const ai_editor_context_variable_1 = require("./ai-editor-context-variable");
|
|
23
|
-
const ai_core_1 = require("@theia/ai-core");
|
|
24
26
|
exports.default = new inversify_1.ContainerModule(bind => {
|
|
25
27
|
bind(ai_editor_command_contribution_1.AiEditorCommandContribution).toSelf().inSingletonScope();
|
|
26
28
|
bind(common_1.CommandContribution).toService(ai_editor_command_contribution_1.AiEditorCommandContribution);
|
|
27
29
|
bind(common_1.MenuContribution).toService(ai_editor_command_contribution_1.AiEditorCommandContribution);
|
|
30
|
+
bind(browser_1.KeybindingContribution).toService(ai_editor_command_contribution_1.AiEditorCommandContribution);
|
|
28
31
|
bind(ai_core_1.AIVariableContribution).to(ai_editor_context_variable_1.EditorContextVariableContribution).inSingletonScope();
|
|
32
|
+
bind(ai_code_action_provider_1.AICodeActionProvider).toSelf().inSingletonScope();
|
|
33
|
+
bind(browser_1.FrontendApplicationContribution).toService(ai_code_action_provider_1.AICodeActionProvider);
|
|
29
34
|
});
|
|
30
35
|
//# sourceMappingURL=ai-editor-frontend-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-editor-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ai-editor-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,
|
|
1
|
+
{"version":3,"file":"ai-editor-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ai-editor-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,4CAAwD;AACxD,qDAAkG;AAClG,mDAA+E;AAC/E,4DAA+D;AAC/D,wCAAsC;AACtC,uEAAiE;AACjE,qFAA+E;AAC/E,6EAAiF;AAEjF,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,4DAA2B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAE9D,IAAI,CAAC,4BAAmB,CAAC,CAAC,SAAS,CAAC,4DAA2B,CAAC,CAAC;IACjE,IAAI,CAAC,yBAAgB,CAAC,CAAC,SAAS,CAAC,4DAA2B,CAAC,CAAC;IAC9D,IAAI,CAAC,gCAAsB,CAAC,CAAC,SAAS,CAAC,4DAA2B,CAAC,CAAC;IAEpE,IAAI,CAAC,gCAAsB,CAAC,CAAC,EAAE,CAAC,8DAAiC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAEtF,IAAI,CAAC,8CAAoB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACvD,IAAI,CAAC,yCAA+B,CAAC,CAAC,SAAS,CAAC,8CAAoB,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-editor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.63.0-next.52+176018e53",
|
|
4
4
|
"description": "Theia - AI Editor",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-chat": "1.
|
|
7
|
-
"@theia/ai-core": "1.
|
|
8
|
-
"@theia/core": "1.
|
|
9
|
-
"@theia/editor": "1.
|
|
10
|
-
"@theia/filesystem": "1.
|
|
11
|
-
"@theia/monaco": "1.
|
|
6
|
+
"@theia/ai-chat": "1.63.0-next.52+176018e53",
|
|
7
|
+
"@theia/ai-core": "1.63.0-next.52+176018e53",
|
|
8
|
+
"@theia/core": "1.63.0-next.52+176018e53",
|
|
9
|
+
"@theia/editor": "1.63.0-next.52+176018e53",
|
|
10
|
+
"@theia/filesystem": "1.63.0-next.52+176018e53",
|
|
11
|
+
"@theia/monaco": "1.63.0-next.52+176018e53",
|
|
12
12
|
"@theia/monaco-editor-core": "1.96.302",
|
|
13
|
-
"@theia/workspace": "1.
|
|
13
|
+
"@theia/workspace": "1.63.0-next.52+176018e53"
|
|
14
14
|
},
|
|
15
15
|
"main": "lib/common",
|
|
16
16
|
"publishConfig": {
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"nyc": {
|
|
54
54
|
"extends": "../../configs/nyc.json"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "176018e53e62cafec9b25b23ac9f0b4826b6d0f7"
|
|
57
57
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 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 { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
18
|
+
import { CommandService } from '@theia/core/lib/common/command';
|
|
19
|
+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
20
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
21
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
22
|
+
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
|
|
23
|
+
|
|
24
|
+
export const AI_EDITOR_SEND_TO_CHAT = {
|
|
25
|
+
id: 'ai-editor.sendToChat',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
@injectable()
|
|
29
|
+
export class AICodeActionProvider implements FrontendApplicationContribution {
|
|
30
|
+
|
|
31
|
+
@inject(CommandService)
|
|
32
|
+
protected readonly commandService: CommandService;
|
|
33
|
+
|
|
34
|
+
@inject(MonacoEditorService)
|
|
35
|
+
protected readonly monacoEditorService: MonacoEditorService;
|
|
36
|
+
|
|
37
|
+
protected readonly toDispose = new DisposableCollection();
|
|
38
|
+
|
|
39
|
+
onStart(): void {
|
|
40
|
+
this.registerCodeActionProvider();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
dispose(): void {
|
|
44
|
+
this.toDispose.dispose();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected registerCodeActionProvider(): void {
|
|
48
|
+
const disposable = monaco.languages.registerCodeActionProvider('*', {
|
|
49
|
+
provideCodeActions: (model, range, context, token) => {
|
|
50
|
+
// Filter for error markers only
|
|
51
|
+
const errorMarkers = context.markers.filter(marker =>
|
|
52
|
+
marker.severity === monaco.MarkerSeverity.Error);
|
|
53
|
+
|
|
54
|
+
if (errorMarkers.length === 0) {
|
|
55
|
+
return { actions: [], dispose: () => { } };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const actions: monaco.languages.CodeAction[] = [];
|
|
59
|
+
|
|
60
|
+
// Create code actions for each error marker: Fix with AI and Explain with AI
|
|
61
|
+
errorMarkers.forEach(marker => {
|
|
62
|
+
actions.push({
|
|
63
|
+
title: 'Fix with AI',
|
|
64
|
+
diagnostics: [marker],
|
|
65
|
+
isAI: true,
|
|
66
|
+
kind: 'quickfix',
|
|
67
|
+
command: {
|
|
68
|
+
id: AI_EDITOR_SEND_TO_CHAT.id,
|
|
69
|
+
title: 'Fix with AI',
|
|
70
|
+
arguments: [{
|
|
71
|
+
prompt: `@Coder Help to fix this error: "${marker.message}"`
|
|
72
|
+
}]
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
actions.push({
|
|
76
|
+
title: 'Explain with AI',
|
|
77
|
+
diagnostics: [marker],
|
|
78
|
+
kind: 'quickfix',
|
|
79
|
+
isAI: true,
|
|
80
|
+
command: {
|
|
81
|
+
id: AI_EDITOR_SEND_TO_CHAT.id,
|
|
82
|
+
title: 'Explain with AI',
|
|
83
|
+
arguments: [{
|
|
84
|
+
prompt: `@Architect Explain this error: "${marker.message}"`
|
|
85
|
+
}]
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
actions: actions,
|
|
91
|
+
dispose: () => { }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.toDispose.push(disposable);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
+
import { ChatAgentLocation, ChatService } from '@theia/ai-chat';
|
|
18
|
+
import { ENABLE_AI_CONTEXT_KEY } from '@theia/ai-core/lib/browser';
|
|
17
19
|
import { MenuContribution, MenuModelRegistry } from '@theia/core';
|
|
20
|
+
import { KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
|
|
18
21
|
import { Coordinate } from '@theia/core/lib/browser/context-menu-renderer';
|
|
19
22
|
import { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common';
|
|
20
23
|
import { nls } from '@theia/core/lib/common/nls';
|
|
@@ -23,17 +26,20 @@ import { EditorContextMenu } from '@theia/editor/lib/browser';
|
|
|
23
26
|
import { MonacoCommandRegistry, MonacoEditorCommandHandler } from '@theia/monaco/lib/browser/monaco-command-registry';
|
|
24
27
|
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
|
25
28
|
import { AskAIInputWidget } from './ask-ai-input-widget';
|
|
26
|
-
import { ChatAgentLocation, ChatService } from '@theia/ai-chat';
|
|
27
29
|
|
|
28
30
|
export namespace AI_EDITOR_COMMANDS {
|
|
29
31
|
export const AI_EDITOR_ASK_AI: Command = {
|
|
30
32
|
id: 'ai-editor.contextAction',
|
|
31
33
|
label: nls.localize('theia/ai-editor/contextMenu', 'Ask AI [Experimental]')
|
|
32
34
|
};
|
|
35
|
+
export const AI_EDITOR_SEND_TO_CHAT: Command = {
|
|
36
|
+
id: 'ai-editor.sendToChat',
|
|
37
|
+
label: nls.localize('theia/ai-editor/sendToChat', 'Send to AI Chat [Experimental]')
|
|
38
|
+
};
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
@injectable()
|
|
36
|
-
export class AiEditorCommandContribution implements CommandContribution, MenuContribution {
|
|
42
|
+
export class AiEditorCommandContribution implements CommandContribution, MenuContribution, KeybindingContribution {
|
|
37
43
|
|
|
38
44
|
@inject(MonacoCommandRegistry)
|
|
39
45
|
protected readonly monacoCommandRegistry: MonacoCommandRegistry;
|
|
@@ -45,13 +51,59 @@ export class AiEditorCommandContribution implements CommandContribution, MenuCon
|
|
|
45
51
|
|
|
46
52
|
registerCommands(registry: CommandRegistry): void {
|
|
47
53
|
registry.registerCommand(AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI);
|
|
54
|
+
registry.registerCommand(AI_EDITOR_COMMANDS.AI_EDITOR_SEND_TO_CHAT);
|
|
55
|
+
|
|
48
56
|
this.monacoCommandRegistry.registerHandler(AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.id, this.showInputWidgetHandler());
|
|
57
|
+
this.monacoCommandRegistry.registerHandler(AI_EDITOR_COMMANDS.AI_EDITOR_SEND_TO_CHAT.id, this.sendToChatHandler());
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
protected showInputWidgetHandler(): MonacoEditorCommandHandler {
|
|
52
61
|
return {
|
|
53
|
-
execute: (
|
|
54
|
-
|
|
62
|
+
execute: (editor: MonacoEditor, position?: Coordinate) => {
|
|
63
|
+
let coordinates: Coordinate;
|
|
64
|
+
|
|
65
|
+
if (position) {
|
|
66
|
+
// Called from context menu - use provided position
|
|
67
|
+
coordinates = { x: position.x, y: position.y + 10 };
|
|
68
|
+
} else {
|
|
69
|
+
// Called from keybinding - calculate position from cursor in editor
|
|
70
|
+
const cursorPosition = editor.getControl().getPosition();
|
|
71
|
+
if (cursorPosition) {
|
|
72
|
+
const editorNode = editor.getControl().getDomNode();
|
|
73
|
+
if (editorNode) {
|
|
74
|
+
const editorRect = editorNode.getBoundingClientRect();
|
|
75
|
+
const coordinatesInEditor = editor.getControl().getScrolledVisiblePosition(cursorPosition);
|
|
76
|
+
|
|
77
|
+
if (coordinatesInEditor) {
|
|
78
|
+
// Calculate screen coordinates from editor-relative coordinates
|
|
79
|
+
coordinates = {
|
|
80
|
+
x: editorRect.left + coordinatesInEditor.left,
|
|
81
|
+
y: editorRect.top + coordinatesInEditor.top + coordinatesInEditor.height + 5
|
|
82
|
+
};
|
|
83
|
+
} else {
|
|
84
|
+
// Fallback: center of editor viewport
|
|
85
|
+
coordinates = {
|
|
86
|
+
x: editorRect.left + editorRect.width / 2,
|
|
87
|
+
y: editorRect.top + editorRect.height / 2
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
// Ultimate fallback: center of screen
|
|
92
|
+
coordinates = {
|
|
93
|
+
x: window.innerWidth / 2,
|
|
94
|
+
y: window.innerHeight / 2
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
// Fallback if no cursor position available
|
|
99
|
+
coordinates = {
|
|
100
|
+
x: window.innerWidth / 2,
|
|
101
|
+
y: window.innerHeight / 2
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.showInputWidget(coordinates);
|
|
55
107
|
}
|
|
56
108
|
};
|
|
57
109
|
}
|
|
@@ -62,10 +114,7 @@ export class AiEditorCommandContribution implements CommandContribution, MenuCon
|
|
|
62
114
|
this.askAiInputWidget = new AskAIInputWidget();
|
|
63
115
|
|
|
64
116
|
this.askAiInputWidget.onSubmit(event => {
|
|
65
|
-
|
|
66
|
-
this.chatService.sendRequest(session.id, {
|
|
67
|
-
text: `${event.userInput} #editorContext`
|
|
68
|
-
});
|
|
117
|
+
this.createNewChatSession(event.userInput);
|
|
69
118
|
});
|
|
70
119
|
|
|
71
120
|
this.askAiInputWidget.show(coordinates);
|
|
@@ -82,10 +131,35 @@ export class AiEditorCommandContribution implements CommandContribution, MenuCon
|
|
|
82
131
|
}
|
|
83
132
|
}
|
|
84
133
|
|
|
134
|
+
protected sendToChatHandler(): MonacoEditorCommandHandler {
|
|
135
|
+
return {
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
execute: (_editor: MonacoEditor, ...args: any[]) => {
|
|
138
|
+
const prompt = args[0].prompt;
|
|
139
|
+
this.createNewChatSession(prompt);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private createNewChatSession(prompt: string): void {
|
|
145
|
+
const session = this.chatService.createSession(ChatAgentLocation.Panel, { focus: true });
|
|
146
|
+
this.chatService.sendRequest(session.id, {
|
|
147
|
+
text: `${prompt} #editorContext`
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
85
151
|
registerMenus(menus: MenuModelRegistry): void {
|
|
86
152
|
menus.registerMenuAction(EditorContextMenu.NAVIGATION, {
|
|
87
153
|
commandId: AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.id,
|
|
88
154
|
label: AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.label
|
|
89
155
|
});
|
|
90
156
|
}
|
|
157
|
+
|
|
158
|
+
registerKeybindings(registry: KeybindingRegistry): void {
|
|
159
|
+
registry.registerKeybinding({
|
|
160
|
+
command: AI_EDITOR_COMMANDS.AI_EDITOR_ASK_AI.id,
|
|
161
|
+
keybinding: 'ctrlcmd+i',
|
|
162
|
+
when: `${ENABLE_AI_CONTEXT_KEY} && editorFocus && !editorReadonly`
|
|
163
|
+
});
|
|
164
|
+
}
|
|
91
165
|
}
|
|
@@ -18,8 +18,10 @@ import { AIVariable, AIVariableContext, AIVariableContribution, AIVariableResolu
|
|
|
18
18
|
import { FrontendVariableService } from '@theia/ai-core/lib/browser';
|
|
19
19
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
20
|
import { codiconArray } from '@theia/core/lib/browser';
|
|
21
|
+
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
|
21
22
|
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
|
22
23
|
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
|
24
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
23
25
|
|
|
24
26
|
export const EDITOR_CONTEXT_VARIABLE: AIVariable = {
|
|
25
27
|
id: 'editorContext',
|
|
@@ -77,10 +79,8 @@ export class EditorContextVariableContribution implements AIVariableContribution
|
|
|
77
79
|
// Get workspace-relative path
|
|
78
80
|
const workspaceRelativePath = uri ? await this.workspaceService.getWorkspaceRelativePath(uri) : '';
|
|
79
81
|
|
|
80
|
-
// Create
|
|
81
|
-
const
|
|
82
|
-
Metadata provided by the user:
|
|
83
|
-
${JSON.stringify({
|
|
82
|
+
// Create base context information
|
|
83
|
+
const baseContext = {
|
|
84
84
|
file: {
|
|
85
85
|
uri: workspaceRelativePath,
|
|
86
86
|
languageId,
|
|
@@ -99,7 +99,16 @@ export class EditorContextVariableContribution implements AIVariableContribution
|
|
|
99
99
|
column,
|
|
100
100
|
lineContent: position ? model.getLineContent(position.lineNumber) : ''
|
|
101
101
|
}
|
|
102
|
-
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const diagnostics = await this.getDiagnosticContext(editor);
|
|
105
|
+
|
|
106
|
+
const fullContext = {
|
|
107
|
+
...baseContext,
|
|
108
|
+
diagnostics
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const contextValue = JSON.stringify(fullContext, undefined, 2);
|
|
103
112
|
|
|
104
113
|
return {
|
|
105
114
|
variable: request.variable,
|
|
@@ -107,4 +116,75 @@ export class EditorContextVariableContribution implements AIVariableContribution
|
|
|
107
116
|
contextValue // Full detailed context for AI processing
|
|
108
117
|
};
|
|
109
118
|
}
|
|
119
|
+
protected getDiagnosticContext(editor: MonacoEditor): Record<string, unknown> {
|
|
120
|
+
const model = editor.getControl().getModel();
|
|
121
|
+
if (!model) {
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const markers = monaco.editor.getModelMarkers({ resource: model.uri });
|
|
126
|
+
|
|
127
|
+
if (markers.length === 0) {
|
|
128
|
+
return {
|
|
129
|
+
errorCount: 0,
|
|
130
|
+
warningCount: 0,
|
|
131
|
+
infoCount: 0,
|
|
132
|
+
hintCount: 0,
|
|
133
|
+
totalIssues: 0
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const issues: Array<{
|
|
138
|
+
line: number;
|
|
139
|
+
column: number;
|
|
140
|
+
severity: string;
|
|
141
|
+
message: string;
|
|
142
|
+
source?: string;
|
|
143
|
+
}> = [];
|
|
144
|
+
|
|
145
|
+
const markerCounter = {
|
|
146
|
+
[monaco.MarkerSeverity.Error]: 0,
|
|
147
|
+
[monaco.MarkerSeverity.Warning]: 0,
|
|
148
|
+
[monaco.MarkerSeverity.Info]: 0,
|
|
149
|
+
[monaco.MarkerSeverity.Hint]: 0
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
markers.forEach(marker => {
|
|
153
|
+
markerCounter[marker.severity]++;
|
|
154
|
+
|
|
155
|
+
issues.push({
|
|
156
|
+
line: marker.startLineNumber,
|
|
157
|
+
column: marker.startColumn,
|
|
158
|
+
severity: this.severityToString(marker.severity),
|
|
159
|
+
message: marker.message,
|
|
160
|
+
source: marker.source
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
diagnosticCounts: {
|
|
166
|
+
errorCount: markerCounter[monaco.MarkerSeverity.Error],
|
|
167
|
+
warningCount: markerCounter[monaco.MarkerSeverity.Warning],
|
|
168
|
+
infoCount: markerCounter[monaco.MarkerSeverity.Info],
|
|
169
|
+
hintCount: markerCounter[monaco.MarkerSeverity.Hint]
|
|
170
|
+
},
|
|
171
|
+
totalIssues: markers.length,
|
|
172
|
+
issues
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected severityToString(severity: monaco.MarkerSeverity): string {
|
|
177
|
+
switch (severity) {
|
|
178
|
+
case monaco.MarkerSeverity.Error:
|
|
179
|
+
return 'error';
|
|
180
|
+
case monaco.MarkerSeverity.Warning:
|
|
181
|
+
return 'warning';
|
|
182
|
+
case monaco.MarkerSeverity.Info:
|
|
183
|
+
return 'info';
|
|
184
|
+
case monaco.MarkerSeverity.Hint:
|
|
185
|
+
return 'hint';
|
|
186
|
+
default:
|
|
187
|
+
return 'unknown';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
110
190
|
}
|
|
@@ -14,18 +14,24 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { AIVariableContribution } from '@theia/ai-core';
|
|
18
|
+
import { FrontendApplicationContribution, KeybindingContribution } from '@theia/core/lib/browser';
|
|
18
19
|
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
|
|
19
|
-
import {
|
|
20
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
20
21
|
import '../../style/ask-ai-input.css';
|
|
22
|
+
import { AICodeActionProvider } from './ai-code-action-provider';
|
|
23
|
+
import { AiEditorCommandContribution } from './ai-editor-command-contribution';
|
|
21
24
|
import { EditorContextVariableContribution } from './ai-editor-context-variable';
|
|
22
|
-
import { AIVariableContribution } from '@theia/ai-core';
|
|
23
25
|
|
|
24
26
|
export default new ContainerModule(bind => {
|
|
25
27
|
bind(AiEditorCommandContribution).toSelf().inSingletonScope();
|
|
26
28
|
|
|
27
29
|
bind(CommandContribution).toService(AiEditorCommandContribution);
|
|
28
30
|
bind(MenuContribution).toService(AiEditorCommandContribution);
|
|
31
|
+
bind(KeybindingContribution).toService(AiEditorCommandContribution);
|
|
29
32
|
|
|
30
33
|
bind(AIVariableContribution).to(EditorContextVariableContribution).inSingletonScope();
|
|
34
|
+
|
|
35
|
+
bind(AICodeActionProvider).toSelf().inSingletonScope();
|
|
36
|
+
bind(FrontendApplicationContribution).toService(AICodeActionProvider);
|
|
31
37
|
});
|