Skip to content

Commit 19890b8

Browse files
authored
Merge pull request #2855 from github/charisk/tidy-castings
Don't use 'as any' when checking open view
2 parents df1c12f + bd67afe commit 19890b8

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { CancellationTokenSource, Uri, ViewColumn, window } from "vscode";
1+
import {
2+
CancellationTokenSource,
3+
Tab,
4+
TabInputWebview,
5+
Uri,
6+
ViewColumn,
7+
window,
8+
} from "vscode";
29
import {
310
AbstractWebview,
411
WebviewPanelConfig,
@@ -150,26 +157,28 @@ export class ModelEditorView extends AbstractWebview<
150157

151158
private isAModelEditorOpen(): boolean {
152159
return window.tabGroups.all.some((tabGroup) =>
153-
tabGroup.tabs.some((tab) => {
154-
const viewType: string | undefined = (tab.input as any)?.viewType;
155-
// The viewType has a prefix, such as "mainThreadWebview-", but if the
156-
// suffix matches that should be enough to identify the view.
157-
return viewType && viewType.endsWith("model-editor");
158-
}),
160+
tabGroup.tabs.some((tab) => this.isTabModelEditorView(tab)),
159161
);
160162
}
161163

162164
private isAModelEditorActive(): boolean {
163165
return window.tabGroups.all.some((tabGroup) =>
164-
tabGroup.tabs.some((tab) => {
165-
const viewType: string | undefined = (tab.input as any)?.viewType;
166-
// The viewType has a prefix, such as "mainThreadWebview-", but if the
167-
// suffix matches that should be enough to identify the view.
168-
return viewType && viewType.endsWith("model-editor") && tab.isActive;
169-
}),
166+
tabGroup.tabs.some(
167+
(tab) => this.isTabModelEditorView(tab) && tab.isActive,
168+
),
170169
);
171170
}
172171

172+
private isTabModelEditorView(tab: Tab): boolean {
173+
if (!(tab.input instanceof TabInputWebview)) {
174+
return false;
175+
}
176+
177+
// The viewType has a prefix, such as "mainThreadWebview-", but if the
178+
// suffix matches that should be enough to identify the view.
179+
return tab.input.viewType.endsWith("model-editor");
180+
}
181+
173182
protected async getPanelConfig(): Promise<WebviewPanelConfig> {
174183
return {
175184
viewId: "model-editor",

0 commit comments

Comments
 (0)