Skip to content

Commit 1c62250

Browse files
authored
Merge pull request microsoft#187478 from microsoft/aiday/positionInlineChatFromExtension
Allowing extension to specify the position where inline chat should appear
2 parents ba4564b + 8e1b095 commit 1c62250

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/vs/workbench/api/common/extHostInlineChat.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
1717
import type * as vscode from 'vscode';
1818
import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
1919
import { IRange } from 'vs/editor/common/core/range';
20+
import { IPosition } from 'vs/editor/common/core/position';
2021

2122
class ProviderWrapper {
2223

@@ -59,12 +60,14 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
5960
initialRange?: vscode.Range;
6061
message?: string;
6162
autoSend?: boolean;
63+
position?: vscode.Position;
6264
};
6365

6466
type InteractiveEditorRunOptions = {
6567
initialRange?: IRange;
6668
message?: string;
6769
autoSend?: boolean;
70+
position?: IPosition;
6871
};
6972

7073
extHostCommands.registerApiCommand(new ApiCommand(
@@ -78,7 +81,8 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
7881
return {
7982
initialRange: v.initialRange ? typeConvert.Range.from(v.initialRange) : undefined,
8083
message: v.message,
81-
autoSend: v.autoSend
84+
autoSend: v.autoSend,
85+
position: v.position ? typeConvert.Position.from(v.position) : undefined,
8286
};
8387
})],
8488
ApiCommandResult.Void

src/vs/workbench/contrib/inlineChat/browser/inlineChatActions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from 'vs/platform/accessibility/co
2929
import { AccessibilityHelpAction } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
3030
import { Disposable } from 'vs/base/common/lifecycle';
3131
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
32+
import { Position } from 'vs/editor/common/core/position';
3233

3334
CommandsRegistry.registerCommandAlias('interactiveEditor.start', 'inlineChat.start');
3435

@@ -50,11 +51,12 @@ export class StartSessionAction extends EditorAction2 {
5051
}
5152

5253
private _isInteractivEditorOptions(options: any): options is InlineChatRunOptions {
53-
const { initialRange, message, autoSend } = options;
54+
const { initialRange, message, autoSend, position } = options;
5455
if (
5556
typeof message !== 'undefined' && typeof message !== 'string'
5657
|| typeof autoSend !== 'undefined' && typeof autoSend !== 'boolean'
57-
|| typeof initialRange !== 'undefined' && !Range.isIRange(initialRange)) {
58+
|| typeof initialRange !== 'undefined' && !Range.isIRange(initialRange)
59+
|| typeof position !== 'undefined' && !Position.isIPosition(position)) {
5860
return false;
5961
}
6062
return true;

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { StopWatch } from 'vs/base/common/stopwatch';
1414
import { assertType } from 'vs/base/common/types';
1515
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1616
import { EditOperation } from 'vs/editor/common/core/editOperation';
17-
import { Position } from 'vs/editor/common/core/position';
17+
import { IPosition, Position } from 'vs/editor/common/core/position';
1818
import { IRange, Range } from 'vs/editor/common/core/range';
1919
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
2020
import { ModelDecorationOptions, createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel';
@@ -66,6 +66,7 @@ export interface InlineChatRunOptions {
6666
autoSend?: boolean;
6767
existingSession?: Session;
6868
isUnstashed?: boolean;
69+
position?: IPosition;
6970
}
7071

7172
export class InlineChatController implements IEditorContribution {
@@ -184,12 +185,12 @@ export class InlineChatController implements IEditorContribution {
184185

185186
// ---- state machine
186187

187-
private _showWidget(initialRender: boolean = false) {
188+
private _showWidget(initialRender: boolean = false, position?: IPosition) {
188189
assertType(this._editor.hasModel());
189190

190191
let widgetPosition: Position;
191192
if (initialRender) {
192-
widgetPosition = this._editor.getSelection().getEndPosition();
193+
widgetPosition = position ? Position.lift(position) : this._editor.getSelection().getEndPosition();
193194
this._zone.value.setContainerMargins();
194195
this._zone.value.setWidgetMargins(widgetPosition);
195196
} else {
@@ -219,7 +220,7 @@ export class InlineChatController implements IEditorContribution {
219220

220221
let session: Session | undefined = options.existingSession;
221222

222-
this._showWidget(true);
223+
this._showWidget(true, options.position);
223224
this._zone.value.widget.updateInfo(localize('welcome.1', "AI-generated code may be incorrect"));
224225
this._zone.value.widget.placeholder = this._getPlaceholderText();
225226

@@ -307,7 +308,7 @@ export class InlineChatController implements IEditorContribution {
307308
}
308309
});
309310

310-
this._showWidget(true);
311+
this._showWidget(true, options.position);
311312

312313
this._sessionStore.add(this._editor.onDidChangeModel((e) => {
313314
const msg = this._activeSession?.lastExchange

0 commit comments

Comments
 (0)