Skip to content

Commit 376fca8

Browse files
committed
Don't import 'vscode' in webview code
microsoft#70807
1 parent 0768663 commit 376fca8

5 files changed

Lines changed: 30 additions & 23 deletions

File tree

src/vs/editor/common/modes.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,24 @@ export interface WorkspaceCommentProvider {
13961396
onDidChangeCommentThreads(): Event<CommentThreadChangedEvent>;
13971397
}
13981398

1399+
/**
1400+
* @internal
1401+
*/
1402+
export interface IWebviewOptions {
1403+
readonly enableScripts?: boolean;
1404+
readonly enableCommandUris?: boolean;
1405+
readonly localResourceRoots?: ReadonlyArray<URI>;
1406+
readonly portMapping?: ReadonlyArray<{ port: number, resolvedPort: number }>;
1407+
}
1408+
1409+
/**
1410+
* @internal
1411+
*/
1412+
export interface IWebviewPanelOptions {
1413+
readonly enableFindWidget?: boolean;
1414+
readonly retainContextWhenHidden?: boolean;
1415+
}
1416+
13991417
export interface ICodeLensSymbol {
14001418
range: IRange;
14011419
id?: string;

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -504,27 +504,16 @@ export interface WebviewPanelShowOptions {
504504
readonly preserveFocus?: boolean;
505505
}
506506

507-
export interface IWebviewPanelOptions {
508-
readonly enableFindWidget?: boolean;
509-
readonly retainContextWhenHidden?: boolean;
510-
}
511-
512-
export interface IWebviewOptions {
513-
readonly enableScripts?: boolean;
514-
readonly enableCommandUris?: boolean;
515-
readonly localResourceRoots?: ReadonlyArray<UriComponents>;
516-
}
517-
518507
export interface MainThreadWebviewsShape extends IDisposable {
519-
$createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, showOptions: WebviewPanelShowOptions, options: IWebviewPanelOptions & IWebviewOptions, extensionId: ExtensionIdentifier, extensionLocation: UriComponents): void;
520-
$createWebviewCodeInset(handle: WebviewInsetHandle, symbolId: string, options: IWebviewOptions, extensionLocation: UriComponents | undefined): void;
508+
$createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, showOptions: WebviewPanelShowOptions, options: modes.IWebviewPanelOptions & modes.IWebviewOptions, extensionId: ExtensionIdentifier, extensionLocation: UriComponents): void;
509+
$createWebviewCodeInset(handle: WebviewInsetHandle, symbolId: string, options: modes.IWebviewOptions, extensionLocation: UriComponents | undefined): void;
521510
$disposeWebview(handle: WebviewPanelHandle): void;
522511
$reveal(handle: WebviewPanelHandle, showOptions: WebviewPanelShowOptions): void;
523512
$setTitle(handle: WebviewPanelHandle, value: string): void;
524513
$setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents } | undefined): void;
525514

526515
$setHtml(handle: WebviewPanelHandle | WebviewInsetHandle, value: string): void;
527-
$setOptions(handle: WebviewPanelHandle | WebviewInsetHandle, options: IWebviewOptions): void;
516+
$setOptions(handle: WebviewPanelHandle | WebviewInsetHandle, options: modes.IWebviewOptions): void;
528517
$postMessage(handle: WebviewPanelHandle | WebviewInsetHandle, value: any): Promise<boolean>;
529518

530519
$registerSerializer(viewType: string): void;
@@ -541,7 +530,7 @@ export interface ExtHostWebviewsShape {
541530
$onMessage(handle: WebviewPanelHandle, message: any): void;
542531
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, newState: WebviewPanelViewState): void;
543532
$onDidDisposeWebviewPanel(handle: WebviewPanelHandle): Promise<void>;
544-
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorViewColumn, options: IWebviewOptions): Promise<void>;
533+
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorViewColumn, options: modes.IWebviewOptions): Promise<void>;
545534
}
546535

