diff --git a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts index 828756017c..537f9b57f3 100644 --- a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts @@ -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 { + public sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise { 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((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; diff --git a/src/sql/workbench/services/queryEditor/common/queryEditorService.ts b/src/sql/workbench/services/queryEditor/common/queryEditorService.ts index 7dd2bce676..0c23e52f66 100644 --- a/src/sql/workbench/services/queryEditor/common/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/common/queryEditorService.ts @@ -8,6 +8,9 @@ import { IConnectableInput } from 'sql/platform/connection/common/connectionMana import { IEditorOptions } from 'vs/platform/editor/common/editor'; 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 { @@ -35,4 +38,6 @@ export interface IQueryEditorService { * @param newResource URI of the file after the save as operation was completed */ onSaveAsCompleted(oldResource: URI, newResource: URI): void; + + sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise; } diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 3aaadc09b7..9fb8fbc654 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -52,7 +52,7 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment, IStatusbarEntry } from 'vs/platform/statusbar/common/statusbar'; // {{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 { constructor(private master: IEncodingSupport, private details: IEncodingSupport) { } @@ -864,7 +864,8 @@ export class ChangeModeAction extends Action { @IQuickInputService private readonly quickInputService: IQuickInputService, @IPreferencesService private readonly preferencesService: IPreferencesService, @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); } @@ -985,7 +986,7 @@ export class ChangeModeAction extends Action { // {{SQL CARBON EDIT}} @anthonydresser preform a check before we actuall set the mode // Change mode if (typeof languageSelection !== 'undefined') { - QueryEditorService.sqlLanguageModeCheck(textModel, languageSelection, activeEditor).then(newTextModel => { + this.queryEditorService.sqlLanguageModeCheck(textModel, languageSelection, activeEditor).then(newTextModel => { if (newTextModel) { modeSupport.setMode(languageSelection.languageIdentifier.language); } diff --git a/src/vs/workbench/services/untitled/common/untitledEditorService.ts b/src/vs/workbench/services/untitled/common/untitledEditorService.ts index f7cfcc9f10..c85fca9248 100644 --- a/src/vs/workbench/services/untitled/common/untitledEditorService.ts +++ b/src/vs/workbench/services/untitled/common/untitledEditorService.ts @@ -56,12 +56,6 @@ export interface IUntitledEditorService { */ exists(resource: URI): boolean; - // {{SQL CARBON EDIT}} - /** - * Returns all untitled editor inputs. - */ - getAll(resources?: URI[]): UntitledEditorInput[]; - /** * Returns dirty untitled editors as resource URIs. */ @@ -147,8 +141,7 @@ export class UntitledEditorService extends Disposable implements IUntitledEditor return this.mapResourceToInput.get(resource); } - // {{SQL CARBON EDIT}} - public getAll(resources?: URI[]): UntitledEditorInput[] { + protected getAll(resources?: URI[]): UntitledEditorInput[] { if (resources) { return arrays.coalesce(resources.map(r => this.get(r))); }