mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
@@ -18,6 +18,7 @@ import { QueryPlanInput } from 'sql/parts/queryPlan/queryPlanInput';
|
|||||||
import { NotebookInput, NotebookInputModel, NotebookInputValidator } from 'sql/parts/notebook/notebookInput';
|
import { NotebookInput, NotebookInputModel, NotebookInputValidator } from 'sql/parts/notebook/notebookInput';
|
||||||
import { DEFAULT_NOTEBOOK_PROVIDER, INotebookService } from 'sql/services/notebook/notebookService';
|
import { DEFAULT_NOTEBOOK_PROVIDER, INotebookService } from 'sql/services/notebook/notebookService';
|
||||||
import { getProviderForFileName } from 'sql/parts/notebook/notebookUtils';
|
import { getProviderForFileName } from 'sql/parts/notebook/notebookUtils';
|
||||||
|
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ export const untitledFilePrefix = 'SQLQuery';
|
|||||||
|
|
||||||
// mode identifier for SQL mode
|
// mode identifier for SQL mode
|
||||||
export const sqlModeId = 'sql';
|
export const sqlModeId = 'sql';
|
||||||
|
export const notebookModeId = 'notebook';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified input is supported by one our custom input types, and if so convert it
|
* Checks if the specified input is supported by one our custom input types, and if so convert it
|
||||||
@@ -95,6 +97,13 @@ export function getSupportedInputResource(input: IEditorInput): URI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input instanceof ResourceEditorInput) {
|
||||||
|
let resourceCast: ResourceEditorInput = <ResourceEditorInput>input;
|
||||||
|
if (resourceCast) {
|
||||||
|
return resourceCast.getResource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +161,6 @@ function getQueryPlanEditorUri(input: EditorInput): URI {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If input is a supported notebook editor file (.ipynb), return it's URI. Otherwise return undefined.
|
* If input is a supported notebook editor file (.ipynb), return it's URI. Otherwise return undefined.
|
||||||
* @param input The EditorInput to get the URI of.
|
* @param input The EditorInput to get the URI of.
|
||||||
@@ -162,18 +170,15 @@ function getNotebookEditorUri(input: EditorInput, instantiationService: IInstant
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If this editor is not already of type notebook input
|
// If this editor is not already of type notebook input
|
||||||
if (!(input instanceof NotebookInput)) {
|
if (!(input instanceof NotebookInput)) {
|
||||||
let uri: URI = getSupportedInputResource(input);
|
let uri: URI = getSupportedInputResource(input);
|
||||||
if (uri) {
|
if (uri) {
|
||||||
if (hasFileExtension(getNotebookFileExtensions(instantiationService), input, false)) {
|
if (hasFileExtension(getNotebookFileExtensions(instantiationService), input, false) || hasNotebookFileMode(input)) {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +188,18 @@ function getNotebookFileExtensions(instantiationService: IInstantiationService):
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given EditorInput is set to either undefined or notebook mode
|
||||||
|
* @param input The EditorInput to check the mode of
|
||||||
|
*/
|
||||||
|
function hasNotebookFileMode(input: EditorInput): boolean {
|
||||||
|
if (input instanceof UntitledEditorInput) {
|
||||||
|
let untitledCast: UntitledEditorInput = <UntitledEditorInput>input;
|
||||||
|
return (untitledCast && untitledCast.getModeId() === notebookModeId);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function withService<TService, TResult>(instantiationService: IInstantiationService, serviceId: ServiceIdentifier<TService>, action: (service: TService) => TResult, ): TResult {
|
function withService<TService, TResult>(instantiationService: IInstantiationService, serviceId: ServiceIdentifier<TService>, action: (service: TService) => TResult, ): TResult {
|
||||||
return instantiationService.invokeFunction(accessor => {
|
return instantiationService.invokeFunction(accessor => {
|
||||||
let service = accessor.get(serviceId);
|
let service = accessor.get(serviceId);
|
||||||
@@ -225,3 +242,17 @@ function hasFileExtension(extensions: string[], input: EditorInput, checkUntitle
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns file mode - notebookModeId or sqlModeId
|
||||||
|
export function getFileMode(instantiationService: IInstantiationService, resource: URI): string {
|
||||||
|
if (!resource) {
|
||||||
|
return sqlModeId;
|
||||||
|
}
|
||||||
|
return withService<INotebookService, string>(instantiationService, INotebookService, notebookService => {
|
||||||
|
for (const editor of notebookService.listNotebookEditors()) {
|
||||||
|
if (editor.notebookParams.notebookUri === resource) {
|
||||||
|
return notebookModeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlModeId;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -46,6 +46,9 @@ import { KernelsDropdown, AttachToDropdown, AddCellAction, TrustedAction, SaveNo
|
|||||||
import { IObjectExplorerService } from 'sql/parts/objectExplorer/common/objectExplorerService';
|
import { IObjectExplorerService } from 'sql/parts/objectExplorer/common/objectExplorerService';
|
||||||
import * as TaskUtilities from 'sql/workbench/common/taskUtilities';
|
import * as TaskUtilities from 'sql/workbench/common/taskUtilities';
|
||||||
import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
|
import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||||
|
import { IResourceInput } from 'vs/platform/editor/common/editor';
|
||||||
|
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
||||||
|
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
|
||||||
|
|
||||||
export const NOTEBOOK_SELECTOR: string = 'notebook-component';
|
export const NOTEBOOK_SELECTOR: string = 'notebook-component';
|
||||||
|
|
||||||
@@ -89,7 +92,9 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
@Inject(IKeybindingService) private keybindingService: IKeybindingService,
|
@Inject(IKeybindingService) private keybindingService: IKeybindingService,
|
||||||
@Inject(IHistoryService) private historyService: IHistoryService,
|
@Inject(IHistoryService) private historyService: IHistoryService,
|
||||||
@Inject(IWindowService) private windowService: IWindowService,
|
@Inject(IWindowService) private windowService: IWindowService,
|
||||||
@Inject(IViewletService) private viewletService: IViewletService
|
@Inject(IViewletService) private viewletService: IViewletService,
|
||||||
|
@Inject(IUntitledEditorService) private untitledEditorService: IUntitledEditorService,
|
||||||
|
@Inject(IEditorGroupsService) private editorGroupService: IEditorGroupsService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.updateProfile();
|
this.updateProfile();
|
||||||
@@ -403,7 +408,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
this.saveNotebook().then(result => {
|
this.saveNotebook().then(result => {
|
||||||
if(result)
|
if(result)
|
||||||
{
|
{
|
||||||
this.notebookService.renameNotebookEditor(resource, target, this);
|
return this.replaceUntitledNotebookEditor(resource, target);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
@@ -416,6 +421,27 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replaces untitled notebook editor with the saved file name
|
||||||
|
private async replaceUntitledNotebookEditor(resource: URI, target: URI): Promise<boolean> {
|
||||||
|
let encodingOfSource = this.untitledEditorService.getEncoding(resource);
|
||||||
|
const replacement: IResourceInput = {
|
||||||
|
resource: target,
|
||||||
|
encoding: encodingOfSource,
|
||||||
|
options: {
|
||||||
|
pinned: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return TPromise.join(this.editorGroupService.groups.map(g =>
|
||||||
|
this.editorService.replaceEditors([{
|
||||||
|
editor: { resource },
|
||||||
|
replacement
|
||||||
|
}], g))).then(() => {
|
||||||
|
this.notebookService.renameNotebookEditor(resource, target, this);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async saveNotebook(): Promise<boolean> {
|
private async saveNotebook(): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
let saved = await this._model.saveModel();
|
let saved = await this._model.saveModel();
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ import { coalesce } from 'vs/base/common/arrays';
|
|||||||
import { isCodeEditor, isDiffEditor, ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
|
import { isCodeEditor, isDiffEditor, ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
|
||||||
import { IEditorGroupView, IEditorOpeningEvent, EditorGroupsServiceImpl, EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
|
import { IEditorGroupView, IEditorOpeningEvent, EditorGroupsServiceImpl, EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
|
||||||
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
|
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
|
||||||
import { convertEditorInput } from 'sql/parts/common/customInputConverter';
|
//{{ SQL CARBON EDIT }}
|
||||||
|
import { convertEditorInput, getFileMode } from 'sql/parts/common/customInputConverter';
|
||||||
|
|
||||||
type ICachedEditorInput = ResourceEditorInput | IFileEditorInput | DataUriEditorInput;
|
type ICachedEditorInput = ResourceEditorInput | IFileEditorInput | DataUriEditorInput;
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
|
|||||||
@IInstantiationService private instantiationService: IInstantiationService,
|
@IInstantiationService private instantiationService: IInstantiationService,
|
||||||
@IUriDisplayService private uriDisplayService: IUriDisplayService,
|
@IUriDisplayService private uriDisplayService: IUriDisplayService,
|
||||||
@IFileService private fileService: IFileService,
|
@IFileService private fileService: IFileService,
|
||||||
@IConfigurationService private configurationService: IConfigurationService
|
@IConfigurationService private configurationService: IConfigurationService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -495,9 +496,11 @@ export class EditorService extends Disposable implements EditorServiceImpl {
|
|||||||
const untitledInput = <IUntitledResourceInput>input;
|
const untitledInput = <IUntitledResourceInput>input;
|
||||||
if (!untitledInput.resource || typeof untitledInput.filePath === 'string' || (untitledInput.resource instanceof URI && untitledInput.resource.scheme === Schemas.untitled)) {
|
if (!untitledInput.resource || typeof untitledInput.filePath === 'string' || (untitledInput.resource instanceof URI && untitledInput.resource.scheme === Schemas.untitled)) {
|
||||||
// {{SQL CARBON EDIT}}
|
// {{SQL CARBON EDIT}}
|
||||||
|
|
||||||
|
let mode: string = getFileMode( this.instantiationService, untitledInput.resource);
|
||||||
return convertEditorInput(this.untitledEditorService.createOrGet(
|
return convertEditorInput(this.untitledEditorService.createOrGet(
|
||||||
untitledInput.filePath ? URI.file(untitledInput.filePath) : untitledInput.resource,
|
untitledInput.filePath ? URI.file(untitledInput.filePath) : untitledInput.resource,
|
||||||
'sql',
|
mode,
|
||||||
untitledInput.contents,
|
untitledInput.contents,
|
||||||
untitledInput.encoding
|
untitledInput.encoding
|
||||||
), undefined, this.instantiationService);
|
), undefined, this.instantiationService);
|
||||||
|
|||||||
Reference in New Issue
Block a user