Merge remote-tracking branch 'origin/notebook/dev' into main

This commit is contained in:
Peng Lyu 2021-05-10 23:44:32 +00:00 committed by GitHub
commit ae998a9261
55 changed files with 697 additions and 573 deletions

View file

@ -140,17 +140,17 @@ suite('Notebook Document', function () {
{
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCells(document.uri, new vscode.NotebookRange(0, 0), [{
kind: vscode.NotebookCellKind.Markdown,
language: 'markdown',
kind: vscode.NotebookCellKind.Markup,
languageId: 'markdown',
metadata: undefined,
outputs: [],
source: 'new_markdown'
value: 'new_markdown'
}, {
kind: vscode.NotebookCellKind.Code,
language: 'fooLang',
languageId: 'fooLang',
metadata: undefined,
outputs: [],
source: 'new_code'
value: 'new_code'
}]);
const success = await vscode.workspace.applyEdit(edit);
@ -177,17 +177,17 @@ suite('Notebook Document', function () {
{
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCells(document.uri, new vscode.NotebookRange(0, 1), [{
kind: vscode.NotebookCellKind.Markdown,
language: 'markdown',
kind: vscode.NotebookCellKind.Markup,
languageId: 'markdown',
metadata: undefined,
outputs: [],
source: 'new2_markdown'
value: 'new2_markdown'
}, {
kind: vscode.NotebookCellKind.Code,
language: 'fooLang',
languageId: 'fooLang',
metadata: undefined,
outputs: [],
source: 'new2_code'
value: 'new2_code'
}]);
const success = await vscode.workspace.applyEdit(edit);
assert.strictEqual(success, true);
@ -213,17 +213,17 @@ suite('Notebook Document', function () {
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCells(document.uri, new vscode.NotebookRange(0, 0), [{
kind: vscode.NotebookCellKind.Markdown,
language: 'markdown',
kind: vscode.NotebookCellKind.Markup,
languageId: 'markdown',
metadata: undefined,
outputs: [],
source: 'new_markdown'
value: 'new_markdown'
}, {
kind: vscode.NotebookCellKind.Code,
language: 'fooLang',
languageId: 'fooLang',
metadata: undefined,
outputs: [],
source: 'new_code'
value: 'new_code'
}]);
const event = utils.asPromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
@ -260,17 +260,17 @@ suite('Notebook Document', function () {
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCells(notebook.uri, new vscode.NotebookRange(0, 0), [{
kind: vscode.NotebookCellKind.Markdown,
language: 'markdown',
kind: vscode.NotebookCellKind.Markup,
languageId: 'markdown',
metadata: undefined,
outputs: [],
source: 'new_markdown'
value: 'new_markdown'
}, {
kind: vscode.NotebookCellKind.Code,
language: 'fooLang',
languageId: 'fooLang',
metadata: undefined,
outputs: [],
source: 'new_code'
value: 'new_code'
}]);
const success = await vscode.workspace.applyEdit(edit);

View file

@ -116,16 +116,16 @@ suite('Notebook API tests', function () {
metadata: new vscode.NotebookDocumentMetadata().with({ custom: { testMetadata: false } }),
cells: [
{
source: 'test',
language: 'typescript',
value: 'test',
languageId: 'typescript',
kind: vscode.NotebookCellKind.Code,
outputs: [],
metadata: new vscode.NotebookCellMetadata().with({ custom: { testCellMetadata: 123 } }),
latestExecutionSummary: { startTime: 10, endTime: 20 }
},
{
source: 'test2',
language: 'typescript',
value: 'test2',
languageId: 'typescript',
kind: vscode.NotebookCellKind.Code,
outputs: [
new vscode.NotebookCellOutput([
@ -416,7 +416,7 @@ suite('Notebook API tests', function () {
const cellMetadataChangeEvent = asPromise<vscode.NotebookCellMetadataChangeEvent>(vscode.notebook.onDidChangeCellMetadata);
const version = vscode.window.activeNotebookEditor!.document.version;
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]);
editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]);
editBuilder.replaceCellMetadata(0, new vscode.NotebookCellMetadata().with({ inputCollapsed: false }));
});
@ -433,7 +433,7 @@ suite('Notebook API tests', function () {
const cellMetadataChangeEvent = asPromise<vscode.NotebookCellMetadataChangeEvent>(vscode.notebook.onDidChangeCellMetadata);
const version = vscode.window.activeNotebookEditor!.document.version;
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]);
editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]);
editBuilder.replaceCellMetadata(0, new vscode.NotebookCellMetadata().with({ inputCollapsed: false }));
});
@ -863,7 +863,7 @@ suite('Notebook API tests', function () {
let eventCount = 0;
let resolve: () => void;
const p = new Promise<void>(r => resolve = r);
const listener = vscode.notebook.onDidChangeCellExecutionState(e => {
const listener = vscode.notebook.onDidChangeNotebookCellExecutionState(e => {
if (eventCount === 0) {
assert.strictEqual(e.executionState, vscode.NotebookCellExecutionState.Pending, 'should be set to Pending');
} else if (eventCount === 1) {
@ -1158,7 +1158,7 @@ suite('Notebook API tests', function () {
const cellsChangeEvent = asPromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
await editor.edit(editBuilder => {
editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]);
editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]);
});
const cellChangeEventRet = await cellsChangeEvent;
@ -1237,7 +1237,7 @@ suite('Notebook API tests', function () {
const emitter = new vscode.EventEmitter<vscode.NotebookCell>();
const onDidCallProvide = emitter.event;
suiteSetup(() => {
vscode.notebook.registerNotebookCellStatusBarItemProvider({ viewType: 'notebookCoreTest' }, {
vscode.notebook.registerNotebookCellStatusBarItemProvider('notebookCoreTest', {
async provideCellStatusBarItems(cell: vscode.NotebookCell, _token: vscode.CancellationToken): Promise<vscode.NotebookCellStatusBarItem[]> {
emitter.fire(cell);
return [];

View file

@ -26,16 +26,16 @@ export function activate(context: vscode.ExtensionContext): any {
metadata: new vscode.NotebookDocumentMetadata(),
cells: [
{
source: 'code()',
language: 'typescript',
value: 'code()',
languageId: 'typescript',
kind: vscode.NotebookCellKind.Code,
outputs: [],
metadata: new vscode.NotebookCellMetadata().with({ custom: { testCellMetadata: 123 } })
},
{
source: 'Markdown Cell',
language: 'markdown',
kind: vscode.NotebookCellKind.Markdown,
value: 'Markdown Cell',
languageId: 'markdown',
kind: vscode.NotebookCellKind.Markup,
outputs: [],
metadata: new vscode.NotebookCellMetadata().with({ custom: { testCellMetadata: 123 } })
}

View file

@ -107,8 +107,8 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
);
}
public lookupKeybinding(commandId: string): ResolvedKeybinding | undefined {
const result = this._getResolver().lookupPrimaryKeybinding(commandId);
public lookupKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybinding | undefined {
const result = this._getResolver().lookupPrimaryKeybinding(commandId, context);
if (!result) {
return undefined;
}

View file

@ -6,7 +6,7 @@
import { Event } from 'vs/base/common/event';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { Keybinding, KeyCode, ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
@ -85,7 +85,7 @@ export interface IKeybindingService {
* Look up the preferred (last defined) keybinding for a command.
* @returns The preferred keybinding or null if the command is not bound.
*/
lookupKeybinding(commandId: string): ResolvedKeybinding | undefined;
lookupKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybinding | undefined;
getDefaultKeybindingsContent(): string;

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IContext, ContextKeyExpression, ContextKeyExprType } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyExpression, ContextKeyExprType, IContext, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
export interface IResolveResult {
@ -247,13 +247,15 @@ export class KeybindingResolver {
return result;
}
public lookupPrimaryKeybinding(commandId: string): ResolvedKeybindingItem | null {
public lookupPrimaryKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybindingItem | null {
let items = this._lookupMap.get(commandId);
if (typeof items === 'undefined' || items.length === 0) {
return null;
}
return items[items.length - 1];
const itemMatchingContext = context &&
Array.from(items).reverse().find(item => context.contextMatchesRules(item.when));
return itemMatchingContext ?? items[items.length - 1];
}
public resolve(context: IContext, currentChord: string | null, keypress: string): IResolveResult | null {

View file

@ -1013,12 +1013,29 @@ declare module 'vscode' {
//#region https://github.com/microsoft/vscode/issues/122922, Notebook, Finalization 1
/**
* A notebook cell kind.
*/
export enum NotebookCellKind {
// todo@API rename/rethink as "Markup" cell
Markdown = 1,
/**
* A markup-cell is formatted source that is used for display.
*/
Markup = 1,
/**
* A code-cell is source that can be {@link NotebookController executed} and that
* produces {@link NotebookCellOutput output}.
*/
Code = 2
}
/**
* Represents a cell of a {@link NotebookDocument notebook}, either a {@link NotebookCellKind.Code code}-cell
* or {@link NotebookCellKind.Markup markup}-cell.
*
* NotebookCell instances are immutable and are kept in sync for as long as they are part of their notebook.
*/
// todo@API support ids https://github.com/jupyter/enhancement-proposals/blob/master/62-cell-id/cell-id.md
export interface NotebookCell {
@ -1257,37 +1274,94 @@ declare module 'vscode' {
//todo@API string or Unit8Array?
value: unknown;
metadata?: Record<string, any>;
metadata?: { [key: string]: any };
constructor(mime: string, value: unknown, metadata?: Record<string, any>);
constructor(mime: string, value: unknown, metadata?: { [key: string]: any });
}
// @jrieken transient
export class NotebookCellOutput {
id: string;
outputs: NotebookCellOutputItem[];
metadata?: Record<string, any>;
constructor(outputs: NotebookCellOutputItem[], metadata?: Record<string, any>);
constructor(outputs: NotebookCellOutputItem[], id: string, metadata?: Record<string, any>);
metadata?: { [key: string]: any };
constructor(outputs: NotebookCellOutputItem[], metadata?: { [key: string]: any });
constructor(outputs: NotebookCellOutputItem[], id: string, metadata?: { [key: string]: any });
}
/**
* NotebookCellData is the raw representation of notebook cells. Its is part of {@link NotebookData `NotebookData`}.
*/
// todo@API support ids https://github.com/jupyter/enhancement-proposals/blob/master/62-cell-id/cell-id.md
export class NotebookCellData {
/**
* The {@link NotebookCellKind kind} of this cell data.
*/
kind: NotebookCellKind;
// todo@API better names: value? text?
source: string;
// todo@API languageId (as in TextDocument)
language: string;
/**
* The source value of this cell data - either source code or formatted text.
*/
value: string;
/**
* The language identifier of the source value of this cell data. Any value from
* {@link languages.getLanguages `getLanguages`} is possible.
*/
languageId: string;
/**
* The outputs of this cell data.
*/
outputs?: NotebookCellOutput[];
/**
* The metadata of this cell data.
*/
metadata?: NotebookCellMetadata;
// todo@API just executionSummary or lastExecutionSummary
latestExecutionSummary?: NotebookCellExecutionSummary;
constructor(kind: NotebookCellKind, source: string, language: string, outputs?: NotebookCellOutput[], metadata?: NotebookCellMetadata, latestExecutionSummary?: NotebookCellExecutionSummary);
/**
* Create new cell data. Minimal cell data specifies its kind, its source value, and the
* language identifier of its source.
*
* @param kind The kind.
* @param value The source value.
* @param languageId The language identifier of the source value.
* @param outputs //TODO@API remove ctor?
* @param metadata //TODO@API remove ctor?
* @param latestExecutionSummary //TODO@API remove ctor?
*/
constructor(kind: NotebookCellKind, value: string, languageId: string, outputs?: NotebookCellOutput[], metadata?: NotebookCellMetadata, latestExecutionSummary?: NotebookCellExecutionSummary);
}
/**
* NotebookData is the raw representation of notebooks.
*
* Extensions are responsible to create {@link NotebookData `NotebookData`} so that the editor
* can create a {@link NotebookDocument `NotebookDocument`}.
*
* @see {@link NotebookSerializer}
*/
export class NotebookData {
/**
* The cell data of this notebook data.
*/
cells: NotebookCellData[];
/**
* The metadata of this notebook data.
*/
metadata: NotebookDocumentMetadata;
/**
* Create new notebook data.
*
* @param cells An array of cell data.
* @param metadata Notebook metadata.
*/
constructor(cells: NotebookCellData[], metadata?: NotebookDocumentMetadata);
}
@ -1403,6 +1477,7 @@ declare module 'vscode' {
endTime?: number;
}
// todo@API jsdoc slightly outdated: kernel, notebook.createNotebookCellExecutionTask
/**
* A NotebookCellExecutionTask is how the kernel modifies a notebook cell as it is executing. When
* {@link notebook.createNotebookCellExecutionTask `createNotebookCellExecutionTask`} is called, the cell
@ -1501,9 +1576,9 @@ declare module 'vscode' {
dispose(): void;
/**
* A kernel can apply to one or many notebook documents but a notebook has only one active
* kernel. This event fires whenever a notebook has been associated to a kernel or when
* that association has been removed.
* An event that fires whenever a controller has been selected for a notebook document. Selecting a controller
* for a notebook is a user gesture and happens either explicitly or implicitly when interacting while a
* controller was suggested.
*/
readonly onDidChangeNotebookAssociation: Event<{ notebook: NotebookDocument, selected: boolean }>;
@ -1633,10 +1708,9 @@ declare module 'vscode' {
// todo@API what is this used for?
// todo@API qualify cell, ...NotebookCell...
export const onDidChangeCellExecutionState: Event<NotebookCellExecutionStateChangeEvent>;
export const onDidChangeNotebookCellExecutionState: Event<NotebookCellExecutionStateChangeEvent>;
// todo@API use viewType instead of NotebookSelector
export function registerNotebookCellStatusBarItemProvider(selector: NotebookSelector, provider: NotebookCellStatusBarItemProvider): Disposable;
export function registerNotebookCellStatusBarItemProvider(notebookType: string, provider: NotebookCellStatusBarItemProvider): Disposable;
}
//#endregion
@ -1848,18 +1922,6 @@ declare module 'vscode' {
//#endregion
//#region https://github.com/microsoft/vscode/issues/119949, Notebook (deprecated)
export interface NotebookFilter {
readonly viewType?: string;
readonly scheme?: string;
readonly pattern?: GlobPattern;
}
export type NotebookSelector = NotebookFilter | string | ReadonlyArray<NotebookFilter | string>;
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookContentProvider

View file

@ -10,7 +10,6 @@ import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle'
import { URI } from 'vs/base/common/uri';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { NotebookSelector } from 'vs/workbench/contrib/notebook/common/notebookSelector';
import { INotebookCellStatusBarItemProvider, INotebookContributionData, NotebookDataDto, TransientCellMetadata, TransientDocumentMetadata, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookContentProvider, INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { ExtHostContext, ExtHostNotebookShape, IExtHostContext, MainContext, MainThreadNotebookShape, NotebookExtensionDescription } from '../common/extHost.protocol';
@ -131,7 +130,7 @@ export class MainThreadNotebooks implements MainThreadNotebookShape {
}
}
async $registerNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined, selector: NotebookSelector): Promise<void> {
async $registerNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined, viewType: string): Promise<void> {
const that = this;
const provider: INotebookCellStatusBarItemProvider = {
async provideCellStatusBarItems(uri: URI, index: number, token: CancellationToken) {
@ -145,7 +144,7 @@ export class MainThreadNotebooks implements MainThreadNotebookShape {
}
};
},
selector: selector
viewType
};
if (typeof eventHandle === 'number') {

View file

@ -1065,9 +1065,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension);
return extHostNotebook.registerNotebookContentProvider(extension, viewType, provider, options, extension.enableProposedApi ? registration : undefined);
},
registerNotebookCellStatusBarItemProvider: (selector: vscode.NotebookSelector, provider: vscode.NotebookCellStatusBarItemProvider) => {
registerNotebookCellStatusBarItemProvider: (notebookType: string, provider: vscode.NotebookCellStatusBarItemProvider) => {
checkProposedApiEnabled(extension);
return extHostNotebook.registerNotebookCellStatusBarItemProvider(extension, selector, provider);
return extHostNotebook.registerNotebookCellStatusBarItemProvider(extension, notebookType, provider);
},
createNotebookEditorDecorationType(options: vscode.NotebookDecorationRenderOptions): vscode.NotebookEditorDecorationType {
checkProposedApiEnabled(extension);
@ -1081,7 +1081,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension);
return extHostNotebook.onDidChangeNotebookCells(listener, thisArgs, disposables);
},
onDidChangeCellExecutionState(listener, thisArgs?, disposables?) {
onDidChangeNotebookCellExecutionState(listener, thisArgs?, disposables?) {
checkProposedApiEnabled(extension);
return extHostNotebook.onDidChangeNotebookCellExecutionState(listener, thisArgs, disposables);
},

View file

@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as performance from 'vs/base/common/performance';
import { VSBuffer } from 'vs/base/common/buffer';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IRemoteConsoleLog } from 'vs/base/common/console';
@ -11,7 +10,10 @@ import { SerializedError } from 'vs/base/common/errors';
import { IRelativePattern } from 'vs/base/common/glob';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IDisposable } from 'vs/base/common/lifecycle';
import { revive } from 'vs/base/common/marshalling';
import * as performance from 'vs/base/common/performance';
import Severity from 'vs/base/common/severity';
import { Dto } from 'vs/base/common/types';
import { URI, UriComponents } from 'vs/base/common/uri';
import { RenderLineNumbersType, TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
import { IPosition } from 'vs/editor/common/core/position';
@ -22,8 +24,9 @@ import { EndOfLineSequence, ISingleEditOperation } from 'vs/editor/common/model'
import { IModelChangedEvent } from 'vs/editor/common/model/mirrorTextModel';
import * as modes from 'vs/editor/common/modes';
import { CharacterPair, CommentRule, EnterAction } from 'vs/editor/common/modes/languageConfiguration';
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { ConfigurationTarget, IConfigurationData, IConfigurationChange, IConfigurationOverrides } from 'vs/platform/configuration/common/configuration';
import { ConfigurationTarget, IConfigurationChange, IConfigurationData, IConfigurationOverrides } from 'vs/platform/configuration/common/configuration';
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import * as files from 'vs/platform/files/common/files';
@ -32,39 +35,35 @@ import { LogLevel } from 'vs/platform/log/common/log';
import { IMarkerData } from 'vs/platform/markers/common/markers';
import { IProgressOptions, IProgressStep } from 'vs/platform/progress/common/progress';
import * as quickInput from 'vs/platform/quickinput/common/quickInput';
import { RemoteAuthorityResolverErrorCode, ResolverResult, TunnelDescription, IRemoteConnectionData } from 'vs/platform/remote/common/remoteAuthorityResolver';
import * as statusbar from 'vs/workbench/services/statusbar/common/statusbar';
import { IRemoteConnectionData, RemoteAuthorityResolverErrorCode, ResolverResult, TunnelDescription } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { ProvidedPortAttributes, TunnelCreationOptions, TunnelOptions, TunnelProviderFeatures } from 'vs/platform/remote/common/tunnel';
import { ClassifiedEvent, GDPRClassification, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
import { IShellLaunchConfig, IShellLaunchConfigDto, ITerminalDimensions, ITerminalEnvironment, ITerminalLaunchError } from 'vs/platform/terminal/common/terminal';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
import * as tasks from 'vs/workbench/api/common/shared/tasks';
import { IRevealOptions, ITreeItem } from 'vs/workbench/common/views';
import { IAdapterDescriptor, IConfig, IDebugSessionReplMode } from 'vs/workbench/contrib/debug/common/debug';
import { ITextQueryBuilderOptions } from 'vs/workbench/contrib/search/common/queryBuilder';
import { ActivationKind, MissingExtensionDependency, ExtensionHostKind } from 'vs/workbench/services/extensions/common/extensions';
import { createExtHostContextProxyIdentifier as createExtId, createMainContextProxyIdentifier as createMainId, IRPCProtocol } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import * as search from 'vs/workbench/services/search/common/search';
import { EditorGroupColumn, SaveReason } from 'vs/workbench/common/editor';
import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/extensionsStorageSync';
import { WorkspaceTrustRequestOptions } from 'vs/platform/workspace/common/workspaceTrust';
import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtensionActivator';
import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { TunnelCreationOptions, TunnelProviderFeatures, TunnelOptions, ProvidedPortAttributes } from 'vs/platform/remote/common/tunnel';
import { Timeline, TimelineChangeEvent, TimelineOptions, TimelineProviderDescriptor, InternalTimelineOptions } from 'vs/workbench/contrib/timeline/common/timeline';
import { revive } from 'vs/base/common/marshalling';
import { NotebookCellMetadata, NotebookDocumentMetadata, ICellEditOperation, NotebookCellsChangedEventDto, NotebookDataDto, IMainCellDto, TransientCellMetadata, INotebookDecorationRenderOptions, IOutputDto, TransientOptions, IImmediateCellEditOperation, INotebookCellStatusBarItem, TransientDocumentMetadata, INotebookContributionData } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { Dto } from 'vs/base/common/types';
import { DebugConfigurationProviderTriggerKind, TestResultState } from 'vs/workbench/api/common/extHostTypes';
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/extensionsStorageSync';
import { InternalTestItem, RunTestForProviderRequest, RunTestsRequest, TestIdWithSrc, TestsDiff, ISerializedTestResults, ITestMessage, ITestItem, ITestRunTask, ExtensionRunTestsRequest } from 'vs/workbench/contrib/testing/common/testCollection';
import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { WorkspaceTrustRequestOptions } from 'vs/platform/workspace/common/workspaceTrust';
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
import { IShellLaunchConfig, IShellLaunchConfigDto, ITerminalDimensions, ITerminalEnvironment, ITerminalLaunchError } from 'vs/platform/terminal/common/terminal';
import { ITerminalProfile } from 'vs/workbench/contrib/terminal/common/terminal';
import { NotebookSelector } from 'vs/workbench/contrib/notebook/common/notebookSelector';
import * as tasks from 'vs/workbench/api/common/shared/tasks';
import { EditorGroupColumn, SaveReason } from 'vs/workbench/common/editor';
import { IRevealOptions, ITreeItem } from 'vs/workbench/common/views';
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { IAdapterDescriptor, IConfig, IDebugSessionReplMode } from 'vs/workbench/contrib/debug/common/debug';
import { CellKind, ICellEditOperation, IImmediateCellEditOperation, IMainCellDto, INotebookCellStatusBarItem, INotebookContributionData, INotebookDecorationRenderOptions, IOutputDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookDataDto, NotebookDocumentMetadata, TransientCellMetadata, TransientDocumentMetadata, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { InputValidationType } from 'vs/workbench/contrib/scm/common/scm';
import { ITextQueryBuilderOptions } from 'vs/workbench/contrib/search/common/queryBuilder';
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
import { ITerminalProfile } from 'vs/workbench/contrib/terminal/common/terminal';
import { ExtensionRunTestsRequest, InternalTestItem, ISerializedTestResults, ITestItem, ITestMessage, ITestRunTask, RunTestForProviderRequest, RunTestsRequest, TestIdWithSrc, TestsDiff } from 'vs/workbench/contrib/testing/common/testCollection';
import { InternalTimelineOptions, Timeline, TimelineChangeEvent, TimelineOptions, TimelineProviderDescriptor } from 'vs/workbench/contrib/timeline/common/timeline';
import { ActivationKind, ExtensionHostKind, MissingExtensionDependency } from 'vs/workbench/services/extensions/common/extensions';
import { createExtHostContextProxyIdentifier as createExtId, createMainContextProxyIdentifier as createMainId, IRPCProtocol } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService';
import * as search from 'vs/workbench/services/search/common/search';
import * as statusbar from 'vs/workbench/services/statusbar/common/statusbar';
export interface IEnvironment {
isExtensionDevelopmentDebug: boolean;
@ -817,11 +816,6 @@ export interface ExtHostWebviewViewsShape {
$disposeWebviewView(webviewHandle: WebviewHandle): void;
}
export enum CellKind {
Markdown = 1,
Code = 2
}
export enum CellOutputKind {
Text = 1,
Error = 2,
@ -879,7 +873,7 @@ export interface MainThreadNotebookShape extends IDisposable {
$registerNotebookSerializer(handle: number, extension: NotebookExtensionDescription, viewType: string, options: TransientOptions, registration: INotebookContributionData | undefined): void;
$unregisterNotebookSerializer(handle: number): void;
$registerNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined, selector: NotebookSelector): Promise<void>;
$registerNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined, viewType: string): Promise<void>;
$unregisterNotebookCellStatusBarItemProvider(handle: number, eventHandle: number | undefined): Promise<void>;
$emitCellStatusBarEvent(eventHandle: number): void;
}

View file

@ -228,13 +228,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
};
}
registerNotebookCellStatusBarItemProvider(extension: IExtensionDescription, selector: vscode.NotebookSelector, provider: vscode.NotebookCellStatusBarItemProvider) {
registerNotebookCellStatusBarItemProvider(extension: IExtensionDescription, notebookType: string, provider: vscode.NotebookCellStatusBarItemProvider) {
const handle = ExtHostNotebookController._notebookStatusBarItemProviderHandlePool++;
const eventHandle = typeof provider.onDidChangeCellStatusBarItems === 'function' ? ExtHostNotebookController._notebookStatusBarItemProviderHandlePool++ : undefined;
this._notebookStatusBarItemProviders.set(handle, provider);
this._notebookProxy.$registerNotebookCellStatusBarItemProvider(handle, eventHandle, selector);
this._notebookProxy.$registerNotebookCellStatusBarItemProvider(handle, eventHandle, notebookType);
let subscription: vscode.Disposable | undefined;
if (eventHandle !== undefined) {
@ -358,11 +358,19 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
if (!serializer) {
throw new Error('NO serializer found');
}
const data = await serializer.deserializeNotebook(bytes.buffer, token);
return {
const res: NotebookDataDto = {
metadata: typeConverters.NotebookDocumentMetadata.from(data.metadata),
cells: data.cells.map(typeConverters.NotebookCellData.from),
cells: [],
};
for (let cell of data.cells) {
extHostTypes.NotebookCellData.validate(cell);
res.cells.push(typeConverters.NotebookCellData.from(cell));
}
return res;
}
async $notebookToData(handle: number, data: NotebookDataDto, token: CancellationToken): Promise<VSBuffer> {

View file

@ -6,12 +6,12 @@
import { Schemas } from 'vs/base/common/network';
import { deepFreeze, equals } from 'vs/base/common/objects';
import { URI } from 'vs/base/common/uri';
import { CellKind, INotebookDocumentPropertiesChangeData, MainThreadNotebookDocumentsShape } from 'vs/workbench/api/common/extHost.protocol';
import { INotebookDocumentPropertiesChangeData, MainThreadNotebookDocumentsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors, IExtHostModelAddedData } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { IMainCellDto, IOutputDto, IOutputItemDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, IMainCellDto, IOutputDto, IOutputItemDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
class RawContentChangeEvent {

View file

@ -1466,8 +1466,8 @@ export namespace NotebookCellPreviousExecutionResult {
export namespace NotebookCellKind {
export function from(data: vscode.NotebookCellKind): notebooks.CellKind {
switch (data) {
case types.NotebookCellKind.Markdown:
return notebooks.CellKind.Markdown;
case types.NotebookCellKind.Markup:
return notebooks.CellKind.Markup;
case types.NotebookCellKind.Code:
default:
return notebooks.CellKind.Code;
@ -1476,8 +1476,8 @@ export namespace NotebookCellKind {
export function to(data: notebooks.CellKind): vscode.NotebookCellKind {
switch (data) {
case notebooks.CellKind.Markdown:
return types.NotebookCellKind.Markdown;
case notebooks.CellKind.Markup:
return types.NotebookCellKind.Markup;
case notebooks.CellKind.Code:
default:
return types.NotebookCellKind.Code;
@ -1490,8 +1490,8 @@ export namespace NotebookCellData {
export function from(data: vscode.NotebookCellData): notebooks.ICellDto2 {
return {
cellKind: NotebookCellKind.from(data.kind),
language: data.language,
source: data.source,
language: data.languageId,
source: data.value,
metadata: {
...data.metadata,
...NotebookCellPreviousExecutionResult.from(data.latestExecutionSummary ?? {})

View file

@ -3023,6 +3023,18 @@ export class NotebookDocumentMetadata {
export class NotebookCellData {
static validate(data: NotebookCellData): void {
if (typeof data.kind !== 'number') {
throw new Error('NotebookCellData MUST have \'kind\' property');
}
if (typeof data.value !== 'string') {
throw new Error('NotebookCellData MUST have \'value\' property');
}
if (typeof data.languageId !== 'string') {
throw new Error('NotebookCellData MUST have \'languageId\' property');
}
}
static isNotebookCellDataArray(value: unknown): value is vscode.NotebookCellData[] {
return Array.isArray(value) && (<unknown[]>value).every(elem => NotebookCellData.isNotebookCellData(elem));
}
@ -3033,19 +3045,21 @@ export class NotebookCellData {
}
kind: NotebookCellKind;
source: string;
language: string;
value: string;
languageId: string;
outputs?: NotebookCellOutput[];
metadata?: NotebookCellMetadata;
latestExecutionSummary?: vscode.NotebookCellExecutionSummary;
constructor(kind: NotebookCellKind, source: string, language: string, outputs?: NotebookCellOutput[], metadata?: NotebookCellMetadata, latestExecutionSummary?: vscode.NotebookCellExecutionSummary) {
constructor(kind: NotebookCellKind, value: string, languageId: string, outputs?: NotebookCellOutput[], metadata?: NotebookCellMetadata, latestExecutionSummary?: vscode.NotebookCellExecutionSummary) {
this.kind = kind;
this.source = source;
this.language = language;
this.value = value;
this.languageId = languageId;
this.outputs = outputs ?? [];
this.metadata = metadata;
this.latestExecutionSummary = latestExecutionSummary;
NotebookCellData.validate(this);
}
}
@ -3101,7 +3115,7 @@ export class NotebookCellOutput {
}
export enum NotebookCellKind {
Markdown = 1,
Markup = 1,
Code = 2
}

View file

@ -17,9 +17,9 @@ suite('CellOperations', () => {
test('Move cells - single cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -34,9 +34,9 @@ suite('CellOperations', () => {
test('Move cells - multiple cells in a selection', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -53,9 +53,9 @@ suite('CellOperations', () => {
test('Move cells - move with folding ranges', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -80,9 +80,9 @@ suite('CellOperations', () => {
test('Copy/duplicate cells - single cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -99,9 +99,9 @@ suite('CellOperations', () => {
test('Copy/duplicate cells - target and selection are different, #119769', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -118,9 +118,9 @@ suite('CellOperations', () => {
test('Copy/duplicate cells - multiple cells in a selection', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -139,9 +139,9 @@ suite('CellOperations', () => {
test('Copy/duplicate cells - move with folding ranges', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -168,9 +168,9 @@ suite('CellOperations', () => {
test('Join cell with below - single cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -196,9 +196,9 @@ suite('CellOperations', () => {
test('Join cell with above - single cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],
@ -445,4 +445,3 @@ suite('CellOperations', () => {
});
});
});

View file

@ -38,9 +38,9 @@ suite('Notebook Clipboard', () => {
test('Cut multiple selected cells', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(INotebookService, new class extends mock<INotebookService>() { override setToCopy() { } });
@ -59,12 +59,12 @@ suite('Notebook Clipboard', () => {
test('Cut should take folding info into account', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3', 'javascript', CellKind.Markdown, [], {}],
['# header d', 'markdown', CellKind.Markdown, [], {}],
['var c = 3', 'javascript', CellKind.Markup, [], {}],
['# header d', 'markdown', CellKind.Markup, [], {}],
['var e = 4;', 'javascript', CellKind.Code, [], {}],
],
async (editor, accessor) => {
@ -91,12 +91,12 @@ suite('Notebook Clipboard', () => {
test('Copy should take folding info into account', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3', 'javascript', CellKind.Markdown, [], {}],
['# header d', 'markdown', CellKind.Markdown, [], {}],
['var c = 3', 'javascript', CellKind.Markup, [], {}],
['# header d', 'markdown', CellKind.Markup, [], {}],
['var e = 4;', 'javascript', CellKind.Code, [], {}],
],
async (editor, accessor) => {
@ -129,9 +129,9 @@ suite('Notebook Clipboard', () => {
test('#119773, cut last item should not focus on the top first cell', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(INotebookService, new class extends mock<INotebookService>() { override setToCopy() { } });
@ -148,9 +148,9 @@ suite('Notebook Clipboard', () => {
test('#119771, undo paste should restore selections', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(INotebookService, new class extends mock<INotebookService>() {
@ -183,9 +183,9 @@ suite('Notebook Clipboard', () => {
test('copy cell from ui still works if the target cell is not part of a selection', async () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
let _toCopy: NotebookCellTextModel[] = [];
@ -213,10 +213,10 @@ suite('Notebook Clipboard', () => {
test('cut cell from ui still works if the target cell is not part of a selection', async () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['paragraph 3', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
['paragraph 3', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(INotebookService, new class extends mock<INotebookService>() {
@ -255,10 +255,10 @@ suite('Notebook Clipboard', () => {
test('cut focus cell still works if the focus is not part of any selection', async () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['paragraph 3', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
['paragraph 3', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(INotebookService, new class extends mock<INotebookService>() {
@ -280,10 +280,10 @@ suite('Notebook Clipboard', () => {
test('cut focus cell still works if the focus is not part of any selection 2', async () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['paragraph 3', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
['paragraph 3', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(INotebookService, new class extends mock<INotebookService>() {

View file

@ -686,7 +686,7 @@ registerAction2(class ExecuteNotebookAction extends NotebookAction {
function renderAllMarkdownCells(context: INotebookActionContext): void {
context.notebookEditor.viewModel.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
cell.updateEditState(CellEditState.Preview, 'renderAllMarkdownCells');
}
});
@ -784,7 +784,7 @@ registerAction2(class ChangeCellToMarkdownAction extends NotebookCellAction {
}
async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
await changeCellToKind(CellKind.Markdown, context);
await changeCellToKind(CellKind.Markup, context);
}
});
@ -956,7 +956,7 @@ registerAction2(class InsertMarkdownCellAtTopAction extends NotebookAction {
}
async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
const newCell = context.notebookEditor.insertNotebookCell(undefined, CellKind.Markdown, 'above', undefined, true);
const newCell = context.notebookEditor.insertNotebookCell(undefined, CellKind.Markup, 'above', undefined, true);
if (newCell) {
context.notebookEditor.focusNotebookCell(newCell, 'editor');
}
@ -996,7 +996,7 @@ registerAction2(class InsertMarkdownCellAboveAction extends InsertCellCommand {
order: 2
}
},
CellKind.Markdown,
CellKind.Markup,
'above');
}
});
@ -1012,7 +1012,7 @@ registerAction2(class InsertMarkdownCellBelowAction extends InsertCellCommand {
order: 3
}
},
CellKind.Markdown,
CellKind.Markup,
'below');
}
});
@ -1110,7 +1110,7 @@ registerAction2(class QuitEditCellAction extends NotebookCellAction {
}
async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext) {
if (context.cell.cellKind === CellKind.Markdown) {
if (context.cell.cellKind === CellKind.Markup) {
context.cell.updateEditState(CellEditState.Preview, QUIT_EDIT_CELL_COMMAND_ID);
}
@ -1356,7 +1356,7 @@ registerAction2(class ChangeCellLanguageAction extends NotebookCellAction<ICellR
providerLanguages.forEach(languageId => {
let description: string;
if (context.cell.cellKind === CellKind.Markdown ? (languageId === 'markdown') : (languageId === context.cell.language)) {
if (context.cell.cellKind === CellKind.Markup ? (languageId === 'markdown') : (languageId === context.cell.language)) {
description = localize('languageDescription', "({0}) - Current Language", languageId);
} else {
description = localize('languageDescriptionConfigured', "({0})", languageId);
@ -1400,11 +1400,11 @@ registerAction2(class ChangeCellLanguageAction extends NotebookCellAction<ICellR
private async setLanguage(context: IChangeCellContext, languageId: string) {
if (languageId === 'markdown' && context.cell?.language !== 'markdown') {
const newCell = await changeCellToKind(CellKind.Markdown, { cell: context.cell, notebookEditor: context.notebookEditor }, 'markdown');
const newCell = await changeCellToKind(CellKind.Markup, { cell: context.cell, notebookEditor: context.notebookEditor }, 'markdown');
if (newCell) {
context.notebookEditor.focusNotebookCell(newCell, 'editor');
}
} else if (languageId !== 'markdown' && context.cell?.cellKind === CellKind.Markdown) {
} else if (languageId !== 'markdown' && context.cell?.cellKind === CellKind.Markup) {
await changeCellToKind(CellKind.Code, { cell: context.cell, notebookEditor: context.notebookEditor }, languageId);
} else {
const index = context.notebookEditor.viewModel.notebookDocument.cells.indexOf(context.cell.model);

View file

@ -169,14 +169,14 @@ export class FindModel extends Disposable {
// the cell still exist
const cell = this._notebookEditor.viewModel!.viewCells[oldCurrMatchCellIndex];
if (cell.cellKind === CellKind.Markdown && cell.getEditState() === CellEditState.Preview) {
if (cell.cellKind === CellKind.Markup && cell.getEditState() === CellEditState.Preview) {
// find the nearest match above this cell
const matchAfterSelection = findFirstInSorted(findMatches.map(match => match.index), index => index >= oldCurrMatchCellIndex);
this._updateCurrentMatch(findMatches, this._matchesCountBeforeIndex(findMatches, matchAfterSelection));
return;
}
if ((cell.cellKind === CellKind.Markdown && cell.getEditState() === CellEditState.Editing) || cell.cellKind === CellKind.Code) {
if ((cell.cellKind === CellKind.Markup && cell.getEditState() === CellEditState.Editing) || cell.cellKind === CellKind.Code) {
// check if there is monaco editor selection and find the first match, otherwise find the first match above current cell
// this._findMatches[cellIndex].matches[matchIndex].range
const currentMatchDecorationId = this._currentMatchDecorations.find(decoration => decoration.ownerId === cell.handle);

View file

@ -50,9 +50,9 @@ suite('Notebook Find', () => {
test('Update find matches basics', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
accessor.stub(IConfigurationService, configurationService);
@ -85,11 +85,11 @@ suite('Notebook Find', () => {
test('Update find matches basics 2', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.2', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.3', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.2', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.3', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
setupEditorForTest(editor);
@ -128,11 +128,11 @@ suite('Notebook Find', () => {
test('Update find matches basics 3', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.2', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.3', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.2', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.3', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
setupEditorForTest(editor);
@ -164,11 +164,11 @@ suite('Notebook Find', () => {
test('Update find matches, #112748', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.1', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.2', 'markdown', CellKind.Markdown, [], {}],
['paragraph 1.3', 'markdown', CellKind.Markdown, [], {}],
['paragraph 2', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.1', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.2', 'markdown', CellKind.Markup, [], {}],
['paragraph 1.3', 'markdown', CellKind.Markup, [], {}],
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
setupEditorForTest(editor);

View file

@ -39,7 +39,7 @@ export class FoldingController extends Disposable implements INotebookEditorCont
}
this._localStore.add(this._notebookEditor.viewModel.eventDispatcher.onDidChangeCellState(e => {
if (e.source.editStateChanged && e.cell.cellKind === CellKind.Markdown) {
if (e.source.editStateChanged && e.cell.cellKind === CellKind.Markup) {
this._foldingModel?.recompute();
// this._updateEditorFoldingRanges();
}

View file

@ -16,13 +16,13 @@ suite('Notebook Folding', () => {
test('Folding based on markdown cells', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['## header 2.1', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['## header 2.1', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -43,13 +43,13 @@ suite('Notebook Folding', () => {
test('Top level header in a cell wins', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['## header 2.1\n# header3', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['## header 2.1\n# header3', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -75,13 +75,13 @@ suite('Notebook Folding', () => {
test('Folding', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['## header 2.1', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['## header 2.1', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -97,13 +97,13 @@ suite('Notebook Folding', () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['## header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['## header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -120,13 +120,13 @@ suite('Notebook Folding', () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -145,13 +145,13 @@ suite('Notebook Folding', () => {
test('Nested Folding', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -200,18 +200,18 @@ suite('Notebook Folding', () => {
test('Folding Memento', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -229,18 +229,18 @@ suite('Notebook Folding', () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -262,18 +262,18 @@ suite('Notebook Folding', () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -297,18 +297,18 @@ suite('Notebook Folding', () => {
test('View Index', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;
@ -334,18 +334,18 @@ suite('Notebook Folding', () => {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markdown, [], {}],
['body 2', 'markdown', CellKind.Markdown, [], {}],
['body 3', 'markdown', CellKind.Markdown, [], {}],
['## header 2.2', 'markdown', CellKind.Markdown, [], {}],
['var e = 7;', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
['# header 2.1\n', 'markdown', CellKind.Markup, [], {}],
['body 2', 'markdown', CellKind.Markup, [], {}],
['body 3', 'markdown', CellKind.Markup, [], {}],
['## header 2.2', 'markdown', CellKind.Markup, [], {}],
['var e = 7;', 'markdown', CellKind.Markup, [], {}],
],
(editor) => {
const viewModel = editor.viewModel;

View file

@ -68,7 +68,7 @@ registerAction2(class extends NotebookCellAction {
return;
}
const newFocusMode = newCell.cellKind === CellKind.Markdown && newCell.getEditState() === CellEditState.Preview ? 'container' : 'editor';
const newFocusMode = newCell.cellKind === CellKind.Markup && newCell.getEditState() === CellEditState.Preview ? 'container' : 'editor';
editor.focusNotebookCell(newCell, newFocusMode);
editor.cursorNavigationMode = true;
}
@ -115,7 +115,7 @@ registerAction2(class extends NotebookCellAction {
return;
}
const newFocusMode = newCell.cellKind === CellKind.Markdown && newCell.getEditState() === CellEditState.Preview ? 'container' : 'editor';
const newFocusMode = newCell.cellKind === CellKind.Markup && newCell.getEditState() === CellEditState.Preview ? 'container' : 'editor';
editor.focusNotebookCell(newCell, newFocusMode);
editor.cursorNavigationMode = true;
}

View file

@ -396,7 +396,7 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> {
for (let i = 0; i < viewModel.length; i++) {
const cell = viewModel.viewCells[i];
const isMarkdown = cell.cellKind === CellKind.Markdown;
const isMarkdown = cell.cellKind === CellKind.Markup;
if (!isMarkdown && !includeCodeCells) {
continue;
}

View file

@ -49,7 +49,7 @@ suite('Notebook Outline', function () {
test('special characters in heading', async function () {
await withNotebookOutline([
['# Hellö & Hällo', 'md', CellKind.Markdown]
['# Hellö & Hällo', 'md', CellKind.Markup]
], outline => {
assert.ok(outline instanceof NotebookCellOutline);
assert.deepStrictEqual(outline.config.quickPickDataSource.getQuickPickElements().length, 1);
@ -57,7 +57,7 @@ suite('Notebook Outline', function () {
});
await withNotebookOutline([
['# bo<i>ld</i>', 'md', CellKind.Markdown]
['# bo<i>ld</i>', 'md', CellKind.Markup]
], outline => {
assert.ok(outline instanceof NotebookCellOutline);
assert.deepStrictEqual(outline.config.quickPickDataSource.getQuickPickElements().length, 1);
@ -67,7 +67,7 @@ suite('Notebook Outline', function () {
test('Heading text defines entry label', async function () {
return await withNotebookOutline([
['foo\n # h1', 'md', CellKind.Markdown]
['foo\n # h1', 'md', CellKind.Markup]
], outline => {
assert.ok(outline instanceof NotebookCellOutline);
assert.deepStrictEqual(outline.config.quickPickDataSource.getQuickPickElements().length, 1);
@ -77,7 +77,7 @@ suite('Notebook Outline', function () {
test('Notebook outline ignores markdown headings #115200', async function () {
await withNotebookOutline([
['## h2 \n# h1', 'md', CellKind.Markdown]
['## h2 \n# h1', 'md', CellKind.Markup]
], outline => {
assert.ok(outline instanceof NotebookCellOutline);
assert.deepStrictEqual(outline.config.quickPickDataSource.getQuickPickElements().length, 2);
@ -86,8 +86,8 @@ suite('Notebook Outline', function () {
});
await withNotebookOutline([
['## h2', 'md', CellKind.Markdown],
['# h1', 'md', CellKind.Markdown]
['## h2', 'md', CellKind.Markup],
['# h1', 'md', CellKind.Markup]
], outline => {
assert.ok(outline instanceof NotebookCellOutline);
assert.deepStrictEqual(outline.config.quickPickDataSource.getQuickPickElements().length, 2);

View file

@ -13,16 +13,19 @@ import { getNotebookEditorFromEditorPane, INotebookEditor, NOTEBOOK_IS_ACTIVE_ED
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { combinedDisposable, Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/common/statusbar';
import { configureKernelIcon, selectKernelIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { INotebookKernel, INotebookTextModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernel, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ILabelService } from 'vs/platform/label/common/label';
import { ILogService } from 'vs/platform/log/common/log';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { HoverProviderRegistry } from 'vs/editor/common/modes';
import { Schemas } from 'vs/base/common/network';
registerAction2(class extends Action2 {
constructor() {
@ -144,15 +147,65 @@ registerAction2(class extends Action2 {
}
});
class ImplictKernelSelector implements IDisposable {
readonly dispose: () => void;
constructor(
notebook: NotebookTextModel,
suggested: INotebookKernel,
@INotebookKernelService notebookKernelService: INotebookKernelService,
@ILogService logService: ILogService
) {
const disposables = new DisposableStore();
this.dispose = disposables.dispose.bind(disposables);
const selectKernel = () => {
disposables.clear();
notebookKernelService.selectKernelForNotebook(suggested, notebook);
};
// IMPLICITLY select a suggested kernel when the notebook has been changed
// e.g change cell source, move cells, etc
disposables.add(notebook.onDidChangeContent(e => {
for (let event of e.rawEvents) {
switch (event.kind) {
case NotebookCellsChangeType.ChangeCellContent:
case NotebookCellsChangeType.ModelChange:
case NotebookCellsChangeType.Move:
case NotebookCellsChangeType.ChangeLanguage:
logService.trace('IMPLICIT kernel selection because of change event', event.kind);
selectKernel();
break;
}
}
}));
// IMPLICITLY select a suggested kernel when users start to hover. This should
// be a strong enough hint that the user wants to interact with the notebook. Maybe
// add more triggers like goto-providers or completion-providers
disposables.add(HoverProviderRegistry.register({ scheme: Schemas.vscodeNotebookCell, pattern: notebook.uri.path }, {
provideHover() {
logService.trace('IMPLICIT kernel selection because of hover');
selectKernel();
return undefined;
}
}));
}
}
export class KernelStatus extends Disposable implements IWorkbenchContribution {
private readonly _editorDisposables = this._register(new DisposableStore());
private readonly _kernelInfoElement = this._register(new MutableDisposable());
private readonly _kernelInfoElement = this._register(new DisposableStore());
constructor(
@IEditorService private readonly _editorService: IEditorService,
@IStatusbarService private readonly _statusbarService: IStatusbarService,
@INotebookKernelService private readonly _notebookKernelService: INotebookKernelService,
@ILogService private readonly _logService: ILogService,
) {
super();
this._register(this._editorService.onDidActiveEditorChange(() => this._updateStatusbar()));
@ -184,42 +237,48 @@ export class KernelStatus extends Disposable implements IWorkbenchContribution {
updateStatus();
}
private _showKernelStatus(notebook: INotebookTextModel) {
private _showKernelStatus(notebook: NotebookTextModel) {
let { selected, all } = this._notebookKernelService.getMatchingKernel(notebook);
this._kernelInfoElement.clear();
let { selected, suggested, all } = this._notebookKernelService.getMatchingKernel(notebook);
let isSuggested = false;
if (all.length === 0) {
// no kernel -> no status
this._kernelInfoElement.clear();
return;
} else if (selected || all.length === 1) {
} else if (selected || suggested) {
// selected or single kernel
if (!selected) {
selected = all[0];
let kernel = selected;
if (!kernel) {
// proceed with suggested kernel - show UI and install handler that selects the kernel
// when non trivial interactions with the notebook happen.
kernel = suggested!;
isSuggested = true;
this._kernelInfoElement.add(new ImplictKernelSelector(notebook, kernel, this._notebookKernelService, this._logService));
}
const text = `$(notebook-kernel-select) ${selected.label}`;
const tooltip = selected.description ?? selected.detail ?? selected.label;
const registration = this._statusbarService.addEntry(
const tooltip = kernel.description ?? kernel.detail ?? kernel.label;
this._kernelInfoElement.add(this._statusbarService.addEntry(
{
text,
ariaLabel: selected.label,
text: `$(notebook-kernel-select) ${kernel.label}`,
ariaLabel: kernel.label,
tooltip: isSuggested ? nls.localize('tooltop', "{0} (suggestion)", tooltip) : tooltip,
command: 'notebook.selectKernel',
},
'notebook.selectKernel',
nls.localize('notebook.info', "Notebook Kernel Info"),
StatusbarAlignment.RIGHT,
1000
);
const listener = selected.onDidChange(() => this._showKernelStatus(notebook));
this._kernelInfoElement.value = combinedDisposable(listener, registration);
10
));
this._kernelInfoElement.add(kernel.onDidChange(() => this._showKernelStatus(notebook)));
} else {
// multiple kernels -> show selection hint
const registration = this._statusbarService.addEntry(
this._kernelInfoElement.add(this._statusbarService.addEntry(
{
text: nls.localize('kernel.select.label', "Select Kernel"),
ariaLabel: nls.localize('kernel.select.label', "Select Kernel"),
@ -229,14 +288,13 @@ export class KernelStatus extends Disposable implements IWorkbenchContribution {
'notebook.selectKernel',
nls.localize('notebook.select', "Notebook Kernel Selection"),
StatusbarAlignment.RIGHT,
1000
);
this._kernelInfoElement.value = registration;
10
));
}
}
}
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(KernelStatus, LifecyclePhase.Ready);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(KernelStatus, LifecyclePhase.Restored);
export class ActiveCellStatus extends Disposable implements IWorkbenchContribution {
@ -304,4 +362,4 @@ export class ActiveCellStatus extends Disposable implements IWorkbenchContributi
}
}
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(ActiveCellStatus, LifecyclePhase.Ready);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(ActiveCellStatus, LifecyclePhase.Restored);

View file

@ -5,14 +5,19 @@
import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { localize } from 'vs/nls';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
import { ICellVisibilityChangeEvent, NotebookVisibleCellObserver } from 'vs/workbench/contrib/notebook/browser/contrib/statusBar/notebookVisibleCellObserver';
import { ICellViewModel, INotebookEditor, INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { EXECUTE_CELL_COMMAND_ID, ICellViewModel, INotebookEditor, INotebookEditorContribution, NOTEBOOK_CELL_EXECUTION_STATE, QUIT_EDIT_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { registerNotebookContribution } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
import { cellStatusIconError, cellStatusIconSuccess } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { CellStatusbarAlignment, INotebookCellStatusBarItem, NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellStatusbarAlignment, INotebookCellStatusBarItem, NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
export class NotebookStatusBarController extends Disposable implements INotebookEditorContribution {
static id: string = 'workbench.notebook.statusBar.exec';
@ -23,6 +28,7 @@ export class NotebookStatusBarController extends Disposable implements INotebook
constructor(
private readonly _notebookEditor: INotebookEditor,
@IInstantiationService private readonly _instantiationService: IInstantiationService
) {
super();
this._observer = this._register(new NotebookVisibleCellObserver(this._notebookEditor));
@ -45,8 +51,9 @@ export class NotebookStatusBarController extends Disposable implements INotebook
for (let newCell of e.added) {
const helpers = [
new ExecutionStateCellStatusBarHelper(vm, newCell),
new TimerCellStatusBarHelper(vm, newCell)
this._instantiationService.createInstance(ExecutionStateCellStatusBarHelper, vm, newCell),
this._instantiationService.createInstance(TimerCellStatusBarHelper, vm, newCell),
this._instantiationService.createInstance(KeybindingPlaceholderStatusBarHelper, vm, newCell),
];
this._visibleCells.set(newCell.handle, helpers);
}
@ -219,4 +226,80 @@ class TimerCellStatusBarHelper extends Disposable {
}
}
/**
* Shows a keybinding hint for the execute command
*/
class KeybindingPlaceholderStatusBarHelper extends Disposable {
private _currentItemIds: string[] = [];
private readonly _contextKeyService: IContextKeyService;
constructor(
private readonly _notebookViewModel: NotebookViewModel,
private readonly _cell: ICellViewModel,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IContextKeyService _contextKeyService: IContextKeyService,
) {
super();
// Create a fake ContextKeyService, and look up the keybindings within this context.
this._contextKeyService = _contextKeyService.createScoped(document.createElement('div'));
InputFocusedContext.bindTo(this._contextKeyService).set(true);
EditorContextKeys.editorTextFocus.bindTo(this._contextKeyService).set(true);
EditorContextKeys.focus.bindTo(this._contextKeyService).set(true);
EditorContextKeys.textInputFocus.bindTo(this._contextKeyService).set(true);
NOTEBOOK_CELL_EXECUTION_STATE.bindTo(this._contextKeyService).set('idle');
this._update();
this._register(this._cell.model.onDidChangeMetadata(() => this._update()));
}
private async _update() {
const items = this._getItemsForCell(this._cell);
if (Array.isArray(items)) {
this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items }]);
}
}
private _getItemsForCell(cell: ICellViewModel): INotebookCellStatusBarItem[] {
if (typeof cell.metadata?.runState !== 'undefined' || typeof cell.metadata?.lastRunSuccess !== 'undefined') {
return [];
}
let text: string;
if (cell.cellKind === CellKind.Code) {
const keybinding = this._keybindingService.lookupKeybinding(EXECUTE_CELL_COMMAND_ID, this._contextKeyService)?.getLabel();
if (!keybinding) {
return [];
}
text = localize('notebook.cell.status.codeExecuteTip', "Press {0} to execute cell", keybinding);
} else {
const keybinding = this._keybindingService.lookupKeybinding(QUIT_EDIT_CELL_COMMAND_ID, this._contextKeyService)?.getLabel();
if (!keybinding) {
return [];
}
text = localize('notebook.cell.status.markdownExecuteTip', "Press {0} to stop editing", keybinding);
}
const item = <INotebookCellStatusBarItem>{
text,
tooltip: text,
alignment: CellStatusbarAlignment.Left,
opacity: '0.7',
onlyShowWhenActive: true,
priority: 100
};
return [item];
}
override dispose() {
super.dispose();
this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items: [] }]);
}
}
registerNotebookContribution(NotebookStatusBarController.id, NotebookStatusBarController);

View file

@ -3,73 +3,23 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Disposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IModeService } from 'vs/editor/common/services/modeService';
import { localize } from 'vs/nls';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { CHANGE_CELL_LANGUAGE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { CellKind, CellStatusbarAlignment, INotebookCellStatusBarItem, INotebookCellStatusBarItemList, INotebookCellStatusBarItemProvider } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IModeService } from 'vs/editor/common/services/modeService';
import { CHANGE_CELL_LANGUAGE, EXECUTE_CELL_COMMAND_ID, QUIT_EDIT_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { NotebookSelector } from 'vs/workbench/contrib/notebook/common/notebookSelector';
class CellStatusBarPlaceholderProvider implements INotebookCellStatusBarItemProvider {
readonly selector: NotebookSelector = {
pattern: '**/*'
};
constructor(
@INotebookService private readonly _notebookService: INotebookService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
) { }
async provideCellStatusBarItems(uri: URI, index: number, token: CancellationToken): Promise<INotebookCellStatusBarItemList | undefined> {
const doc = this._notebookService.getNotebookTextModel(uri);
const cell = doc?.cells[index];
if (!cell || typeof cell.metadata.runState !== 'undefined' || typeof cell.metadata.lastRunSuccess !== 'undefined') {
return;
}
let text: string;
if (cell.cellKind === CellKind.Code) {
const keybinding = this._keybindingService.lookupKeybinding(EXECUTE_CELL_COMMAND_ID)?.getLabel();
if (!keybinding) {
return;
}
text = localize('notebook.cell.status.codeExecuteTip', "Press {0} to execute cell", keybinding);
} else {
const keybinding = this._keybindingService.lookupKeybinding(QUIT_EDIT_CELL_COMMAND_ID)?.getLabel();
if (!keybinding) {
return;
}
text = localize('notebook.cell.status.markdownExecuteTip', "Press {0} to stop editing", keybinding);
}
const item = <INotebookCellStatusBarItem>{
text,
tooltip: text,
alignment: CellStatusbarAlignment.Left,
opacity: '0.7',
onlyShowWhenActive: true
};
return {
items: [item]
};
}
}
class CellStatusBarLanguagePickerProvider implements INotebookCellStatusBarItemProvider {
readonly selector: NotebookSelector = {
pattern: '**/*'
};
readonly viewType = '*';
constructor(
@INotebookService private readonly _notebookService: INotebookService,
@ -83,7 +33,7 @@ class CellStatusBarLanguagePickerProvider implements INotebookCellStatusBarItemP
return;
}
const modeId = cell.cellKind === CellKind.Markdown ?
const modeId = cell.cellKind === CellKind.Markup ?
'markdown' :
(this._modeService.getModeIdForLanguageName(cell.language) || cell.language);
const text = this._modeService.getLanguageName(modeId) || this._modeService.getLanguageName('plaintext');
@ -107,7 +57,6 @@ class BuiltinCellStatusBarProviders extends Disposable {
super();
const builtinProviders = [
CellStatusBarPlaceholderProvider,
CellStatusBarLanguagePickerProvider,
];
builtinProviders.forEach(p => {

View file

@ -24,7 +24,7 @@ class NotebookUndoRedoContribution extends Disposable {
return editor.viewModel.undo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markdown && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
if (cell.cellKind === CellKind.Markup && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
cell.updateEditState(CellEditState.Editing, 'undo');
}
});
@ -43,7 +43,7 @@ class NotebookUndoRedoContribution extends Disposable {
return editor.viewModel.redo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markdown && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
if (cell.cellKind === CellKind.Markup && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
cell.updateEditState(CellEditState.Editing, 'redo');
}
});

View file

@ -12,8 +12,8 @@ suite('Notebook Undo/Redo', () => {
test('Basics', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
const modeService = accessor.get(IModeService);
@ -57,8 +57,8 @@ suite('Notebook Undo/Redo', () => {
test('Invalid replace count should not throw', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
const modeService = accessor.get(IModeService);
@ -81,8 +81,8 @@ suite('Notebook Undo/Redo', () => {
test('Replace beyond length', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
],
async (editor) => {
const viewModel = editor.viewModel;
@ -100,8 +100,8 @@ suite('Notebook Undo/Redo', () => {
test('Invalid replace count should not affect undo/redo', async function () {
await withTestNotebook(
[
['# header 1', 'markdown', CellKind.Markdown, [], {}],
['body', 'markdown', CellKind.Markdown, [], {}],
['# header 1', 'markdown', CellKind.Markup, [], {}],
['body', 'markdown', CellKind.Markup, [], {}],
],
async (editor, accessor) => {
const modeService = accessor.get(IModeService);

View file

@ -41,7 +41,7 @@ class NotebookViewportContribution extends Disposable implements INotebookEditor
cellRangesToIndexes(visibleRanges).forEach(index => {
const cell = this._notebookEditor.viewModel?.viewCells[index];
if (cell?.cellKind === CellKind.Markdown && cell?.getEditState() === CellEditState.Preview && !cell.metadata?.inputCollapsed) {
if (cell?.cellKind === CellKind.Markup && cell?.getEditState() === CellEditState.Preview && !cell.metadata?.inputCollapsed) {
this._notebookEditor.createMarkdownPreview(cell);
} else if (cell?.cellKind === CellKind.Code) {
const viewCell = (cell as CodeCellViewModel);

View file

@ -239,7 +239,7 @@ class CellContentProvider implements ITextModelContentProvider {
return cell.textBuffer.getLineContent(1).substr(0, limit);
}
};
const language = cell.cellKind === CellKind.Markdown ? this._modeService.create('markdown') : (cell.language ? this._modeService.create(cell.language) : this._modeService.createByFilepathOrFirstLine(resource, cell.textBuffer.getLineContent(1)));
const language = cell.cellKind === CellKind.Markup ? this._modeService.create('markdown') : (cell.language ? this._modeService.create(cell.language) : this._modeService.createByFilepathOrFirstLine(resource, cell.textBuffer.getLineContent(1)));
result = this._modelService.createModel(
bufferFactory,
language,

View file

@ -10,7 +10,6 @@ import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle'
import { URI } from 'vs/base/common/uri';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { INotebookCellStatusBarItemList, INotebookCellStatusBarItemProvider } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { score } from 'vs/workbench/contrib/notebook/common/notebookSelector';
export class NotebookCellStatusBarService extends Disposable implements INotebookCellStatusBarService {
@ -43,7 +42,7 @@ export class NotebookCellStatusBarService extends Disposable implements INoteboo
}
async getStatusBarItemsForCell(docUri: URI, cellIndex: number, viewType: string, token: CancellationToken): Promise<INotebookCellStatusBarItemList[]> {
const providers = this._providers.filter(p => score(p.selector, docUri, viewType) > 0);
const providers = this._providers.filter(p => p.viewType === viewType || p.viewType === '*');
return await Promise.all(providers.map(async p => {
try {
return await p.provideCellStatusBarItems(docUri, cellIndex, token) ?? { items: [] };

View file

@ -6,7 +6,7 @@
import * as nls from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellKind, INotebookKernel, INotebookTextModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, INotebookKernel, INotebookTextModel, NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust';
@ -24,20 +24,7 @@ export class NotebookEditorKernelManager extends Disposable {
getSelectedOrSuggestedKernel(notebook: INotebookTextModel): INotebookKernel | undefined {
// returns SELECTED or the ONLY available kernel
const info = this._notebookKernelService.getMatchingKernel(notebook);
if (info.selected) {
return info.selected;
}
if (info.all.length === 1) {
return info.all[0];
}
return undefined;
}
confirmSuggestedKernel(notebook: INotebookTextModel): void {
const kernel = this.getSelectedOrSuggestedKernel(notebook);
if (kernel) {
this._notebookKernelService.selectKernelForNotebook(kernel, notebook);
}
return info.selected ?? info.suggested;
}
async executeNotebookCells(notebook: INotebookTextModel, cells: Iterable<ICellViewModel>): Promise<void> {
@ -59,7 +46,7 @@ export class NotebookEditorKernelManager extends Disposable {
const cellHandles: number[] = [];
for (const cell of cells) {
if (cell.cellKind !== CellKind.Code) {
if (cell.cellKind !== CellKind.Code || cell.metadata?.runState === NotebookCellExecutionState.Pending || cell.metadata?.runState === NotebookCellExecutionState.Executing) {
continue;
}
if (!kernel.supportedLanguages.includes(cell.language)) {

View file

@ -619,7 +619,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const index = this.viewModel.getCellIndex(element);
if (index >= 0) {
return `Cell ${index}, ${element.cellKind === CellKind.Markdown ? 'markdown' : 'code'} cell`;
return `Cell ${index}, ${element.cellKind === CellKind.Markup ? 'markdown' : 'code'} cell`;
}
return '';
@ -1151,7 +1151,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const deletedCells: MarkdownCellViewModel[] = [];
for (const cell of cells) {
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
const mdCell = cell as MarkdownCellViewModel;
if (this.viewModel?.viewCells.find(cell => cell.handle === mdCell.handle)) {
// Cell has been folded but is still in model
@ -1224,7 +1224,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}));
}
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
store.add((cell as MarkdownCellViewModel).onDidHideInput(() => {
this.hideMarkdownPreviews([(cell as MarkdownCellViewModel)]);
}));
@ -1278,7 +1278,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
offset += (totalHeightCache ? totalHeightCache[i] : 0);
continue;
} else {
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
requests.push([cell, offset]);
}
}
@ -1298,7 +1298,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
visible: false,
})));
} else {
const initRequests = viewModel.viewCells.filter(cell => cell.cellKind === CellKind.Markdown).slice(0, 5).map(cell => ({ cellId: cell.id, cellHandle: cell.handle, content: cell.getText(), offset: -10000, visible: false }));
const initRequests = viewModel.viewCells.filter(cell => cell.cellKind === CellKind.Markup).slice(0, 5).map(cell => ({ cellId: cell.id, cellHandle: cell.handle, content: cell.getText(), offset: -10000, visible: false }));
await this._webview!.initializeMarkdown(initRequests);
// no cached view state so we are rendering the first viewport
@ -1307,7 +1307,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const offsetUpdateRequests: { id: string, top: number }[] = [];
const scrollBottom = Math.max(this._dimension?.height ?? 0, 1080);
for (const cell of viewModel.viewCells) {
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
offsetUpdateRequests.push({ id: cell.id, top: offset });
}
@ -1832,7 +1832,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const defaultLanguage = supportedLanguages[0] || 'plaintext';
if (cell?.cellKind === CellKind.Code) {
language = cell.language;
} else if (cell?.cellKind === CellKind.Markdown) {
} else if (cell?.cellKind === CellKind.Markup) {
const nearestCodeCellIndex = this._nearestCodeCellIndex(index);
if (nearestCodeCellIndex > -1) {
language = this.viewModel.cellAt(nearestCodeCellIndex)!.language;
@ -2010,13 +2010,13 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
let position = '';
switch (focusItem) {
case 'editor':
position = `the inner ${cell.cellKind === CellKind.Markdown ? 'markdown' : 'code'} editor is focused, press escape to focus the cell container`;
position = `the inner ${cell.cellKind === CellKind.Markup ? 'markdown' : 'code'} editor is focused, press escape to focus the cell container`;
break;
case 'output':
position = `the cell output is focused, press escape to focus the cell container`;
break;
case 'container':
position = `the ${cell.cellKind === CellKind.Markdown ? 'markdown preview' : 'cell container'} is focused, press enter to focus the inner ${cell.cellKind === CellKind.Markdown ? 'markdown' : 'code'} editor`;
position = `the ${cell.cellKind === CellKind.Markup ? 'markdown preview' : 'cell container'} is focused, press enter to focus the inner ${cell.cellKind === CellKind.Markup ? 'markdown' : 'code'} editor`;
break;
default:
break;

View file

@ -5,7 +5,7 @@
import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ICellViewModel, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL_COUNT, INotebookEditor, NOTEBOOK_KERNEL_SELECTED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { ICellViewModel, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL_COUNT, INotebookEditor, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
@ -16,6 +16,7 @@ export class NotebookEditorContextKeys {
private readonly _notebookKernelSelected: IContextKey<boolean>;
private readonly _interruptibleKernel: IContextKey<boolean>;
private readonly _someCellRunning: IContextKey<boolean>;
private _viewType!: IContextKey<string>;
private readonly _disposables = new DisposableStore();
private readonly _viewModelDisposables = new DisposableStore();
@ -30,6 +31,7 @@ export class NotebookEditorContextKeys {
this._notebookKernelSelected = NOTEBOOK_KERNEL_SELECTED.bindTo(contextKeyService);
this._interruptibleKernel = NOTEBOOK_INTERRUPTIBLE_KERNEL.bindTo(contextKeyService);
this._someCellRunning = NOTEBOOK_HAS_RUNNING_CELL.bindTo(contextKeyService);
this._viewType = NOTEBOOK_VIEW_TYPE.bindTo(contextKeyService);
this._disposables.add(_editor.onDidChangeModel(this._handleDidChangeModel, this));
this._disposables.add(_notebookKernelService.onDidAddKernel(this._updateKernelContext, this));
@ -43,6 +45,7 @@ export class NotebookEditorContextKeys {
this._notebookKernelCount.reset();
this._interruptibleKernel.reset();
this._someCellRunning.reset();
this._viewType.reset();
dispose(this._cellStateListeners);
this._cellStateListeners.length = 0;
}
@ -86,6 +89,7 @@ export class NotebookEditorContextKeys {
dispose(deletedCells);
});
}));
this._viewType.set(this._editor.viewModel.viewType);
}
private _updateKernelContext(): void {

View file

@ -191,7 +191,7 @@ export class NotebookKernelService implements INotebookKernelService {
const selectedId = this._notebookBindings.get(NotebookTextModelLikeId.str(notebook));
const selected = selectedId ? this._kernels.get(selectedId)?.kernel : undefined;
return { all, selected };
return { all, selected, suggested: all.length === 1 ? all[0] : undefined };
}
// default kernel for notebookType

View file

@ -177,7 +177,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
this._localDisposableStore.add(this.view.onMouseDblClick(() => {
const focus = this.getFocusedElements()[0];
if (focus && focus.cellKind === CellKind.Markdown && !focus.metadata?.inputCollapsed) {
if (focus && focus.cellKind === CellKind.Markup && !focus.metadata?.inputCollapsed) {
focus.updateEditState(CellEditState.Editing, 'dbclick');
focus.focusMode = CellFocusMode.Editor;
}

View file

@ -3,17 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NOTEBOOK_CELL_TYPE, NOTEBOOK_VIEW_TYPE, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_HAS_OUTPUTS, CellViewModelStateChangeEvent, CellEditState, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_FOCUSED, INotebookEditor, NOTEBOOK_CELL_EDITOR_FOCUSED, CellFocusMode, NotebookCellExecutionStateContext, NOTEBOOK_CELL_LINE_NUMBERS } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellEditState, CellFocusMode, CellViewModelStateChangeEvent, INotebookEditor, NotebookCellExecutionStateContext, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LINE_NUMBERS, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
import { MarkdownCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
export class CellContextKeyManager extends Disposable {
private cellType!: IContextKey<string>;
private viewType!: IContextKey<string>;
private cellEditable!: IContextKey<boolean>;
private cellFocused!: IContextKey<boolean>;
private cellEditorFocused!: IContextKey<boolean>;
@ -36,7 +35,6 @@ export class CellContextKeyManager extends Disposable {
this.contextKeyService.bufferChangeEvents(() => {
this.cellType = NOTEBOOK_CELL_TYPE.bindTo(this.contextKeyService);
this.viewType = NOTEBOOK_VIEW_TYPE.bindTo(this.contextKeyService);
this.cellEditable = NOTEBOOK_CELL_EDITABLE.bindTo(this.contextKeyService);
this.cellFocused = NOTEBOOK_CELL_FOCUSED.bindTo(this.contextKeyService);
this.cellEditorFocused = NOTEBOOK_CELL_EDITOR_FOCUSED.bindTo(this.contextKeyService);
@ -76,7 +74,6 @@ export class CellContextKeyManager extends Disposable {
this.updateForCollapseState();
this.updateForOutputs();
this.viewType.set(this.element.viewType);
this.cellLineNumbers.set(this.element.lineNumbers);
});
}

View file

@ -77,7 +77,7 @@ export class NotebookCellListDelegate extends Disposable implements IListVirtual
}
getTemplateId(element: CellViewModel): string {
if (element.cellKind === CellKind.Markdown) {
if (element.cellKind === CellKind.Markup) {
return MarkdownCellRenderer.TEMPLATE_ID;
} else {
return CodeCellRenderer.TEMPLATE_ID;

View file

@ -254,7 +254,7 @@ class CellStatusBarItem extends Disposable {
}
}));
} else {
this.container.tabIndex = -1;
this.container.removeAttribute('tabIndex');
}
this._currentItem = item;

View file

@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import * as DOM from 'vs/base/browser/dom';
import { raceCancellation } from 'vs/base/common/async';
import { disposableTimeout, raceCancellation } from 'vs/base/common/async';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@ -106,7 +106,9 @@ export class StatefulMarkdownCell extends Disposable {
private markdownContainer: HTMLElement;
private editorPart: HTMLElement;
private readonly localDisposables = new DisposableStore();
private readonly localDisposables = this._register(new DisposableStore());
private readonly focusSwitchDisposable = this._register(new MutableDisposable());
private readonly editorDisposables = this._register(new DisposableStore());
private foldingState: CellFoldingState;
private useRenderer: boolean = false;
private renderStrategy: IMarkdownRenderStrategy;
@ -236,7 +238,6 @@ export class StatefulMarkdownCell extends Disposable {
}
override dispose() {
this.localDisposables.dispose();
this.viewCell.detachTextEditor();
super.dispose();
}
@ -278,7 +279,7 @@ export class StatefulMarkdownCell extends Disposable {
if (this.editor && this.editor.hasModel()) {
editorHeight = this.editor.getContentHeight();
// not first time, we don't need to create editor or bind listeners
// not first time, we don't need to create editor
this.viewCell.attachTextEditor(this.editor);
this.focusEditorIfNeeded();
@ -289,7 +290,7 @@ export class StatefulMarkdownCell extends Disposable {
height: editorHeight
});
} else {
this.editor?.dispose();
this.editorDisposables.clear();
const width = this.viewCell.layoutInfo.editorWidth;
const lineNum = this.viewCell.lineCount;
@ -302,9 +303,9 @@ export class StatefulMarkdownCell extends Disposable {
const editorContextKeyService = this.contextKeyService.createScoped(this.templateData.editorPart);
EditorContextKeys.inCompositeEditor.bindTo(editorContextKeyService).set(true);
const editorInstaService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, editorContextKeyService]));
this._register(editorContextKeyService);
this.editorDisposables.add(editorContextKeyService);
this.editor = this._register(editorInstaService.createInstance(CodeEditorWidget, this.templateData.editorContainer, {
this.editor = this.editorDisposables.add(editorInstaService.createInstance(CodeEditorWidget, this.templateData.editorContainer, {
...this.editorOptions,
dimension: {
width: width,
@ -315,7 +316,7 @@ export class StatefulMarkdownCell extends Disposable {
this.templateData.currentEditor = this.editor;
const cts = new CancellationTokenSource();
this._register({ dispose() { cts.dispose(true); } });
this.editorDisposables.add({ dispose() { cts.dispose(true); } });
raceCancellation(this.viewCell.resolveTextModel(), cts.token).then(model => {
if (!model) {
return;
@ -423,6 +424,7 @@ export class StatefulMarkdownCell extends Disposable {
private bindEditorListeners(editor: CodeEditorWidget) {
this.localDisposables.clear();
this.focusSwitchDisposable.clear();
this.localDisposables.add(editor.onDidContentSizeChange(e => {
const viewLayout = editor.getLayoutInfo();
@ -461,9 +463,7 @@ export class StatefulMarkdownCell extends Disposable {
// users click the status bar empty space, which we will then focus the editor
// so we don't want to update the focus state too eagerly
if (document.activeElement?.contains(this.templateData.container)) {
setTimeout(() => {
updateFocusMode();
}, 300);
this.focusSwitchDisposable.value = disposableTimeout(() => updateFocusMode(), 300);
} else {
updateFocusMode();
}

View file

@ -19,7 +19,7 @@ import { CellKind, INotebookSearchOptions } from 'vs/workbench/contrib/notebook/
import { ITextModelService } from 'vs/editor/common/services/resolverService';
export class MarkdownCellViewModel extends BaseCellViewModel implements ICellViewModel {
readonly cellKind = CellKind.Markdown;
readonly cellKind = CellKind.Markup;
private _html: HTMLElement | null = null;
private _layoutInfo: MarkdownCellLayoutInfo;
@ -211,7 +211,7 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
}
getHTML(): HTMLElement | null {
if (this.cellKind === CellKind.Markdown) {
if (this.cellKind === CellKind.Markup) {
if (this._html) {
return this._html;
}

View file

@ -339,7 +339,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
this._layoutInfo = e.value;
this._viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
if (e.source.width || e.source.fontInfo) {
cell.layoutChange({ outerWidth: e.value.width, font: e.value.fontInfo });
}
@ -491,7 +491,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
}
this._viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markdown) {
if (cell.cellKind === CellKind.Markup) {
cell.triggerfoldingStateChange();
}
});

View file

@ -22,11 +22,10 @@ import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { IEditorInput, IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { NotebookSelector } from 'vs/workbench/contrib/notebook/common/notebookSelector';
import { IWorkingCopyBackupMeta } from 'vs/workbench/services/workingCopy/common/workingCopy';
export enum CellKind {
Markdown = 1,
Markup = 1,
Code = 2
}
@ -813,7 +812,7 @@ export interface INotebookKernel {
}
export interface INotebookCellStatusBarItemProvider {
selector: NotebookSelector;
viewType: string;
onDidChangeStatusBarItems?: Event<void>;
provideCellStatusBarItems(uri: URI, index: number, token: CancellationToken): Promise<INotebookCellStatusBarItemList | undefined>;
}

View file

@ -17,6 +17,7 @@ export interface INotebookKernelBindEvent {
export interface INotebookKernelMatchResult {
readonly selected: INotebookKernel | undefined;
readonly suggested: INotebookKernel | undefined;
readonly all: INotebookKernel[];
}

View file

@ -1,31 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IRelativePattern } from 'vs/base/common/glob';
import { URI } from 'vs/base/common/uri';
import * as ls from 'vs/editor/common/modes/languageSelector';
export interface NotebookFilter {
readonly viewType?: string;
readonly scheme?: string;
readonly pattern?: string | IRelativePattern;
}
export type NotebookSelector = NotebookFilter | string | ReadonlyArray<NotebookFilter | string>;
function _asLanguageSelector(s: NotebookSelector): ls.LanguageFilter | ls.LanguageFilter[] {
if (Array.isArray(s)) {
return <ls.LanguageFilter[]>s.map(_asLanguageSelector);
} else if (typeof s === 'string') {
return { language: s };
} else {
const { viewType, scheme, pattern } = <NotebookFilter>s;
return { language: viewType, scheme: scheme, pattern: pattern };
}
}
export function score(selector: NotebookSelector, candidateUri: URI, candidateViewType: string): number {
return ls.score(_asLanguageSelector(selector), candidateUri, candidateViewType, true);
}

View file

@ -28,8 +28,8 @@ suite('notebookBrowser', () => {
test('none code', function () {
const cells = [
{ cellKind: CellKind.Markdown },
{ cellKind: CellKind.Markdown },
{ cellKind: CellKind.Markup },
{ cellKind: CellKind.Markup },
];
assert.deepStrictEqual(getRanges(cells as ICellViewModel[], predicate), []);
});
@ -37,7 +37,7 @@ suite('notebookBrowser', () => {
test('start code', function () {
const cells = [
{ cellKind: CellKind.Code },
{ cellKind: CellKind.Markdown },
{ cellKind: CellKind.Markup },
];
assert.deepStrictEqual(getRanges(cells as ICellViewModel[], predicate), [{ start: 0, end: 1 }]);
});
@ -46,10 +46,10 @@ suite('notebookBrowser', () => {
const cells = [
{ cellKind: CellKind.Code },
{ cellKind: CellKind.Code },
{ cellKind: CellKind.Markdown },
{ cellKind: CellKind.Markup },
{ cellKind: CellKind.Code },
{ cellKind: CellKind.Markdown },
{ cellKind: CellKind.Markdown },
{ cellKind: CellKind.Markup },
{ cellKind: CellKind.Markup },
{ cellKind: CellKind.Code },
];
assert.deepStrictEqual(getRanges(cells as ICellViewModel[], predicate), [{ start: 0, end: 2 }, { start: 3, end: 4 }, { start: 6, end: 7 }]);

View file

@ -14,11 +14,11 @@ suite('NotebookCellList', () => {
test('revealElementsInView: reveal fully visible cell should not scroll', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
const viewModel = editor.viewModel;
@ -59,11 +59,11 @@ suite('NotebookCellList', () => {
test('revealElementsInView: reveal partially visible cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
const viewModel = editor.viewModel;
@ -101,11 +101,11 @@ suite('NotebookCellList', () => {
test('revealElementsInView: reveal cell out of viewport', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
const viewModel = editor.viewModel;
@ -136,11 +136,11 @@ suite('NotebookCellList', () => {
test('updateElementHeight', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
const viewModel = editor.viewModel;
@ -176,11 +176,11 @@ suite('NotebookCellList', () => {
test('updateElementHeight with anchor #121723', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
// await new Promise(c => setTimeout(c, 3000));
@ -229,11 +229,11 @@ suite('NotebookCellList', () => {
test('updateElementHeight with anchor #121723: focus element out of viewport', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
// await new Promise(c => setTimeout(c, 3000));
@ -265,11 +265,11 @@ suite('NotebookCellList', () => {
test('updateElementHeight of cells out of viewport should not trigger scroll #121140', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
async (editor) => {
const viewModel = editor.viewModel;

View file

@ -168,13 +168,13 @@ suite('NotebookCommon', () => {
test('diff markdown', async () => {
await withTestNotebookDiffModel([
['This is a test notebook with only markdown cells', 'markdown', CellKind.Markdown, [], {}],
['Lorem ipsum dolor sit amet', 'markdown', CellKind.Markdown, [], {}],
['In other news', 'markdown', CellKind.Markdown, [], {}],
['This is a test notebook with only markdown cells', 'markdown', CellKind.Markup, [], {}],
['Lorem ipsum dolor sit amet', 'markdown', CellKind.Markup, [], {}],
['In other news', 'markdown', CellKind.Markup, [], {}],
], [
['This is a test notebook with markdown cells only', 'markdown', CellKind.Markdown, [], {}],
['Lorem ipsum dolor sit amet', 'markdown', CellKind.Markdown, [], {}],
['In the news', 'markdown', CellKind.Markdown, [], {}],
['This is a test notebook with markdown cells only', 'markdown', CellKind.Markup, [], {}],
['Lorem ipsum dolor sit amet', 'markdown', CellKind.Markup, [], {}],
['In the news', 'markdown', CellKind.Markup, [], {}],
], (model, accessor) => {
const diff = new LcsDiff(new CellSequence(model.original.notebook), new CellSequence(model.modified.notebook));
const diffResult = diff.ComputeDiff(false);
@ -270,12 +270,12 @@ suite('NotebookCommon', () => {
test('LCS', async () => {
await withTestNotebookDiffModel([
['# Description', 'markdown', CellKind.Markdown, [], { custom: { metadata: {} } }],
['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }],
['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }],
['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }],
['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }]
], [
['# Description', 'markdown', CellKind.Markdown, [], { custom: { metadata: {} } }],
['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }],
['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }],
['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }],
['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }]
@ -303,7 +303,7 @@ suite('NotebookCommon', () => {
test('LCS 2', async () => {
await withTestNotebookDiffModel([
['# Description', 'markdown', CellKind.Markdown, [], { custom: { metadata: {} } }],
['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }],
['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }],
['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }],
['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }],
@ -311,7 +311,7 @@ suite('NotebookCommon', () => {
['x', 'javascript', CellKind.Code, [], {}],
['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '5' }] }], {}],
], [
['# Description', 'markdown', CellKind.Markdown, [], { custom: { metadata: {} } }],
['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }],
['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }],
['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }],
['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }],

View file

@ -17,9 +17,9 @@ suite('ListViewInfoAccessor', () => {
test('basics', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3;', 'javascript', CellKind.Code, [], {}]
],

View file

@ -94,11 +94,11 @@ suite('NotebookCellList focus/selection', () => {
test('notebook cell list focus/selection from UI', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
(editor) => {
const viewModel = editor.viewModel;
@ -130,11 +130,11 @@ suite('NotebookCellList focus/selection', () => {
test('notebook cell list focus/selection with folding regions', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
(editor) => {
const viewModel = editor.viewModel;
@ -175,12 +175,12 @@ suite('NotebookCellList focus/selection', () => {
test('notebook cell list focus/selection with folding regions and applyEdits', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['var c = 3', 'javascript', CellKind.Markdown, [], {}],
['# header d', 'markdown', CellKind.Markdown, [], {}],
['var c = 3', 'javascript', CellKind.Markup, [], {}],
['# header d', 'markdown', CellKind.Markup, [], {}],
['var e = 4;', 'javascript', CellKind.Code, [], {}],
],
(editor) => {
@ -229,11 +229,11 @@ suite('NotebookCellList focus/selection', () => {
test('notebook cell list getModelIndex', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['var b = 2;', 'javascript', CellKind.Code, [], {}],
['# header c', 'markdown', CellKind.Markdown, [], {}]
['# header c', 'markdown', CellKind.Markup, [], {}]
],
(editor) => {
const viewModel = editor.viewModel;
@ -259,7 +259,7 @@ suite('NotebookCellList focus/selection', () => {
test('notebook validate range', async () => {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}]
],
(editor) => {
@ -279,7 +279,7 @@ suite('NotebookCellList focus/selection', () => {
test('notebook updateSelectionState', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}]
],
(editor) => {
@ -292,7 +292,7 @@ suite('NotebookCellList focus/selection', () => {
test('notebook cell selection w/ cell deletion', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}]
],
(editor) => {

View file

@ -333,14 +333,14 @@ suite('NotebookViewModel API', () => {
test('#115432, get nearest code cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}],
['# header b', 'markdown', CellKind.Markup, [], {}],
['b = 2;', 'python', CellKind.Code, [], {}],
['var c = 3', 'javascript', CellKind.Code, [], {}],
['# header d', 'markdown', CellKind.Markdown, [], {}],
['# header d', 'markdown', CellKind.Markup, [], {}],
['var e = 4;', 'TypeScript', CellKind.Code, [], {}],
['# header f', 'markdown', CellKind.Markdown, [], {}]
['# header f', 'markdown', CellKind.Markup, [], {}]
],
(editor) => {
const viewModel = editor.viewModel;
@ -357,9 +357,9 @@ suite('NotebookViewModel API', () => {
test('#108464, get nearest code cell', async function () {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}]
['# header b', 'markdown', CellKind.Markup, [], {}]
],
(editor) => {
const viewModel = editor.viewModel;
@ -371,9 +371,9 @@ suite('NotebookViewModel API', () => {
test('getCells', async () => {
await withTestNotebook(
[
['# header a', 'markdown', CellKind.Markdown, [], {}],
['# header a', 'markdown', CellKind.Markup, [], {}],
['var b = 1;', 'javascript', CellKind.Code, [], {}],
['# header b', 'markdown', CellKind.Markdown, [], {}]
['# header b', 'markdown', CellKind.Markup, [], {}]
],
(editor) => {
const viewModel = editor.viewModel;

View file

@ -69,7 +69,7 @@ suite('NotebookCell#Document', function () {
source: ['### Heading'],
eol: '\n',
language: 'markdown',
cellKind: CellKind.Markdown,
cellKind: CellKind.Markup,
outputs: [],
}, {
handle: 1,
@ -325,7 +325,7 @@ suite('NotebookCell#Document', function () {
source: ['### Heading'],
eol: '\n',
language: 'markdown',
cellKind: CellKind.Markdown,
cellKind: CellKind.Markup,
outputs: [],
}, {
handle: 4,

View file

@ -65,7 +65,7 @@ suite('NotebookConcatDocument', function () {
source: ['### Heading'],
eol: '\n',
language: 'markdown',
cellKind: CellKind.Markdown,
cellKind: CellKind.Markup,
outputs: [],
}],
versionId: 0

View file

@ -84,7 +84,7 @@ suite('NotebookKernel', function () {
source: ['### Heading'],
eol: '\n',
language: 'markdown',
cellKind: CellKind.Markdown,
cellKind: CellKind.Markup,
outputs: [],
}, {
handle: 1,