提交 298a5d07 编写于 作者: R rebornix

Move typings to common.

上级 7d12ce55
......@@ -8,7 +8,7 @@ import * as path from 'path';
declare var TextEncoder: any;
const mjAPI = require("mathjax-node-svg2png");
const mjAPI = require("mathjax-node");
mjAPI.config({
MathJax: {
// traditional MathJax configuration
......
......@@ -1518,106 +1518,6 @@ export interface IWebviewPanelOptions {
readonly retainContextWhenHidden?: boolean;
}
/**
* @internal
*/
export interface INotebookSelectors {
readonly filenamePattern?: string;
}
/**
* @internal
*/
export interface IStreamOutput {
output_type: 'stream';
text: string;
}
/**
* @internal
*/
export interface IErrorOutput {
output_type: 'error';
/**
* Exception Name
*/
ename?: string;
/**
* Exception Value
*/
evalue?: string;
/**
* Exception call stacks
*/
traceback?: string[];
}
/**
* @internal
*/
export interface IDisplayOutput {
output_type: 'display_data';
/**
* { mime_type: value }
*/
data: { string: string };
}
/**
* @internal
*/
export interface IGenericOutput {
output_type: string;
}
/**
* @internal
*/
export type IOutput = IStreamOutput | any;
/**
* @internal
*/
export interface ICell {
handle: number;
source: string[];
language: string;
cell_type: 'markdown' | 'code';
outputs: IOutput[];
onDidChangeOutputs?: Event<void>;
isDirty: boolean;
}
/**
* @internal
*/
export interface LanguageInfo {
file_extension: string;
}
/**
* @internal
*/
export interface IMetadata {
language_info: LanguageInfo;
}
/**
* @internal
*/
export interface INotebook {
handle: number;
// metadata: IMetadata;
readonly uri: URI;
languages: string[];
cells: ICell[];
onDidChangeCells?: Event<void>;
onDidChangeDirtyState: Event<boolean>;
onWillDispose(listener: () => void): IDisposable;
save(): Promise<boolean>;
}
export interface CodeLens {
range: IRange;
id?: string;
......
......@@ -1431,7 +1431,7 @@ declare module 'vscode' {
* @returns HTML fragment. We can probably return `CellOutput` instead of string ?
*/
render(document: NotebookDocument, cell: NotebookCell, output: CellOutput): string;
dependencies?: Uri[];
preloads?: Uri[];
}
namespace window {
......
......@@ -8,9 +8,9 @@ import { MainContext, MainThreadNotebookShape, NotebookExtensionDescription, IEx
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
import { INotebookService, IMainNotebookController } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { INotebook, ICell, IOutput } from 'vs/editor/common/modes';
import { Emitter, Event } from 'vs/base/common/event';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { ICell, IOutput, INotebook, INotebookMimeTypeSelector } from 'vs/workbench/contrib/notebook/common/notebook';
export class MainThreadCell implements ICell {
private _onDidChangeOutputs = new Emitter<void>();
......@@ -183,6 +183,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook
@extHostNamedCustomer(MainContext.MainThreadNotebook)
export class MainThreadNotebooks extends Disposable implements MainThreadNotebookShape {
private readonly _notebookProviders = new Map<string, MainThreadNotebookController>();
private readonly _renderers = new Map<number, MainThreadNotebookController>();
private readonly _proxy: ExtHostNotebookShape;
constructor(
......@@ -196,6 +197,14 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
}));
}
$registerNotebookRenderer(extension: NotebookExtensionDescription, selectors: INotebookMimeTypeSelector, handle: number): Promise<void> {
throw new Error('Method not implemented.');
}
$unregisterNotebookRenderer(handle: number): Promise<void> {
throw new Error('Method not implemented.');
}
async $registerNotebookProvider(extension: NotebookExtensionDescription, viewType: string): Promise<void> {
let controller = new MainThreadNotebookController(this._proxy, this, viewType);
this._notebookProviders.set(viewType, controller);
......
......@@ -50,6 +50,7 @@ import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtens
import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { TunnelOptions } from 'vs/platform/remote/common/tunnel';
import { TimelineItem, TimelineProviderDescriptor, TimelineChangeEvent, TimelineItemWithSource } from 'vs/workbench/contrib/timeline/common/timeline';
import { INotebook, ICell, INotebookMimeTypeSelector } from 'vs/workbench/contrib/notebook/common/notebook';
export interface IEnvironment {
isExtensionDevelopmentDebug: boolean;
......@@ -627,10 +628,12 @@ export interface ExtHostWebviewsShape {
export interface MainThreadNotebookShape extends IDisposable {
$registerNotebookProvider(extension: NotebookExtensionDescription, viewType: string): Promise<void>;
$unregisterNotebookProvider(viewType: string): Promise<void>;
$registerNotebookRenderer(extension: NotebookExtensionDescription, selectors: INotebookMimeTypeSelector, handle: number): Promise<void>;
$unregisterNotebookRenderer(handle: number): Promise<void>;
$createNotebookDocument(handle: number, viewType: string, resource: UriComponents): Promise<void>;
$updateNotebook(viewType: string, resource: UriComponents, notebook: modes.INotebook): Promise<void>;
$updateNotebookCells(viewType: string, resource: UriComponents, cells: modes.ICell[]): Promise<void>;
$updateNotebookCell(viewType: string, resource: UriComponents, cell: modes.ICell): Promise<void>;
$updateNotebook(viewType: string, resource: UriComponents, notebook: INotebook): Promise<void>;
$updateNotebookCells(viewType: string, resource: UriComponents, cells: ICell[]): Promise<void>;
$updateNotebookCell(viewType: string, resource: UriComponents, cell: ICell): Promise<void>;
$updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise<void>;
}
......@@ -1457,7 +1460,7 @@ export interface ExtHostNotebookShape {
$executeNotebook(viewType: string, uri: URI): Promise<void>;
$executeNotebookCell(viewType: string, uri: URI, cellHandle: number): Promise<void>;
$latexRenderer(viewType: string, value: string): Promise<IMarkdownString | undefined>;
$createRawCell(viewType: string, uri: URI, index: number, language: string, type: 'markdown' | 'code'): Promise<modes.ICell | undefined>;
$createRawCell(viewType: string, uri: URI, index: number, language: string, type: 'markdown' | 'code'): Promise<ICell | undefined>;
$deleteCell(viewType: string, uri: URI, index: number): Promise<boolean>;
$saveNotebook(viewType: string, uri: URI): Promise<boolean>;
$updateActiveEditor(viewType: string, uri: URI): Promise<void>;
......
......@@ -12,10 +12,9 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { readonly } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { ICell } from 'vs/editor/common/modes';
// import { ExtHostDocumentData } from 'vs/workbench/api/common/extHostDocumentData';
import * as extHostTypeConverter from 'vs/workbench/api/common/extHostTypeConverters';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { ICell } from 'vs/workbench/contrib/notebook/common/notebook';
export class ExtHostCell implements vscode.NotebookCell {
......@@ -101,7 +100,7 @@ export class ExtHostNotebookDocument implements vscode.NotebookDocument {
} else {
return output;
}
})
});
}
this._proxy.$updateNotebookCell(this.viewType, this.uri, {
......@@ -152,7 +151,7 @@ export class ExtHostNotebookDocument implements vscode.NotebookDocument {
} else {
return output;
}
})
});
}
return {
......@@ -162,9 +161,9 @@ export class ExtHostNotebookDocument implements vscode.NotebookDocument {
cell_type: cell.cell_type,
outputs: outputs,
isDirty: false
}
};
}
));
));
}
insertRawCell(index: number, cell: ExtHostCell) {
......@@ -187,7 +186,7 @@ export class ExtHostNotebookDocument implements vscode.NotebookDocument {
} else {
return output;
}
})
});
}
this._proxy.$updateNotebookCell(this.viewType, this.uri, {
......@@ -302,6 +301,9 @@ export class ExtHostNotebookEditor implements vscode.NotebookEditor {
}
export class ExtHostNotebookOutputRenderer {
private static _handlePool: number = 0;
readonly handle = ExtHostNotebookOutputRenderer._handlePool++;
constructor(
private filter: vscode.NotebookOutputSelector,
private renderer: vscode.NotebookOutputRenderer
......@@ -332,7 +334,7 @@ export class ExtHostNotebookOutputRenderer {
}
render(document: ExtHostNotebookDocument, cell: ExtHostCell, output: vscode.CellOutput): vscode.CellDisplayOutput {
let html = this.renderer.render(document ,cell, output);
let html = this.renderer.render(document, cell, output);
return {
output_type: 'display_data',
......@@ -357,7 +359,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
private readonly _notebookProviders = new Map<string, { readonly provider: vscode.NotebookProvider, readonly extension: IExtensionDescription }>();
private readonly _documents = new Map<string, ExtHostNotebookDocument>();
private readonly _editors = new Map<string, ExtHostNotebookEditor>();
private readonly _notebookOutputRenderers: ExtHostNotebookOutputRenderer[] = [];
private readonly _notebookOutputRenderers = new Map<number, ExtHostNotebookOutputRenderer>();
constructor(mainContext: IMainContext, private _documentsAndEditors: ExtHostDocumentsAndEditors) {
......@@ -377,16 +379,19 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
filter: vscode.NotebookOutputSelector,
renderer: vscode.NotebookOutputRenderer
): vscode.Disposable {
this._notebookOutputRenderers.push(new ExtHostNotebookOutputRenderer(filter, renderer));
let extHostRenderer = new ExtHostNotebookOutputRenderer(filter, renderer);
this._notebookOutputRenderers.set(extHostRenderer.handle, extHostRenderer);
this._proxy.$registerNotebookRenderer({ id: extension.identifier, location: extension.extensionLocation }, filter, extHostRenderer.handle);
return new VSCodeDisposable(() => {
})
this._notebookOutputRenderers.delete(extHostRenderer.handle);
this._proxy.$unregisterNotebookRenderer(extHostRenderer.handle);
});
}
findBestMatchedRenderer(output: vscode.CellOutput): ExtHostNotebookOutputRenderer | undefined {
for (let i = 0; i < this._notebookOutputRenderers.length; i++) {
if (this._notebookOutputRenderers[i].matches(output)) {
return this._notebookOutputRenderers[i];
for (let renderer of this._notebookOutputRenderers) {
if (renderer[1].matches(output)) {
return renderer[1];
}
}
......
......@@ -25,7 +25,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContextKey, InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
import { KeyCode } from 'vs/base/common/keyCodes';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
EditorDescriptor.create(
......
......@@ -31,10 +31,10 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { getZoomLevel } from 'vs/base/browser/browser';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotebook } from 'vs/editor/common/modes';
import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { NotebookHandler, CELL_MARGIN } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { INotebook, CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebook';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
const $ = DOM.$;
const NOTEBOOK_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'NotebookEditorViewState';
......@@ -280,7 +280,7 @@ export class NotebookEditor extends BaseEditor implements NotebookHandler {
let viewState = this.loadTextEditorViewState(input);
this.notebook = model.getNotebook();
this.viewType = input.viewType;
this.viewCells = this.notebook.cells.map(cell => {
this.viewCells = this.notebook!.cells.map(cell => {
const isEditing = viewState && viewState.editingCells[cell.handle];
return new CellViewModel(input.viewType!, this.notebook!.handle, cell, !!isEditing, this.modelService, this.modeService, this.openerService, this.notebookService, this.themeService);
});
......
......@@ -7,8 +7,8 @@ import { EditorInput, EditorModel, IEditorInput, GroupIdentifier, ISaveOptions }
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ITextModel } from 'vs/editor/common/model';
import { Emitter, Event } from 'vs/base/common/event';
import { INotebook, ICell } from 'vs/editor/common/modes';
import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { INotebook, ICell } from 'vs/workbench/contrib/notebook/common/notebook';
export class NotebookEditorModel extends EditorModel {
private _dirty = false;
......
......@@ -3,14 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as DOM from 'vs/base/browser/dom';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/renderers/cellViewModel';
export const CELL_MARGIN = 24;
export interface NotebookHandler {
viewType: string | undefined;
insertEmptyNotebookCell(listIndex: number | undefined, cell: CellViewModel, type: 'markdown' | 'code', direction: 'above' | 'below'): Promise<void>;
......
......@@ -5,13 +5,13 @@
import { Disposable, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { INotebook, ICell } from 'vs/editor/common/modes';
import { URI } from 'vs/base/common/uri';
import { notebookExtensionPoint } from 'vs/workbench/contrib/notebook/browser/extensionPoint';
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
import { Emitter, Event } from 'vs/base/common/event';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { INotebook, ICell } from 'vs/workbench/contrib/notebook/common/notebook';
function MODEL_ID(resource: URI): string {
return resource.toString();
......
......@@ -17,12 +17,12 @@ import { getZoomLevel } from 'vs/base/browser/browser';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { Action } from 'vs/base/common/actions';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { NotebookHandler, CellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { StatefullMarkdownCell } from 'vs/workbench/contrib/notebook/browser/renderers/markdownCell';
import { CellViewModel } from './cellViewModel';
import { CodeCell } from 'vs/workbench/contrib/notebook/browser/renderers/codeCell';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { CellRenderTemplate, NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
export class NotebookCellListDelegate implements IListVirtualDelegate<CellViewModel> {
private _lineHeight: number;
......
......@@ -9,12 +9,12 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { ITextModel } from 'vs/editor/common/model';
import { IModeService } from 'vs/editor/common/services/modeService';
import { Emitter } from 'vs/base/common/event';
import { ICell } from 'vs/editor/common/modes';
import * as UUID from 'vs/base/common/uuid';
import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/renderers/mdRenderer';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ICell } from 'vs/workbench/contrib/notebook/common/notebook';
export class CellViewModel extends Disposable {
private _textModel: ITextModel | null = null;
......
......@@ -5,13 +5,14 @@
import { Disposable } from 'vs/base/common/lifecycle';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/renderers/cellViewModel';
import { CellRenderTemplate, NotebookHandler, CELL_MARGIN } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { getResizesObserver } from 'vs/workbench/contrib/notebook/browser/renderers/sizeObserver';
import { MimeTypeRenderer } from 'vs/workbench/contrib/notebook/browser/renderers/outputRenderer';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebook';
import { CellRenderTemplate, NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
export class CodeCell extends Disposable {
constructor(
......
......@@ -13,7 +13,8 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { URI } from 'vs/base/common/uri';
import { WebviewResourceScheme } from 'vs/workbench/contrib/webview/common/resourceLoader';
import * as path from 'vs/base/common/path';
import { NotebookHandler, CELL_MARGIN } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebook';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
export interface IDimentionMessage {
type: 'dimension';
......
......@@ -6,10 +6,11 @@
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/renderers/cellViewModel';
import { CellRenderTemplate, NotebookHandler, CELL_MARGIN } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { getResizesObserver } from 'vs/workbench/contrib/notebook/browser/renderers/sizeObserver';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebook';
import { NotebookHandler, CellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
export class StatefullMarkdownCell extends Disposable {
private editor: CodeEditorWidget | null = null;
......
......@@ -8,15 +8,15 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { RGBA, Color } from 'vs/base/common/color';
import { ansiColorIdentifiers } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
import { isArray } from 'vs/base/common/types';
import { IOutput } from 'vs/editor/common/modes';
import * as marked from 'vs/base/common/marked/marked';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/renderers/interfaces';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IModelService } from 'vs/editor/common/services/modelService';
import { URI } from 'vs/base/common/uri';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOutput } from 'vs/workbench/contrib/notebook/common/notebook';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookHandler';
export function registerMineTypeRenderer(types: string[], renderer: IMimeRenderer) {
types.forEach(type => {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
export interface INotebookMimeTypeSelector {
type: string;
subTypes?: string[];
}
/**
* @internal
*/
export interface INotebookSelectors {
readonly filenamePattern?: string;
}
/**
* @internal
*/
export interface IStreamOutput {
output_type: 'stream';
text: string;
}
/**
* @internal
*/
export interface IErrorOutput {
output_type: 'error';
/**
* Exception Name
*/
ename?: string;
/**
* Exception Value
*/
evalue?: string;
/**
* Exception call stacks
*/
traceback?: string[];
}
/**
* @internal
*/
export interface IDisplayOutput {
output_type: 'display_data';
/**
* { mime_type: value }
*/
data: { string: string };
}
/**
* @internal
*/
export interface IGenericOutput {
output_type: string;
}
/**
* @internal
*/
export type IOutput = IStreamOutput | any;
/**
* @internal
*/
export interface ICell {
handle: number;
source: string[];
language: string;
cell_type: 'markdown' | 'code';
outputs: IOutput[];
onDidChangeOutputs?: Event<void>;
isDirty: boolean;
}
/**
* @internal
*/
export interface LanguageInfo {
file_extension: string;
}
/**
* @internal
*/
export interface IMetadata {
language_info: LanguageInfo;
}
/**
* @internal
*/
export interface INotebook {
handle: number;
// metadata: IMetadata;
readonly uri: URI;
languages: string[];
cells: ICell[];
onDidChangeCells?: Event<void>;
onDidChangeDirtyState: Event<boolean>;
onWillDispose(listener: () => void): IDisposable;
save(): Promise<boolean>;
}
export const CELL_MARGIN = 24;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册