Skip to content

Commit ead2adc

Browse files
authored
fix: enable Attach Selection to Chat for untitled files (microsoft#223413)
1 parent ea0d703 commit ead2adc

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatContextActions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import { CancellationToken } from 'vs/base/common/cancellation';
77
import { Codicon } from 'vs/base/common/codicons';
88
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
99
import { Schemas } from 'vs/base/common/network';
10-
import { IRange } from 'vs/editor/common/core/range';
10+
import { compare } from 'vs/base/common/strings';
1111
import { ThemeIcon } from 'vs/base/common/themables';
1212
import { URI } from 'vs/base/common/uri';
1313
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
14+
import { IRange } from 'vs/editor/common/core/range';
15+
import { EditorType } from 'vs/editor/common/editorCommon';
1416
import { Command } from 'vs/editor/common/languages';
1517
import { AbstractGotoSymbolQuickAccessProvider, IGotoSymbolQuickPickItem } from 'vs/editor/contrib/quickAccess/browser/gotoSymbolQuickAccess';
1618
import { localize, localize2 } from 'vs/nls';
1719
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
1820
import { ICommandService } from 'vs/platform/commands/common/commands';
21+
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1922
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
2023
import { AnythingQuickAccessProviderRunOptions } from 'vs/platform/quickinput/common/quickAccess';
2124
import { IQuickInputService, IQuickPickItem, QuickPickItem } from 'vs/platform/quickinput/common/quickInput';
@@ -27,13 +30,10 @@ import { CONTEXT_CHAT_LOCATION, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_QUICK_CHAT } f
2730
import { IChatRequestVariableEntry } from 'vs/workbench/contrib/chat/common/chatModel';
2831
import { ChatRequestAgentPart } from 'vs/workbench/contrib/chat/common/chatParserTypes';
2932
import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables';
33+
import { ILanguageModelToolsService } from 'vs/workbench/contrib/chat/common/languageModelToolsService';
3034
import { AnythingQuickAccessProvider } from 'vs/workbench/contrib/search/browser/anythingQuickAccess';
3135
import { ISymbolQuickPickItem, SymbolsQuickAccessProvider } from 'vs/workbench/contrib/search/browser/symbolsQuickAccess';
32-
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
3336
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
34-
import { EditorType } from 'vs/editor/common/editorCommon';
35-
import { compare } from 'vs/base/common/strings';
36-
import { ILanguageModelToolsService } from 'vs/workbench/contrib/chat/common/languageModelToolsService';
3737

3838
export function registerChatContextActions() {
3939
registerAction2(AttachContextAction);
@@ -107,7 +107,7 @@ class AttachFileAction extends Action2 {
107107
const textEditorService = accessor.get(IEditorService);
108108

109109
const activeUri = textEditorService.activeEditor?.resource;
110-
if (textEditorService.activeTextEditorControl?.getEditorType() === EditorType.ICodeEditor && activeUri && [Schemas.file, Schemas.vscodeRemote].includes(activeUri.scheme)) {
110+
if (textEditorService.activeTextEditorControl?.getEditorType() === EditorType.ICodeEditor && activeUri && [Schemas.file, Schemas.vscodeRemote, Schemas.untitled].includes(activeUri.scheme)) {
111111
variablesService.attachContext('file', activeUri, ChatAgentLocation.Panel);
112112
}
113113
}
@@ -132,7 +132,7 @@ class AttachSelectionAction extends Action2 {
132132

133133
const activeEditor = textEditorService.activeTextEditorControl;
134134
const activeUri = textEditorService.activeEditor?.resource;
135-
if (textEditorService.activeTextEditorControl?.getEditorType() === EditorType.ICodeEditor && activeUri && [Schemas.file, Schemas.vscodeRemote].includes(activeUri.scheme)) {
135+
if (textEditorService.activeTextEditorControl?.getEditorType() === EditorType.ICodeEditor && activeUri && [Schemas.file, Schemas.vscodeRemote, Schemas.untitled].includes(activeUri.scheme)) {
136136
const selection = activeEditor?.getSelection();
137137
if (selection) {
138138
variablesService.attachContext('file', { uri: activeUri, range: selection }, ChatAgentLocation.Panel);

src/vs/workbench/contrib/chat/browser/chatVariables.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ export class ChatVariablesService implements IChatVariablesService {
164164
return;
165165
}
166166

167-
await showChatView(this.viewsService);
168-
const widget = this.chatWidgetService.lastFocusedWidget;
167+
const widget = await showChatView(this.viewsService);
169168
if (!widget || !widget.viewModel) {
170169
return;
171170
}

0 commit comments

Comments
 (0)