From 89cc59a2fd34cb6f6d0857b5a75138b9ad66d614 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Tue, 15 Feb 2022 17:11:43 -0800 Subject: [PATCH] avoid auto language detection for sql editor (#18402) * avoid auto lang detection for sql editor * update comment --- .../services/queryEditor/browser/queryEditorService.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts index c596a40a4d..430bd38d6d 100644 --- a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts @@ -57,7 +57,12 @@ export class QueryEditorService implements IQueryEditorService { let docUri: URI = options.resource ?? URI.from({ scheme: Schemas.untitled, path: await this.createUntitledSqlFilePath(connectionProviderName) }); // Create a sql document pane with accoutrements - const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: this._connectionManagementService.getProviderLanguageMode(connectionProviderName) }) as UntitledTextEditorInput; + const mode = this._connectionManagementService.getProviderLanguageMode(connectionProviderName); + const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: mode }) as UntitledTextEditorInput; + // Set the mode explicitely to stop the language detection service from changing the mode unexpectedly. + // The mode parameter used when creating the editorInput is used as preferred mode, + // the language detection service won't do the language change only if the mode is explicitely set. + fileInput.setMode(mode); let untitledEditorModel = await fileInput.resolve(); if (options.initalContent) { untitledEditorModel.textEditorModel.setValue(options.initalContent);