Merge pull request #192839 from microsoft/rebornix/successful-xerinae

Enable editor hint for notebook cell editor.
This commit is contained in:
Peng Lyu 2023-09-12 11:10:49 -07:00 committed by GitHub
commit 8f12a39b62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 13 deletions

View file

@ -53,22 +53,22 @@ Registry.as<IConfigurationMigrationRegistry>(Extensions.ConfigurationMigration)
])
}]);
const emptyTextEditorHintSetting = 'workbench.editor.empty.hint';
export const emptyTextEditorHintSetting = 'workbench.editor.empty.hint';
export class EmptyTextEditorHintContribution implements IEditorContribution {
public static readonly ID = 'editor.contrib.emptyTextEditorHint';
private toDispose: IDisposable[];
protected toDispose: IDisposable[];
private textHintContentWidget: EmptyTextEditorHintContentWidget | undefined;
constructor(
private readonly editor: ICodeEditor,
protected readonly editor: ICodeEditor,
@IEditorGroupsService private readonly editorGroupsService: IEditorGroupsService,
@ICommandService private readonly commandService: ICommandService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IConfigurationService protected readonly configurationService: IConfigurationService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IInlineChatSessionService inlineChatSessionService: IInlineChatSessionService,
@IInlineChatService private readonly inlineChatService: IInlineChatService,
@IInlineChatService protected readonly inlineChatService: IInlineChatService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IProductService private readonly productService: IProductService,
) {
@ -92,7 +92,7 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
}));
}
private _shouldRenderHint() {
protected _shouldRenderHint() {
const configValue = this.configurationService.getValue(emptyTextEditorHintSetting);
if (configValue === 'hidden') {
return false;
@ -113,17 +113,12 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
return false;
}
const isNotebookCell = model?.uri.scheme === Schemas.vscodeNotebookCell;
if (isNotebookCell) {
return false;
}
const inlineChatProviders = [...this.inlineChatService.getAllProvider()];
const shouldRenderDefaultHint = model?.uri.scheme === Schemas.untitled && languageId === PLAINTEXT_LANGUAGE_ID && !inlineChatProviders.length;
return inlineChatProviders.length > 0 || shouldRenderDefaultHint;
}
private update(): void {
protected update(): void {
this.textHintContentWidget?.dispose();
if (this._shouldRenderHint()) {

View file

@ -0,0 +1,87 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Schemas } from 'vs/base/common/network';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorContributionInstantiation, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IProductService } from 'vs/platform/product/common/productService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { EmptyTextEditorHintContribution } from 'vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint';
import { IInlineChatSessionService } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession';
import { IInlineChatService } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
export class EmptyCellEditorHintContribution extends EmptyTextEditorHintContribution {
public static readonly CONTRIB_ID = 'notebook.editor.contrib.emptyCellEditorHint';
constructor(
editor: ICodeEditor,
@IEditorService private readonly _editorService: IEditorService,
@IEditorGroupsService editorGroupsService: IEditorGroupsService,
@ICommandService commandService: ICommandService,
@IConfigurationService configurationService: IConfigurationService,
@IKeybindingService keybindingService: IKeybindingService,
@IInlineChatSessionService inlineChatSessionService: IInlineChatSessionService,
@IInlineChatService inlineChatService: IInlineChatService,
@ITelemetryService telemetryService: ITelemetryService,
@IProductService productService: IProductService
) {
super(
editor,
editorGroupsService,
commandService,
configurationService,
keybindingService,
inlineChatSessionService,
inlineChatService,
telemetryService,
productService
);
const activeEditor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (!activeEditor) {
return;
}
this.toDispose.push(activeEditor.onDidChangeActiveCell(() => this.update()));
}
protected override _shouldRenderHint(): boolean {
const shouldRenderHint = super._shouldRenderHint();
if (!shouldRenderHint) {
return false;
}
const model = this.editor.getModel();
if (!model) {
return false;
}
const isNotebookCell = model?.uri.scheme === Schemas.vscodeNotebookCell;
if (!isNotebookCell) {
return false;
}
const activeEditor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (!activeEditor) {
return false;
}
const activeCell = activeEditor.getActiveCell();
if (activeCell?.uri.fragment !== model.uri.fragment) {
return false;
}
return true;
}
}
registerEditorContribution(EmptyCellEditorHintContribution.CONTRIB_ID, EmptyCellEditorHintContribution, EditorContributionInstantiation.Eager); // eager because it needs to render a help message

View file

@ -0,0 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.monaco-workbench .notebookOverlay .monaco-editor .contentWidgets .empty-editor-hint {
cursor: auto;
}

View file

@ -69,6 +69,7 @@ import 'vs/workbench/contrib/notebook/browser/controller/apiActions';
import 'vs/workbench/contrib/notebook/browser/controller/foldingController';
// Editor Contribution
import 'vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint';
import 'vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard';
import 'vs/workbench/contrib/notebook/browser/contrib/find/notebookFind';
import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting';

View file

@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/notebook';
import 'vs/css!./media/notebookCellEditorHint';
import 'vs/css!./media/notebookCellInsertToolbar';
import 'vs/css!./media/notebookCellStatusBar';
import 'vs/css!./media/notebookCellTitleToolbar';
@ -112,7 +113,8 @@ export function getDefaultNotebookCreationOptions(): INotebookEditorCreationOpti
'editor.contrib.testingOutputPeek',
'editor.contrib.testingDecorations',
'store.contrib.stickyScrollController',
'editor.contrib.findController'
'editor.contrib.findController',
'editor.contrib.emptyTextEditorHint'
];
const contributions = EditorExtensionsRegistry.getEditorContributions().filter(c => skipContributions.indexOf(c.id) === -1);