Skip to content

Commit 2fac2d4

Browse files
authored
Reduce some 'in' (#276321)
* Fix no-in * Reduce some 'in'
1 parent a18659d commit 2fac2d4

File tree

9 files changed

+32
-22
lines changed

9 files changed

+32
-22
lines changed

eslint.config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ export default tseslint.config(
266266
'src/vs/workbench/browser/workbench.ts',
267267
'src/vs/workbench/common/notifications.ts',
268268
'src/vs/workbench/contrib/accessibility/browser/accessibleView.ts',
269-
'src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.ts',
270-
'src/vs/workbench/contrib/chat/browser/chat.ts',
271269
'src/vs/workbench/contrib/chat/browser/chatAttachmentResolveService.ts',
272270
'src/vs/workbench/contrib/chat/browser/chatContentParts/chatAttachmentsContentPart.ts',
273271
'src/vs/workbench/contrib/chat/browser/chatContentParts/chatConfirmationWidget.ts',
@@ -277,16 +275,11 @@ export default tseslint.config(
277275
'src/vs/workbench/contrib/chat/browser/chatContentParts/toolInvocationParts/abstractToolConfirmationSubPart.ts',
278276
'src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.ts',
279277
'src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSessionStorage.ts',
280-
'src/vs/workbench/contrib/chat/browser/chatEditorInput.ts',
281-
'src/vs/workbench/contrib/chat/browser/chatFollowups.ts',
282278
'src/vs/workbench/contrib/chat/browser/chatInlineAnchorWidget.ts',
283-
'src/vs/workbench/contrib/chat/browser/chatInputPart.ts',
284-
'src/vs/workbench/contrib/chat/browser/chatListRenderer.ts',
285279
'src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.ts',
286280
'src/vs/workbench/contrib/chat/browser/chatSessions/common.ts',
287281
'src/vs/workbench/contrib/chat/browser/chatSessions/localChatSessionsProvider.ts',
288282
'src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsTreeRenderer.ts',
289-
'src/vs/workbench/contrib/chat/browser/chatWidget.ts',
290283
'src/vs/workbench/contrib/chat/browser/contrib/chatInputCompletions.ts',
291284
'src/vs/workbench/contrib/chat/common/annotations.ts',
292285
'src/vs/workbench/contrib/chat/common/chat.ts',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { getEditingSessionContext } from '../chatEditing/chatEditingActions.js';
4545
import { ACTION_ID_NEW_CHAT, CHAT_CATEGORY, handleCurrentEditingSession, handleModeSwitch } from './chatActions.js';
4646
import { ctxHasEditorModification } from '../chatEditing/chatEditingEditorContextKeys.js';
4747
import { chatSessionResourceToId } from '../../common/chatUri.js';
48+
import { isITextModel } from '../../../../../editor/common/model.js';
4849

4950
export interface IVoiceChatExecuteActionContext {
5051
readonly disableTimeout?: boolean;
@@ -822,7 +823,7 @@ export class CreateRemoteAgentJobAction extends Action2 {
822823
if (activeEditor) {
823824
const model = activeEditor.getModel();
824825
let activeEditorUri: URI | undefined = undefined;
825-
if (model && 'uri' in model) {
826+
if (model && isITextModel(model)) {
826827
activeEditorUri = model.uri as URI;
827828
}
828829
const selection = activeEditor.getSelection();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface IChatWidgetService {
5656
}
5757

5858
export async function showChatWidgetInViewOrEditor(accessor: ServicesAccessor, widget: IChatWidget) {
59-
if ('viewId' in widget.viewContext) {
59+
if (isIChatViewViewContext(widget.viewContext)) {
6060
await accessor.get(IViewsService).openView(widget.viewContext.viewId);
6161
} else {
6262
const sessionResource = widget.viewModel?.sessionResource;
@@ -185,11 +185,19 @@ export interface IChatViewViewContext {
185185
viewId: string;
186186
}
187187

188+
export function isIChatViewViewContext(context: IChatWidgetViewContext): context is IChatViewViewContext {
189+
return typeof (context as IChatViewViewContext).viewId === 'string';
190+
}
191+
188192
export interface IChatResourceViewContext {
189193
isQuickChat?: boolean;
190194
isInlineChat?: boolean;
191195
}
192196

197+
export function isIChatResourceViewContext(context: IChatWidgetViewContext): context is IChatResourceViewContext {
198+
return !isIChatViewViewContext(context);
199+
}
200+
193201
export type IChatWidgetViewContext = IChatViewViewContext | IChatResourceViewContext | {};
194202

195203
export interface IChatAcceptInputOptions {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler
271271
?? this.chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None, undefined, { canUseTools: false });
272272
} else if (!this.options.target) {
273273
this.model = this.chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None, undefined, { canUseTools: !inputType });
274-
} else if ('data' in this.options.target) {
274+
} else if (this.options.target.data) {
275275
this.model = this.chatService.loadSessionFromContent(this.options.target.data);
276276
}
277277

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ChatFollowups<T extends IChatFollowup> extends Disposable {
4747
: followup.title;
4848
const message = followup.kind === 'reply' ? followup.message : followup.title;
4949
const tooltip = (tooltipPrefix +
50-
('tooltip' in followup && followup.tooltip || message)).trim();
50+
(followup.tooltip || message)).trim();
5151
const button = this._register(new Button(container, { ...this.options, title: tooltip }));
5252
if (followup.kind === 'reply') {
5353
button.element.classList.add('interactive-followup-reply');

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { CodeEditorWidget } from '../../../../editor/browser/widget/codeEditor/c
3737
import { EditorOptions, IEditorOptions } from '../../../../editor/common/config/editorOptions.js';
3838
import { IDimension } from '../../../../editor/common/core/2d/dimension.js';
3939
import { IPosition } from '../../../../editor/common/core/position.js';
40-
import { Range } from '../../../../editor/common/core/range.js';
4140
import { isLocation } from '../../../../editor/common/languages.js';
4241
import { ITextModel } from '../../../../editor/common/model.js';
4342
import { IModelService } from '../../../../editor/common/services/model.js';
@@ -1616,8 +1615,8 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
16161615
this.promptFileAttached.set(this.hasPromptFileAttachments);
16171616

16181617
for (const [index, attachment] of attachments) {
1619-
const resource = URI.isUri(attachment.value) ? attachment.value : attachment.value && typeof attachment.value === 'object' && 'uri' in attachment.value && URI.isUri(attachment.value.uri) ? attachment.value.uri : undefined;
1620-
const range = attachment.value && typeof attachment.value === 'object' && 'range' in attachment.value && Range.isIRange(attachment.value.range) ? attachment.value.range : undefined;
1618+
const resource = URI.isUri(attachment.value) ? attachment.value : isLocation(attachment.value) ? attachment.value.uri : undefined;
1619+
const range = isLocation(attachment.value) ? attachment.value.range : undefined;
16211620
const shouldFocusClearButton = index === Math.min(this._indexOfLastAttachedContextDeletedWithKeyboard, this.attachmentModel.size - 1) && this._indexOfLastAttachedContextDeletedWithKeyboard > -1;
16221621

16231622
let attachmentWidget;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { IChatAgentMetadata } from '../common/chatAgents.js';
5353
import { ChatContextKeys } from '../common/chatContextKeys.js';
5454
import { IChatTextEditGroup } from '../common/chatModel.js';
5555
import { chatSubcommandLeader } from '../common/chatParserTypes.js';
56-
import { ChatAgentVoteDirection, ChatAgentVoteDownReason, ChatErrorLevel, IChatChangesSummary, IChatConfirmation, IChatContentReference, IChatElicitationRequest, IChatExtensionsContent, IChatFollowup, IChatMarkdownContent, IChatMcpServersStarting, IChatMultiDiffData, IChatPullRequestContent, IChatTask, IChatTaskSerialized, IChatThinkingPart, IChatToolInvocation, IChatToolInvocationSerialized, IChatTreeData, IChatUndoStop } from '../common/chatService.js';
56+
import { ChatAgentVoteDirection, ChatAgentVoteDownReason, ChatErrorLevel, IChatChangesSummary, IChatConfirmation, IChatContentReference, IChatElicitationRequest, IChatExtensionsContent, IChatFollowup, IChatMarkdownContent, IChatMcpServersStarting, IChatMultiDiffData, IChatPullRequestContent, IChatTask, IChatTaskSerialized, IChatThinkingPart, IChatToolInvocation, IChatToolInvocationSerialized, IChatTreeData, IChatUndoStop, isChatFollowup } from '../common/chatService.js';
5757
import { IChatRequestVariableEntry } from '../common/chatVariableEntries.js';
5858
import { IChatChangesSummaryPart, IChatCodeCitations, IChatErrorDetailsPart, IChatReferences, IChatRendererContent, IChatRequestViewModel, IChatResponseViewModel, IChatViewModel, isRequestVM, isResponseVM } from '../common/chatViewModel.js';
5959
import { getNWords } from '../common/chatWordCounter.js';
@@ -835,7 +835,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
835835

836836
let content: IChatRendererContent[] = [];
837837
if (!element.confirmation) {
838-
const markdown = 'message' in element.message ?
838+
const markdown = isChatFollowup(element.message) ?
839839
element.message.message :
840840
this.markdownDecorationsRenderer.convertParsedRequestToMarkdown(element.message);
841841
content = [{ content: new MarkdownString(markdown), kind: 'markdownContent' }];
@@ -1729,7 +1729,7 @@ export class ChatListDelegate implements IListVirtualDelegate<ChatTreeItem> {
17291729

17301730
getHeight(element: ChatTreeItem): number {
17311731
const kind = isRequestVM(element) ? 'request' : 'response';
1732-
const height = ('currentRenderedHeight' in element ? element.currentRenderedHeight : undefined) ?? this.defaultElementHeight;
1732+
const height = element.currentRenderedHeight ?? this.defaultElementHeight;
17331733
this._traceLayout('getHeight', `${kind}, height=${height}`);
17341734
return height;
17351735
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import { PromptsType } from '../common/promptSyntax/promptTypes.js';
8484
import { IHandOff, ParsedPromptFile, PromptHeader, Target } from '../common/promptSyntax/promptFileParser.js';
8585
import { IPromptsService } from '../common/promptSyntax/service/promptsService.js';
8686
import { handleModeSwitch } from './actions/chatActions.js';
87-
import { ChatTreeItem, ChatViewId, IChatAcceptInputOptions, IChatAccessibilityService, IChatCodeBlockInfo, IChatFileTreeInfo, IChatListItemRendererOptions, IChatWidget, IChatWidgetService, IChatWidgetViewContext, IChatWidgetViewOptions } from './chat.js';
87+
import { ChatTreeItem, ChatViewId, IChatAcceptInputOptions, IChatAccessibilityService, IChatCodeBlockInfo, IChatFileTreeInfo, IChatListItemRendererOptions, IChatWidget, IChatWidgetService, IChatWidgetViewContext, IChatWidgetViewOptions, isIChatResourceViewContext, isIChatViewViewContext } from './chat.js';
8888
import { ChatAccessibilityProvider } from './chatAccessibilityProvider.js';
8989
import { ChatAttachmentModel } from './chatAttachmentModel.js';
9090
import { ChatSuggestNextWidget } from './chatContentParts/chatSuggestNextWidget.js';
@@ -140,11 +140,11 @@ export interface IChatWidgetLocationOptions {
140140
}
141141

142142
export function isQuickChat(widget: IChatWidget): boolean {
143-
return 'viewContext' in widget && 'isQuickChat' in widget.viewContext && Boolean(widget.viewContext.isQuickChat);
143+
return isIChatResourceViewContext(widget.viewContext) && Boolean(widget.viewContext.isQuickChat);
144144
}
145145

146146
export function isInlineChat(widget: IChatWidget): boolean {
147-
return 'viewContext' in widget && 'isInlineChat' in widget.viewContext && Boolean(widget.viewContext.isInlineChat);
147+
return isIChatResourceViewContext(widget.viewContext) && Boolean(widget.viewContext.isInlineChat);
148148
}
149149

150150
interface IChatHistoryListItem {
@@ -790,7 +790,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
790790
}
791791

792792
render(parent: HTMLElement): void {
793-
const viewId = 'viewId' in this.viewContext ? this.viewContext.viewId : undefined;
793+
const viewId = isIChatViewViewContext(this.viewContext) ? this.viewContext.viewId : undefined;
794794
this.editorOptions = this._register(this.instantiationService.createInstance(ChatEditorOptions, viewId, this.styles.listForeground, this.styles.inputEditorBackground, this.styles.resultEditorBackground));
795795
const renderInputOnTop = this.viewOptions.renderInputOnTop ?? false;
796796
const renderFollowups = this.viewOptions.renderFollowups ?? !renderInputOnTop;
@@ -2061,7 +2061,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
20612061
private getWidgetViewKindTag(): string {
20622062
if (!this.viewContext) {
20632063
return 'editor';
2064-
} else if ('viewId' in this.viewContext) {
2064+
} else if (isIChatViewViewContext(this.viewContext)) {
20652065
return 'view';
20662066
} else {
20672067
return 'quick';

src/vs/workbench/contrib/chat/common/chatService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,15 @@ export interface IChatFollowup {
672672
tooltip?: string;
673673
}
674674

675+
export function isChatFollowup(obj: unknown): obj is IChatFollowup {
676+
return (
677+
!!obj &&
678+
(obj as IChatFollowup).kind === 'reply' &&
679+
typeof (obj as IChatFollowup).message === 'string' &&
680+
typeof (obj as IChatFollowup).agentId === 'string'
681+
);
682+
}
683+
675684
export enum ChatAgentVoteDirection {
676685
Down = 0,
677686
Up = 1

0 commit comments

Comments
 (0)