change how we detect if a untitled query is valid (#6776)

This commit is contained in:
Anthony Dresser
2019-08-17 14:44:16 -07:00
committed by GitHub
parent b4c2acb8d0
commit 7f6839d38e
4 changed files with 23 additions and 41 deletions

View File

@@ -12,10 +12,9 @@ import { QueryPlanInput } from 'sql/workbench/parts/queryPlan/common/queryPlanIn
import { sqlModeId, untitledFilePrefix, getSupportedInputResource } from 'sql/workbench/common/customInputConverter';
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
import { IMode } from 'vs/editor/common/modes';
import { ITextModel } from 'vs/editor/common/model';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEditorService, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import Severity from 'vs/base/common/severity';
import nls = require('vs/nls');
@@ -31,7 +30,6 @@ import { ILanguageSelection } from 'vs/editor/common/services/modeService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { IFileService } from 'vs/platform/files/common/files';
/**
* Service wrapper for opening and creating SQL documents as sql editor inputs
@@ -50,23 +48,14 @@ export class QueryEditorService implements IQueryEditorService {
"Please save or discard changes before switching to/from the SQL Language Mode"
);
// service references for static functions
private static editorService: IEditorService;
private static instantiationService: IInstantiationService;
private static notificationService: INotificationService;
constructor(
@INotificationService _notificationService: INotificationService,
@INotificationService private _notificationService: INotificationService,
@IUntitledEditorService private _untitledEditorService: IUntitledEditorService,
@IInstantiationService private _instantiationService: IInstantiationService,
@IEditorService private _editorService: IEditorService,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IConfigurationService private _configurationService: IConfigurationService,
@IFileService private readonly fileService: IFileService
@IConfigurationService private _configurationService: IConfigurationService
) {
QueryEditorService.editorService = _editorService;
QueryEditorService.instantiationService = _instantiationService;
QueryEditorService.notificationService = _notificationService;
}
////// Public functions
@@ -185,7 +174,7 @@ export class QueryEditorService implements IQueryEditorService {
* In all other cases (when SQL is involved in the language change and the editor is not dirty),
* returns a promise that will resolve when the old editor has been replaced by a new editor.
*/
public static sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise<ITextModel> {
public sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise<ITextModel> {
if (!model || !languageSelection || !editor) {
return Promise.resolve(undefined);
}
@@ -205,7 +194,7 @@ export class QueryEditorService implements IQueryEditorService {
let uri: URI = QueryEditorService._getEditorChangeUri(editor.input, changingToSql);
if (uri.scheme === Schemas.untitled && (editor.input instanceof QueryInput || editor.input instanceof EditDataInput)) {
QueryEditorService.notificationService.notify({
this._notificationService.notify({
severity: Severity.Error,
message: QueryEditorService.CHANGE_UNSUPPORTED_ERROR_MESSAGE
});
@@ -215,7 +204,7 @@ export class QueryEditorService implements IQueryEditorService {
// Return undefined to notify the calling funciton to not perform the language change
// TODO change this - tracked by issue #727
if (editor.input.isDirty()) {
QueryEditorService.notificationService.notify({
this._notificationService.notify({
severity: Severity.Error,
message: QueryEditorService.CHANGE_ERROR_MESSAGE
});
@@ -229,7 +218,7 @@ export class QueryEditorService implements IQueryEditorService {
// Return a promise that will resovle when the old editor has been replaced by a new editor
return new Promise<ITextModel>((resolve, reject) => {
let newEditorInput = QueryEditorService._getNewEditorInput(changingToSql, editor.input, uri);
let newEditorInput = this.getNewEditorInput(changingToSql, editor.input, uri);
// Override queryEditorCheck to not open this file in a QueryEditor
if (!changingToSql) {
@@ -238,7 +227,7 @@ export class QueryEditorService implements IQueryEditorService {
group.closeEditor(editor.input).then(() => {
// Reopen a new editor in the same position/index
QueryEditorService.editorService.openEditor(newEditorInput, options, group).then((editor) => {
this._editorService.openEditor(newEditorInput, options, group).then((editor) => {
resolve(QueryEditorService._onEditorOpened(editor, uri.toString(), undefined, options.pinned));
},
(error) => {
@@ -262,13 +251,7 @@ export class QueryEditorService implements IQueryEditorService {
let counter = 1;
// Get document name and check if it exists
let filePath = prefixFileName(counter);
while (await this.fileService.exists(URI.file(filePath))) {
counter++;
filePath = prefixFileName(counter);
}
let untitledEditors = this._untitledEditorService.getAll();
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
while (this._untitledEditorService.exists(URI.from({ scheme: Schemas.untitled, path: filePath }))) {
counter++;
filePath = prefixFileName(counter);
}
@@ -281,19 +264,19 @@ export class QueryEditorService implements IQueryEditorService {
/**
* Returns a QueryInput if we are changingToSql. Returns a FileEditorInput if we are !changingToSql.
*/
private static _getNewEditorInput(changingToSql: boolean, input: IEditorInput, uri: URI): IEditorInput {
private getNewEditorInput(changingToSql: boolean, input: IEditorInput, uri: URI): IEditorInput {
if (!uri) {
return undefined;
}
let newEditorInput: IEditorInput = undefined;
if (changingToSql) {
const queryResultsInput: QueryResultsInput = QueryEditorService.instantiationService.createInstance(QueryResultsInput, uri.toString());
let queryInput: QueryInput = QueryEditorService.instantiationService.createInstance(QueryInput, '', input, queryResultsInput, undefined);
const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, uri.toString());
let queryInput: QueryInput = this._instantiationService.createInstance(QueryInput, '', input, queryResultsInput, undefined);
newEditorInput = queryInput;
} else {
let uriCopy: URI = URI.from({ scheme: uri.scheme, authority: uri.authority, path: uri.path, query: uri.query, fragment: uri.fragment });
newEditorInput = QueryEditorService.instantiationService.createInstance(FileEditorInput, uriCopy, undefined, undefined);
newEditorInput = this._instantiationService.createInstance(FileEditorInput, uriCopy, undefined, undefined);
}
return newEditorInput;