547536
export interface MainThreadUrlsShape extends IDisposable {

src/vs/workbench/api/electron-browser/mainThreadWebview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1313
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
1414
import { IOpenerService } from 'vs/platform/opener/common/opener';
1515
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
16-
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewInsetHandle, WebviewPanelHandle, WebviewPanelShowOptions, IWebviewOptions } from 'vs/workbench/api/common/extHost.protocol';
16+
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewInsetHandle, WebviewPanelHandle, WebviewPanelShowOptions } from 'vs/workbench/api/common/extHost.protocol';
1717
import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/common/shared/editor';
1818
import { CodeInsetController } from 'vs/workbench/contrib/codeinset/electron-browser/codeInset.contribution';
1919
import { WebviewEditor } from 'vs/workbench/contrib/webview/electron-browser/webviewEditor';
@@ -25,6 +25,7 @@ import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/commo
2525
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2626
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
2727
import { extHostNamedCustomer } from '../common/extHostCustomers';
28+
import { IWebviewOptions } from 'vs/editor/common/modes';
2829

2930
@extHostNamedCustomer(MainContext.MainThreadWebviews)
3031
export class MainThreadWebviews extends Disposable implements MainThreadWebviewsShape {

src/vs/workbench/contrib/webview/electron-browser/webviewEditorInput.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import { URI } from 'vs/base/common/uri';
99
import { IEditorModel } from 'vs/platform/editor/common/editor';
1010
import { EditorInput, EditorModel, GroupIdentifier, IEditorInput } from 'vs/workbench/common/editor';
1111
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
12-
import * as vscode from 'vscode';
1312
import { WebviewEvents, WebviewInputOptions } from './webviewEditorService';
14-
import { WebviewElement } from './webviewElement';
13+
import { WebviewElement, WebviewOptions } from './webviewElement';
1514

1615
export class WebviewEditorInput extends EditorInput {
1716
private static handlePool = 0;
@@ -195,7 +194,7 @@ export class WebviewEditorInput extends EditorInput {
195194
return this._options;
196195
}
197196

198-
public setOptions(value: vscode.WebviewOptions) {
197+
public setOptions(value: WebviewOptions) {
199198
this._options = {
200199
...this._options,
201200
...value

src/vs/workbench/contrib/webview/electron-browser/webviewEditorService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { createDecorator, IInstantiationService } from 'vs/platform/instantiatio
1111
import { GroupIdentifier } from 'vs/workbench/common/editor';
1212
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1313
import { ACTIVE_GROUP_TYPE, IEditorService, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService';
14-
import * as vscode from 'vscode';
1514
import { RevivedWebviewEditorInput, WebviewEditorInput } from './webviewEditorInput';
15+
import { IWebviewOptions, IWebviewPanelOptions } from 'vs/editor/common/modes';
1616

1717
export const IWebviewEditorService = createDecorator<IWebviewEditorService>('webviewEditorService');
1818

@@ -72,10 +72,10 @@ export interface WebviewReviver {
7272
export interface WebviewEvents {
7373
onMessage?(message: any): void;
7474
onDispose?(): void;
75-
onDidClickLink?(link: URI, options: vscode.WebviewOptions): void;
75+
onDidClickLink?(link: URI, options: IWebviewOptions): void;
7676
}
7777

78-
export interface WebviewInputOptions extends vscode.WebviewOptions, vscode.WebviewPanelOptions {
78+
export interface WebviewInputOptions extends IWebviewOptions, IWebviewPanelOptions {
7979
tryRestoreScrollPosition?: boolean;
8080
}
8181

@@ -129,7 +129,7 @@ export class WebviewEditorService implements IWebviewEditorService {
129129
viewType: string,
130130
title: string,
131131
showOptions: ICreateWebViewShowOptions,
132-
options: vscode.WebviewOptions,
132+
options: IWebviewOptions,
133133
extensionLocation: URI | undefined,
134134
events: WebviewEvents
135135
): WebviewEditorInput {

0 commit comments

Comments
 (0)