mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
change how we detect if a untitled query is valid (#6776)
This commit is contained in:
@@ -12,10 +12,9 @@ import { QueryPlanInput } from 'sql/workbench/parts/queryPlan/common/queryPlanIn
|
|||||||
import { sqlModeId, untitledFilePrefix, getSupportedInputResource } from 'sql/workbench/common/customInputConverter';
|
import { sqlModeId, untitledFilePrefix, getSupportedInputResource } from 'sql/workbench/common/customInputConverter';
|
||||||
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
|
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
|
||||||
|
|
||||||
import { IMode } from 'vs/editor/common/modes';
|
|
||||||
import { ITextModel } from 'vs/editor/common/model';
|
import { ITextModel } from 'vs/editor/common/model';
|
||||||
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
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 { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import Severity from 'vs/base/common/severity';
|
import Severity from 'vs/base/common/severity';
|
||||||
import nls = require('vs/nls');
|
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 { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
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
|
* 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"
|
"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(
|
constructor(
|
||||||
@INotificationService _notificationService: INotificationService,
|
@INotificationService private _notificationService: INotificationService,
|
||||||
@IUntitledEditorService private _untitledEditorService: IUntitledEditorService,
|
@IUntitledEditorService private _untitledEditorService: IUntitledEditorService,
|
||||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||||
@IEditorService private _editorService: IEditorService,
|
@IEditorService private _editorService: IEditorService,
|
||||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||||
@IConfigurationService private _configurationService: IConfigurationService,
|
@IConfigurationService private _configurationService: IConfigurationService
|
||||||
@IFileService private readonly fileService: IFileService
|
|
||||||
) {
|
) {
|
||||||
QueryEditorService.editorService = _editorService;
|
|
||||||
QueryEditorService.instantiationService = _instantiationService;
|
|
||||||
QueryEditorService.notificationService = _notificationService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// Public functions
|
////// 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),
|
* 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.
|
* 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) {
|
if (!model || !languageSelection || !editor) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
@@ -205,7 +194,7 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
|
|
||||||
let uri: URI = QueryEditorService._getEditorChangeUri(editor.input, changingToSql);
|
let uri: URI = QueryEditorService._getEditorChangeUri(editor.input, changingToSql);
|
||||||
if (uri.scheme === Schemas.untitled && (editor.input instanceof QueryInput || editor.input instanceof EditDataInput)) {
|
if (uri.scheme === Schemas.untitled && (editor.input instanceof QueryInput || editor.input instanceof EditDataInput)) {
|
||||||
QueryEditorService.notificationService.notify({
|
this._notificationService.notify({
|
||||||
severity: Severity.Error,
|
severity: Severity.Error,
|
||||||
message: QueryEditorService.CHANGE_UNSUPPORTED_ERROR_MESSAGE
|
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
|
// Return undefined to notify the calling funciton to not perform the language change
|
||||||
// TODO change this - tracked by issue #727
|
// TODO change this - tracked by issue #727
|
||||||
if (editor.input.isDirty()) {
|
if (editor.input.isDirty()) {
|
||||||
QueryEditorService.notificationService.notify({
|
this._notificationService.notify({
|
||||||
severity: Severity.Error,
|
severity: Severity.Error,
|
||||||
message: QueryEditorService.CHANGE_ERROR_MESSAGE
|
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 a promise that will resovle when the old editor has been replaced by a new editor
|
||||||
return new Promise<ITextModel>((resolve, reject) => {
|
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
|
// Override queryEditorCheck to not open this file in a QueryEditor
|
||||||
if (!changingToSql) {
|
if (!changingToSql) {
|
||||||
@@ -238,7 +227,7 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
|
|
||||||
group.closeEditor(editor.input).then(() => {
|
group.closeEditor(editor.input).then(() => {
|
||||||
// Reopen a new editor in the same position/index
|
// 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));
|
resolve(QueryEditorService._onEditorOpened(editor, uri.toString(), undefined, options.pinned));
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
@@ -262,13 +251,7 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
let counter = 1;
|
let counter = 1;
|
||||||
// Get document name and check if it exists
|
// Get document name and check if it exists
|
||||||
let filePath = prefixFileName(counter);
|
let filePath = prefixFileName(counter);
|
||||||
while (await this.fileService.exists(URI.file(filePath))) {
|
while (this._untitledEditorService.exists(URI.from({ scheme: Schemas.untitled, path: filePath }))) {
|
||||||
counter++;
|
|
||||||
filePath = prefixFileName(counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
let untitledEditors = this._untitledEditorService.getAll();
|
|
||||||
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
|
|
||||||
counter++;
|
counter++;
|
||||||
filePath = prefixFileName(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.
|
* 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) {
|
if (!uri) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newEditorInput: IEditorInput = undefined;
|
let newEditorInput: IEditorInput = undefined;
|
||||||
if (changingToSql) {
|
if (changingToSql) {
|
||||||
const queryResultsInput: QueryResultsInput = QueryEditorService.instantiationService.createInstance(QueryResultsInput, uri.toString());
|
const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, uri.toString());
|
||||||
let queryInput: QueryInput = QueryEditorService.instantiationService.createInstance(QueryInput, '', input, queryResultsInput, undefined);
|
let queryInput: QueryInput = this._instantiationService.createInstance(QueryInput, '', input, queryResultsInput, undefined);
|
||||||
newEditorInput = queryInput;
|
newEditorInput = queryInput;
|
||||||
} else {
|
} else {
|
||||||
let uriCopy: URI = URI.from({ scheme: uri.scheme, authority: uri.authority, path: uri.path, query: uri.query, fragment: uri.fragment });
|
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;
|
return newEditorInput;
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import { IConnectableInput } from 'sql/platform/connection/common/connectionMana
|
|||||||
import { IEditorOptions } from 'vs/platform/editor/common/editor';
|
import { IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||||
|
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
|
import { ITextModel } from 'vs/editor/common/model';
|
||||||
|
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||||
|
import { IEditor } from 'vs/workbench/common/editor';
|
||||||
|
|
||||||
export interface IQueryEditorOptions extends IEditorOptions {
|
export interface IQueryEditorOptions extends IEditorOptions {
|
||||||
|
|
||||||
@@ -35,4 +38,6 @@ export interface IQueryEditorService {
|
|||||||
* @param newResource URI of the file after the save as operation was completed
|
* @param newResource URI of the file after the save as operation was completed
|
||||||
*/
|
*/
|
||||||
onSaveAsCompleted(oldResource: URI, newResource: URI): void;
|
onSaveAsCompleted(oldResource: URI, newResource: URI): void;
|
||||||
|
|
||||||
|
sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise<ITextModel>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
|||||||
import { IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment, IStatusbarEntry } from 'vs/platform/statusbar/common/statusbar';
|
import { IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment, IStatusbarEntry } from 'vs/platform/statusbar/common/statusbar';
|
||||||
|
|
||||||
// {{SQL CARBON EDIT}}
|
// {{SQL CARBON EDIT}}
|
||||||
import { QueryEditorService } from 'sql/workbench/services/queryEditor/browser/queryEditorService';
|
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||||
|
|
||||||
class SideBySideEditorEncodingSupport implements IEncodingSupport {
|
class SideBySideEditorEncodingSupport implements IEncodingSupport {
|
||||||
constructor(private master: IEncodingSupport, private details: IEncodingSupport) { }
|
constructor(private master: IEncodingSupport, private details: IEncodingSupport) { }
|
||||||
@@ -864,7 +864,8 @@ export class ChangeModeAction extends Action {
|
|||||||
@IQuickInputService private readonly quickInputService: IQuickInputService,
|
@IQuickInputService private readonly quickInputService: IQuickInputService,
|
||||||
@IPreferencesService private readonly preferencesService: IPreferencesService,
|
@IPreferencesService private readonly preferencesService: IPreferencesService,
|
||||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||||
@IUntitledEditorService private readonly untitledEditorService: IUntitledEditorService
|
@IUntitledEditorService private readonly untitledEditorService: IUntitledEditorService,
|
||||||
|
@IQueryEditorService private readonly queryEditorService: IQueryEditorService // {{ SQL CARBON EDIT }}
|
||||||
) {
|
) {
|
||||||
super(actionId, actionLabel);
|
super(actionId, actionLabel);
|
||||||
}
|
}
|
||||||
@@ -985,7 +986,7 @@ export class ChangeModeAction extends Action {
|
|||||||
// {{SQL CARBON EDIT}} @anthonydresser preform a check before we actuall set the mode
|
// {{SQL CARBON EDIT}} @anthonydresser preform a check before we actuall set the mode
|
||||||
// Change mode
|
// Change mode
|
||||||
if (typeof languageSelection !== 'undefined') {
|
if (typeof languageSelection !== 'undefined') {
|
||||||
QueryEditorService.sqlLanguageModeCheck(textModel, languageSelection, activeEditor).then(newTextModel => {
|
this.queryEditorService.sqlLanguageModeCheck(textModel, languageSelection, activeEditor).then(newTextModel => {
|
||||||
if (newTextModel) {
|
if (newTextModel) {
|
||||||
modeSupport.setMode(languageSelection.languageIdentifier.language);
|
modeSupport.setMode(languageSelection.languageIdentifier.language);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,12 +56,6 @@ export interface IUntitledEditorService {
|
|||||||
*/
|
*/
|
||||||
exists(resource: URI): boolean;
|
exists(resource: URI): boolean;
|
||||||
|
|
||||||
// {{SQL CARBON EDIT}}
|
|
||||||
/**
|
|
||||||
* Returns all untitled editor inputs.
|
|
||||||
*/
|
|
||||||
getAll(resources?: URI[]): UntitledEditorInput[];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns dirty untitled editors as resource URIs.
|
* Returns dirty untitled editors as resource URIs.
|
||||||
*/
|
*/
|
||||||
@@ -147,8 +141,7 @@ export class UntitledEditorService extends Disposable implements IUntitledEditor
|
|||||||
return this.mapResourceToInput.get(resource);
|
return this.mapResourceToInput.get(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
// {{SQL CARBON EDIT}}
|
protected getAll(resources?: URI[]): UntitledEditorInput[] {
|
||||||
public getAll(resources?: URI[]): UntitledEditorInput[] {
|
|
||||||
if (resources) {
|
if (resources) {
|
||||||
return arrays.coalesce(resources.map(r => this.get(r)));
|
return arrays.coalesce(resources.map(r => this.get(r)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user