mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
1133: Notebook file registration changes (#2969)
* 1133: Notebook file registration changes * File registration stuff
This commit is contained in:
@@ -12,6 +12,7 @@ import { QueryInput } from 'sql/parts/query/common/queryInput';
|
|||||||
import URI from 'vs/base/common/uri';
|
import URI from 'vs/base/common/uri';
|
||||||
import { IQueryEditorOptions } from 'sql/parts/query/common/queryEditorService';
|
import { IQueryEditorOptions } from 'sql/parts/query/common/queryEditorService';
|
||||||
import { QueryPlanInput } from 'sql/parts/queryPlan/queryPlanInput';
|
import { QueryPlanInput } from 'sql/parts/queryPlan/queryPlanInput';
|
||||||
|
import { NotebookInput, NotebookInputModel } from 'sql/parts/notebook/notebookInput';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ export const sqlModeId = 'sql';
|
|||||||
* to that type.
|
* to that type.
|
||||||
* @param input The input to check for conversion
|
* @param input The input to check for conversion
|
||||||
* @param options Editor options for controlling the conversion
|
* @param options Editor options for controlling the conversion
|
||||||
* @param instantiationService The instatianation service to use to create the new input types
|
* @param instantiationService The instantiation service to use to create the new input types
|
||||||
*/
|
*/
|
||||||
export function convertEditorInput(input: EditorInput, options: IQueryEditorOptions, instantiationService: IInstantiationService): EditorInput {
|
export function convertEditorInput(input: EditorInput, options: IQueryEditorOptions, instantiationService: IInstantiationService): EditorInput {
|
||||||
let denyQueryEditor = options && options.denyQueryEditor;
|
let denyQueryEditor = options && options.denyQueryEditor;
|
||||||
@@ -48,8 +49,20 @@ export function convertEditorInput(input: EditorInput, options: IQueryEditorOpti
|
|||||||
let queryPlanInput: QueryPlanInput = instantiationService.createInstance(QueryPlanInput, queryPlanXml, 'aaa', undefined);
|
let queryPlanInput: QueryPlanInput = instantiationService.createInstance(QueryPlanInput, queryPlanXml, 'aaa', undefined);
|
||||||
return queryPlanInput;
|
return queryPlanInput;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
//Notebook
|
||||||
|
uri = getNotebookEditorUri(input);
|
||||||
|
if(uri){
|
||||||
|
//TODO: We need to pass in notebook data either through notebook input or notebook service
|
||||||
|
let notebookData: string = fs.readFileSync(uri.fsPath);
|
||||||
|
let fileName: string = input? input.getName() : 'untitled';
|
||||||
|
let filePath: string = uri.fsPath;
|
||||||
|
let notebookInputModel = new NotebookInputModel(filePath, undefined, undefined);
|
||||||
|
//TO DO: Second paramter has to be the content.
|
||||||
|
let notebookInput: NotebookInput = instantiationService.createInstance(NotebookInput, fileName, notebookInputModel);
|
||||||
|
return notebookInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +93,7 @@ export function getSupportedInputResource(input: IEditorInput): URI {
|
|||||||
// file extensions for the inputs we support (should be all upper case for comparison)
|
// file extensions for the inputs we support (should be all upper case for comparison)
|
||||||
const sqlFileTypes = ['SQL'];
|
const sqlFileTypes = ['SQL'];
|
||||||
const sqlPlanFileTypes = ['SQLPLAN'];
|
const sqlPlanFileTypes = ['SQLPLAN'];
|
||||||
|
const notebookFileType = ['IPYNB'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If input is a supported query editor file, return it's URI. Otherwise return undefined.
|
* If input is a supported query editor file, return it's URI. Otherwise return undefined.
|
||||||
@@ -129,6 +143,29 @@ 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.
|
||||||
|
* @param input The EditorInput to get the URI of.
|
||||||
|
*/
|
||||||
|
function getNotebookEditorUri(input: EditorInput): URI {
|
||||||
|
if (!input || !input.getName()) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this editor is not already of type notebook input
|
||||||
|
if (!(input instanceof NotebookInput)) {
|
||||||
|
let uri: URI = getSupportedInputResource(input);
|
||||||
|
if (uri) {
|
||||||
|
if (hasFileExtension(notebookFileType, input, false)) {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given EditorInput is set to either undefined or sql mode
|
* Checks whether the given EditorInput is set to either undefined or sql mode
|
||||||
* @param input The EditorInput to check the mode of
|
* @param input The EditorInput to check the mode of
|
||||||
|
|||||||
Reference in New Issue
Block a user