提交 a14593c8 编写于 作者: J Johannes Rieken

add vscode.notebook.createConcatTextDocument proposal

上级 054cbf4f
......@@ -1667,10 +1667,11 @@ declare module 'vscode' {
languages: string[];
displayOrder?: GlobPattern[];
metadata: NotebookDocumentMetadata;
}
export interface NotebookConcatTextDocument {
isClosed: boolean;
dispose(): void;
onDidChange: Event<void>;
version: number;
getText(): string;
......@@ -1750,6 +1751,13 @@ declare module 'vscode' {
export let activeNotebookDocument: NotebookDocument | undefined;
// export const onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent>;
/**
*
* @param notebook
* @param selector
*/
export function createConcatTextDocument(notebook: NotebookDocument, selector?: DocumentSelector): NotebookConcatTextDocument;
}
//#endregion
......
......@@ -73,6 +73,7 @@ import { IExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelServ
import { IExtHostApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
import { ExtHostAuthentication } from 'vs/workbench/api/common/extHostAuthentication';
import { ExtHostTimeline } from 'vs/workbench/api/common/extHostTimeline';
import { ExtHostNotebookConcatDocument } from 'vs/workbench/api/common/extHostNotebookConcatDocument';
export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
......@@ -910,6 +911,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
},
get activeNotebookDocument(): vscode.NotebookDocument | undefined {
return extHostNotebook.activeNotebookDocument;
},
createConcatTextDocument(notebook, selector) {
checkProposedApiEnabled(extension);
return new ExtHostNotebookConcatDocument(extHostNotebook, extHostDocuments, notebook, selector);
}
};
......
......@@ -6,7 +6,7 @@
import * as types from 'vs/workbench/api/common/extHostTypes';
import * as vscode from 'vscode';
import { Event, Emitter } from 'vs/base/common/event';
import { ExtHostNotebookDocument, ExtHostNotebookController, ExtHostCell } from 'vs/workbench/api/common/extHostNotebook';
import { ExtHostNotebookController, ExtHostCell } from 'vs/workbench/api/common/extHostNotebook';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer';
import { DisposableStore } from 'vs/base/common/lifecycle';
......@@ -17,6 +17,7 @@ import { isEqual } from 'vs/base/common/resources';
export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextDocument {
private _disposables = new DisposableStore();
private _isClosed = false;
private _cells!: ExtHostCell[];
private _cellLengths!: PrefixSumComputer;
......@@ -29,7 +30,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
constructor(
extHostNotebooks: ExtHostNotebookController,
extHostDocuments: ExtHostDocuments,
private readonly _notebook: ExtHostNotebookDocument,
private readonly _notebook: vscode.NotebookDocument,
private readonly _selector: vscode.DocumentSelector | undefined,
) {
this._init();
......@@ -54,6 +55,11 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
dispose(): void {
this._disposables.dispose();
this._isClosed = true;
}
get isClosed() {
return this._isClosed;
}
private _init() {
......@@ -62,7 +68,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
const cellLineCounts: number[] = [];
for (let cell of this._notebook.cells) {
if (cell.cellKind === CellKind.Code && (!this._selector || score(this._selector, cell.uri, cell.language, true))) {
this._cells.push(cell);
this._cells.push(<ExtHostCell>cell);
cellLengths.push(cell.document.getText().length + 1);
cellLineCounts.push(cell.document.lineCount);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册