From 6ba7bad90cd0dfad0ab299d77cfbbbaea3e5104e Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 19 Nov 2021 15:04:54 -0800 Subject: [PATCH] Fix language flavor change on connection when in sqlcmd mode (#17719) * Fix language flavor change on connection when in sqlcmd mode * comment + fix --- .../connection/browser/connectionManagementService.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/services/connection/browser/connectionManagementService.ts b/src/sql/workbench/services/connection/browser/connectionManagementService.ts index 56f8b46e82..9ea478f992 100644 --- a/src/sql/workbench/services/connection/browser/connectionManagementService.ts +++ b/src/sql/workbench/services/connection/browser/connectionManagementService.ts @@ -49,6 +49,8 @@ import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { toErrorMessage } from 'vs/base/common/errorMessage'; import { IQueryEditorConfiguration } from 'sql/platform/query/common/query'; +import { URI } from 'vs/base/common/uri'; +import { QueryEditorInput } from 'sql/workbench/common/editor/query/queryEditorInput'; export class ConnectionManagementService extends Disposable implements IConnectionManagementService { @@ -950,9 +952,12 @@ export class ConnectionManagementService extends Disposable implements IConnecti return this._providers.get(connection.providerName).onReady.then((provider) => { provider.connect(uri, connectionInfo); this._onConnectRequestSent.fire(); - + // Connections are made per URI so while there may possibly be multiple editors with + // that URI they all share the same state + const editor = this._editorService.findEditors(URI.parse(uri))[0]?.editor; // TODO make this generic enough to handle non-SQL languages too - this.doChangeLanguageFlavor(uri, 'sql', connection.providerName); + const language = editor instanceof QueryEditorInput && editor.state.isSqlCmdMode ? 'sqlcmd' : 'sql'; + this.doChangeLanguageFlavor(uri, language, connection.providerName); return true; }); }