Adding Rendered Notebook Diff Option (#14860)

* First attempt nb diff preview

* First attempt nb diff preview

* Simplify everything

* Interim scroll one way

* Double scroll

* Add setting

* Add tests

* Add comment

* Fix tests

* first round PR comments

* Ensure scrollable portion has scrollbar in diff

* Fix sqllint errors, register events

* Fix scrolling, readonly
This commit is contained in:
Chris LaFreniere
2021-04-02 14:49:52 -07:00
committed by GitHub
parent e7be1daf5c
commit 0d3112ef35
9 changed files with 186 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ import { ILanguageAssociationRegistry, Extensions as LanguageAssociationExtensio
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
import { isThenable } from 'vs/base/common/async';
import { withNullAsUndefined } from 'vs/base/common/types';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
const languageAssociationRegistry = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
@@ -41,7 +42,7 @@ export class EditorReplacementContribution implements IWorkbenchContribution {
// return undefined;
// }
if (!(editor instanceof FileEditorInput) && !(editor instanceof UntitledTextEditorInput)) {
if (!(editor instanceof FileEditorInput) && !(editor instanceof UntitledTextEditorInput) && !(editor instanceof DiffEditorInput)) {
return undefined;
}
@@ -57,13 +58,14 @@ export class EditorReplacementContribution implements IWorkbenchContribution {
}
if (!language) {
// just use the extension
language = path.extname(editor.resource.toString()).slice(1); // remove the .
// Attempt to use extension or extension of modified input (if in diff editor)
// remove the .
language = editor instanceof DiffEditorInput ? path.extname(editor.modifiedInput.resource.toString()).slice(1) : path.extname(editor.resource.toString()).slice(1);
}
if (!language) {
const defaultInputCreator = languageAssociationRegistry.defaultAssociation;
if (defaultInputCreator) {
if (defaultInputCreator && !(editor instanceof DiffEditorInput)) {
editor.setMode(defaultInputCreator[0]);
const newInput = defaultInputCreator[1].convertInput(editor);
if (newInput) {

View File

@@ -32,6 +32,10 @@ import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/commo
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
import { TestQueryEditorService } from 'sql/workbench/services/queryEditor/test/common/testQueryEditorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { DiffNotebookInput } from 'sql/workbench/contrib/notebook/browser/models/diffNotebookInput';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
const languageAssociations = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
@@ -47,6 +51,9 @@ suite('Editor Replacer Contribution', () => {
const editorService = new MockEditorService(instantiationService);
instantiationService.stub(IEditorService, editorService);
instantiationService.stub(IQueryEditorService, instantiationService.createInstance(TestQueryEditorService));
const configService = new TestConfigurationService();
configService.setUserConfiguration('notebook', { showRenderedNotebookInDiffEditor: true });
instantiationService.stub(IConfigurationService, configService);
instantiationService.invokeFunction(accessor => {
languageAssociations.start(accessor);
});
@@ -126,6 +133,34 @@ suite('Editor Replacer Contribution', () => {
contrib.dispose();
});
test('does replace notebook file diff input using input extension ipynb', async () => {
const instantiationService = workbenchInstantiationService();
const editorService = new MockEditorService(instantiationService);
instantiationService.stub(IEditorService, editorService);
const contrib = instantiationService.createInstance(EditorReplacementContribution);
const input = instantiationService.createInstance(FileEditorInput, URI.file('/test/file.ipynb'), undefined, undefined, undefined, undefined, undefined);
const input2 = instantiationService.createInstance(FileEditorInput, URI.file('/test/file2.ipynb'), undefined, undefined, undefined, undefined, undefined);
const diffInput = instantiationService.createInstance(DiffEditorInput, undefined, undefined, input, input2, undefined);
const response = editorService.fireOpenEditor(diffInput, undefined, undefined as IEditorGroup, OpenEditorContext.NEW_EDITOR);
const newinput = await response.override; // our test service returns this so we are fine to cast this
assert(newinput instanceof DiffNotebookInput);
contrib.dispose();
});
test('does not replace sql file diff input using input extension sql', async () => {
const instantiationService = workbenchInstantiationService();
const editorService = new MockEditorService(instantiationService);
instantiationService.stub(IEditorService, editorService);
const contrib = instantiationService.createInstance(EditorReplacementContribution);
const input = instantiationService.createInstance(FileEditorInput, URI.file('/test/file.sql'), undefined, undefined, undefined, undefined, undefined);
const input2 = instantiationService.createInstance(FileEditorInput, URI.file('/test/file2.sql'), undefined, undefined, undefined, undefined, undefined);
const diffInput = instantiationService.createInstance(DiffEditorInput, undefined, undefined, input, input2, undefined);
const response = editorService.fireOpenEditor(diffInput, undefined, undefined as IEditorGroup, OpenEditorContext.NEW_EDITOR);
const newinput = await response.override;
assert(newinput instanceof DiffEditorInput);
contrib.dispose();
});
test('does replace file input using default mode', async function () {
const instantiationService = workbenchInstantiationService();
const editorService = new MockEditorService(instantiationService);