Files
azuredatastudio/src/sql/platform/connection/common/connectionManagement.ts
Alex Ma 8c2cea4ea6 Added saving query (#16883)
* removed clear results and results visible.

* revert changes, still work in progress

* added small debug message

* added flag for state

* removed clear in queryResultsView

* moved carbon edit message

* simplifcation

* fixed spacing

* added clarifying message

* added clarifying comment

* added original tab clear line for future things

* added support for regular saves

* removed vscode changes

* added queryEditorTextInput to other versions

* added stuff

* reverted changes to queryTextEditorInput

* deleted duplicates

* moved untitledQueryEditorInput

* added FileQueryEditorInput constructor

* added instantiation

* added queryEditorTest

* added temporary state for save editor input

* added back in FileQueryEditorInput

* added example of both to test

* restored input.

* Added current results processing

* removed queryeditor import

* added disable dispose, WIP

* added small change to dispose

* added oldUri

* added small changes for adding renameQuery

* added first parts of renameQuery, need to add more in other parts. (Place next to disposeQuery).

* moved rename around in queryModel

* added rename to testQueryManagementServices, now need to add to queryrunner.

* added to queryRunner, need to test

* added renameQuery calls

* added renameQuery to extensions

* moved untitledQueryEditorInput to its old location

* removed duplicate untitledQueryEditorInput

* test import

* test blah

* moved fileQueryEditorInput to services

* deleted original fileQueryEditorInput

* Moved fileQueryEditorInput to new location

* added workbenchinstantiationservice

* added titledQueryEditorInput

* restored untitledQueryEditorInput.ts

* removed instantiation service

* made changes to titledQueryEditorInput

* Revert "deleted original fileQueryEditorInput"

This reverts commit dd5eb19ea1489d9c0dda159e6a798975240dab65.

* reverted back to pre move

* added altered untitledQueryEditorInput

* temporarily using old version of save until determining point where new URI is assigned.

* renamed oldUri to newUri to better reflect its actual use.

* added some debug messages for examining how uris work

* made small changes to untitledQueryEditorInput

* restored save to have actual code.

* moved renameQuery to proposed.

* added partially working save as for results (Pressing run breaks query)

* removed instantiationservice

* added newUri for dataservice

* added queryRunner.uri for queryModelService

* moved untitledQueryEditorInput to old location

* changed todomessage

* added explanation messages

* fixed spaces and added description

* moved untitledQueryEditorInput to new location

* added rename for connectionmanagementservice

* added carbon edit message

* removed carbon edit to editorservice

* removed another space

* added get and set for isSaving value

* removed accessor

* Update azdata.proposed.d.ts

added space

* fixed azdata.proposed

* added changeConnectionUriForQuery

* restored request

* replaced changeconnectionuri to changeuri

* Revert "replaced changeconnectionuri to changeuri"

This reverts commit eed8e518dee69cf2922ff86dc1763e6fb7715a71.

* made required changes

* fixed exclamation mark

* removed error on queryRunner changeconnection

* added save connect button status

* added additional state properties to save

* added wip setstate

* added changes for better naming

* added changes in preparation for vscode merge

* take screenshot of failed test before close editor (#16876)

* Add setting for enabling using new markdown renderer (#16864)

* Add setting for enabling using new markdown renderer

* Use const

* Fix circular dependency

* Default setting to false

* fix refresh node and add sample (#16888)

* Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)

* Bump VS Code version to latest sync point (#16891)

* Fix duplicate editor windows on reload (#16893)

* reset the icon before use (#16896)

* Undo merge icon change (#16894)

* disable cancel button after clicked once (#16783)

* disable cancel button after clicked once

* remove enabling of cancel button when cancelling

* Update sqlite version for smoke tests (#16903)

* update sqlite

* bump distro

Co-authored-by: chgagnon <chgagnon@microsoft.com>

* add autoCutoverConfiguration to getMigrationStatus (#16803)

* Enable scripting for triggers and other objects (#16885)

* WIP 1

* Add parentName to azdata

* Add some additional types for scripting

* Add parent type name to support view subobjects

* bump dependencies and address review comments

* Modify treeDataChange event (#125214) (#16907)

Modify treeDataChange event to support firing arrays.

* Move create new option for publish to top and filter out system dbs (#16908)

* Move create new option for publish to top

* Move New tag to description

* fix

* Open project to default location (#16910)

* Have create proj from database show default save location as option (#16909)

* Default create proj location to setting

* update icons

* undo

* Put search/ status/refresh in single line (#16898)

* add horizontal scroll bar to output (#16918)

* Fix extension linting warnings and enable extension linting in pipelines (#16922)

* Fix extension linting errors

* fix test

* Update public preview readme for sql migration extension (#16920)

* Add sql bindings package reference to project (#16912)

* list packages and add packages working

* cleanup and remove list packages

* cleanup

* change to pull in latest package version

* Add STS root folder override (#16927)

* Add STS root folder override

* Display message to user

* Show once for any service

* Fix some unhandled promise lint errors (#16924)

* Moved items around to handle new untitledQueryEditorInput location (#16914)

* moved items around to handle new untitledQueryEditorInput location

* added editor inputs to constants.

* added interface for untitledQueryEditorInput

* added IUntitledQueryEditorInput

* Revert "added IUntitledQueryEditorInput"

This reverts commit 67955eb289458e7ac4e7e5ce0ee077f38ed82a2c.

* Revert "added interface for untitledQueryEditorInput"

This reverts commit 88552dbd811b643fd51d5d21f4571b677d7bfc73.

* Revert "Revert "added interface for untitledQueryEditorInput""

This reverts commit 13a89c40e4cb0a3fa495f5b150c066892387e509.

* Revert "Revert "added IUntitledQueryEditorInput""

This reverts commit 8b2258ab49275a271a39036ea1734feca98ee753.

* added extends for IUntitledQueryEditorInput

* added casting in editorGroupView

* Revert "added casting in editorGroupView"

This reverts commit 61500ea43690b08ba2393808a8d118abc60da4ac.

* Revert "Moved items around to handle new untitledQueryEditorInput location (#16914)"

This reverts commit 87a663ee6b7cc3330c0528b20fb74f557451f911.

* Revert "Fix some unhandled promise lint errors (#16924)"

This reverts commit 73218a840df188f1ae26ff1c2e1aa5b85b9cfcb0.

* Revert "Add STS root folder override (#16927)"

This reverts commit 35936d464f2e452cd29659fffef20018ac6ffdd4.

* Revert "Add sql bindings package reference to project (#16912)"

This reverts commit 72d29ed7a7d298716ba159548af1f08adc82db25.

* Revert "Update public preview readme for sql migration extension (#16920)"

This reverts commit 3b3c3921557aabe86c927e6a833c0c41b48f7e23.

* Revert "Fix extension linting warnings and enable extension linting in pipelines (#16922)"

This reverts commit f5ea3e69ae5132c09eba699e8c25d1a1a66e0914.

* Revert "add horizontal scroll bar to output (#16918)"

This reverts commit 76bf86a2536edfe84b0f323571e489d69fe9fe00.

* Revert "Put search/ status/refresh in single line (#16898)"

This reverts commit d9553d09141c159e8b1cc27f6422e51b68800c7c.

* Revert "Have create proj from database show default save location as option (#16909)"

This reverts commit 88b9b7734b467a2552dfeea9c844b90361a660de.

* Revert "Open project to default location (#16910)"

This reverts commit a46170b347a28ff77f40883b055153823a86308e.

* Revert "Move create new option for publish to top and filter out system dbs (#16908)"

This reverts commit 4be47daf63771b6c3b12b786ba687dfc6ca0e3c6.

* Revert "Modify treeDataChange event (#125214) (#16907)"

This reverts commit 4161c21abcc78a9b5a65e52ae7d7f960ea71219b.

* Revert "Enable scripting for triggers and other objects (#16885)"

This reverts commit 2ece3ffb12478faf0f49df1e66bcc7acc0631500.

* Revert "add autoCutoverConfiguration to getMigrationStatus (#16803)"

This reverts commit 366633e7247d508138b45e902d7e034c79763dec.

* Revert "Update sqlite version for smoke tests (#16903)"

This reverts commit 64f66d7b18418b028cfa56b984d6f9979f65cc50.

* Revert "disable cancel button after clicked once (#16783)"

This reverts commit 12044e30746f44188d46a781f582781bf3638762.

* Revert "Undo merge icon change (#16894)"

This reverts commit 0801d14267a9980a2c29374666ad7fee14dfcafb.

* Revert "reset the icon before use (#16896)"

This reverts commit 971c39e8bc5c774fb49d81c5c36617ec45b4078c.

* Revert "Fix duplicate editor windows on reload (#16893)"

This reverts commit 4df3085b09b645a3ef2728c3ab3778fb7a63f2ba.

* Revert "Bump VS Code version to latest sync point (#16891)"

This reverts commit c1bc6639efcdf69d9b9c57cc44af3a1d19514f83.

* Revert "Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)"

This reverts commit c92da9c02ee221ca69813af69b039d3f3846aa42.

* Revert "fix refresh node and add sample (#16888)"

This reverts commit df820f6c03d167d933d089bfadf5296a7dcaf834.

* Revert "Add setting for enabling using new markdown renderer (#16864)"

This reverts commit e3c036dfbaa0a1e1588f348eb9eb4a7edb4f9bda.

* Revert "take screenshot of failed test before close editor (#16876)"

This reverts commit d466b19a6e56a43654c779c1dab60724b1f0c3db.

* fix spaces

* changed uri to public

* fixed formatting on azdata.proposed

* added queryprovider at the end

* changed already in connections list message.

* added notifyconnectionurichanged

* added changes to fix

* fixed testQueryModelService

* fixed leftover stuff

* more renames

* Added small changes

* added messages to untitledQueryEditorInput

* added work in progress fileQueryEditorInput save as

* fixed space

* removed changeUri

* remove saveAs from queryEditorInput

* removed undefined from createFileQueryEditorInput in untitled.

* changed saveAs for fileQueryEditorInput

* changed saveAs to use createInstance

* bumped version of STS in config.json

* bump version of dataprotocol-client

* update to yarn.lock

* more changes

* removed space for untitledQueryEditorInput

* some refactoring done

* removed already has provider check due to existing provider still existing

* added a comment

* fixed typo

* change results order around

* added already existing connection message

* restored untitledQueryEditorInput

* removed message

* added existing connection

* Revert "added existing connection"

This reverts commit 3cc34f6b1e670bb7b257e046f53560471badfd34.

* add try catch to restore older overwrite file behavior

* added types and error handling

* added error comments.

* changed message of both files

* fixed formatting for azdata.proposed.d.ts

Co-authored-by: Lucy Zhang <luczhan@microsoft.com>
Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
Co-authored-by: Alan Ren <alanren@microsoft.com>
Co-authored-by: Cory Rivera <corivera@microsoft.com>
Co-authored-by: stuti149 <87131830+stuti149@users.noreply.github.com>
Co-authored-by: Rachel Kim <rackim@microsoft.com>
Co-authored-by: Karl Burtram <karlb@microsoft.com>
Co-authored-by: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com>
Co-authored-by: Kim Santiago <31145923+kisantia@users.noreply.github.com>
2021-09-03 09:45:32 -07:00

378 lines
12 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Event } from 'vs/base/common/event';
import * as azdata from 'azdata';
import { IConnectionProfileGroup, ConnectionProfileGroup, INewConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
/**
* A range in the editor. This interface is suitable for serialization.
*/
export interface IRange {
/**
* Line number on which the range starts (starts at 1).
*/
readonly startLineNumber: number;
/**
* Column on which the range starts in line `startLineNumber` (starts at 1).
*/
readonly startColumn: number;
/**
* Line number on which the range ends.
*/
readonly endLineNumber: number;
/**
* Column on which the range ends in line `endLineNumber`.
*/
readonly endColumn: number;
}
/**
* Options for the actions that could happen after connecting is complete
*/
export interface IConnectionCompletionOptions {
/**
* save the connection to MRU and settings (only save to setting if profile.saveProfile is set to true)
*/
saveTheConnection: boolean;
/**
* open the dashboard after connection is complete
*/
showDashboard: boolean;
/**
* Parameters to be used if connecting from an editor
*/
params?: INewConnectionParams;
/**
* Open the connection dialog if connection fails
*/
showConnectionDialogOnError: boolean;
/**
* Open the connection firewall rule dialog if connection fails
*/
showFirewallRuleOnError: boolean;
}
export interface IConnectionResult {
connected: boolean;
errorMessage: string;
errorCode: number;
callStack: string;
errorHandled?: boolean;
connectionProfile?: IConnectionProfile;
}
export interface IConnectionCallbacks {
onConnectStart(): void;
onConnectReject(error?: string): void;
onConnectSuccess(params: INewConnectionParams, profile: IConnectionProfile): void;
onDisconnect(): void;
onConnectCanceled(): void;
}
export const SERVICE_ID = 'connectionManagementService';
export const IConnectionManagementService = createDecorator<IConnectionManagementService>(SERVICE_ID);
export interface IConnectionManagementService {
_serviceBrand: undefined;
// Event Emitters
onAddConnectionProfile: Event<IConnectionProfile>;
onDeleteConnectionProfile: Event<void>;
onConnect: Event<IConnectionParams>;
onDisconnect: Event<IConnectionParams>;
onConnectionChanged: Event<IConnectionParams>;
onLanguageFlavorChanged: Event<azdata.DidChangeLanguageFlavorParams>;
// Properties
providerNameToDisplayNameMap: { [providerDisplayName: string]: string };
/**
* Opens the edit connection dialog to change connection.
*/
showEditConnectionDialog(model: IConnectionProfile): Promise<void>;
/**
* Opens the connection dialog to create new connection
*/
showConnectionDialog(params?: INewConnectionParams, options?: IConnectionCompletionOptions, model?: Partial<IConnectionProfile>, connectionResult?: IConnectionResult): Promise<void>;
/**
* Load the password and opens a new connection
*/
connect(connection: IConnectionProfile, uri?: string, options?: IConnectionCompletionOptions, callbacks?: IConnectionCallbacks): Promise<IConnectionResult>;
/**
* Opens a new connection and save the profile in settings
*/
connectAndSaveProfile(connection: IConnectionProfile, uri: string, options?: IConnectionCompletionOptions, callbacks?: IConnectionCallbacks): Promise<IConnectionResult>;
/**
* Replaces a connectioninfo's associated uri with a new uri.
*/
changeConnectionUri(newUri: string, oldUri: string): void
/**
* Finds existing connection for given profile and purpose is any exists.
* The purpose is connection by default
*/
findExistingConnection(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection'): ConnectionProfile;
/**
* If there's already a connection for given profile and purpose, returns the ownerUri for the connection
* otherwise tries to make a connection and returns the owner uri when connection is complete
* The purpose is connection by default
*/
connectIfNotConnected(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection', saveConnection?: boolean): Promise<string>;
/**
* Adds the successful connection to MRU and send the connection error back to the connection handler for failed connections
*/
onConnectionComplete(handle: number, connectionInfoSummary: azdata.ConnectionInfoSummary): void;
onIntelliSenseCacheComplete(handle: number, connectionUri: string): void;
onConnectionChangedNotification(handle: number, changedConnInfo: azdata.ChangedConnectionInfo): void;
getConnectionGroups(providers?: string[]): ConnectionProfileGroup[];
getRecentConnections(providers?: string[]): ConnectionProfile[];
clearRecentConnectionsList(): void;
clearRecentConnection(connectionProfile: IConnectionProfile): void;
getActiveConnections(providers?: string[]): ConnectionProfile[];
saveProfileGroup(profile: INewConnectionProfileGroup): Promise<string>;
changeGroupIdForConnectionGroup(source: IConnectionProfileGroup, target: IConnectionProfileGroup): Promise<void>;
changeGroupIdForConnection(source: ConnectionProfile, targetGroupName: string): Promise<void>;
deleteConnection(connection: ConnectionProfile): Promise<boolean>;
deleteConnectionGroup(group: ConnectionProfileGroup): Promise<boolean>;
getAdvancedProperties(): azdata.ConnectionOption[] | undefined;
getConnectionUri(connectionProfile: IConnectionProfile): string;
getFormattedUri(uri: string, connectionProfile: IConnectionProfile): string;
getConnectionUriFromId(connectionId: string): string | undefined;
isConnected(fileUri: string): boolean;
refreshAzureAccountTokenIfNecessary(uri: string): Promise<boolean>;
/**
* Returns true if the connection profile is connected
*/
isProfileConnected(connectionProfile: IConnectionProfile): boolean;
/**
* Returns true if the connection profile is connecting
*/
isProfileConnecting(connectionProfile: IConnectionProfile): boolean;
isRecent(connectionProfile: ConnectionProfile): boolean;
isConnected(fileUri?: string, connectionProfile?: ConnectionProfile): boolean;
disconnectEditor(owner: IConnectableInput, force?: boolean): Promise<boolean>;
disconnect(connection: IConnectionProfile): Promise<void>;
disconnect(ownerUri: string): Promise<void>;
addSavedPassword(connectionProfile: IConnectionProfile): Promise<IConnectionProfile>;
listDatabases(connectionUri: string): Thenable<azdata.ListDatabasesResult | undefined>;
/**
* Register a connection provider
*/
registerProvider(providerId: string, provider: azdata.ConnectionProvider): void;
registerIconProvider(providerId: string, provider: azdata.IconProvider): void;
editGroup(group: ConnectionProfileGroup): Promise<void>;
getConnectionProfile(fileUri: string): IConnectionProfile | undefined;
getConnectionInfo(fileUri: string): ConnectionManagementInfo | undefined;
getDefaultProviderId(): string | undefined;
getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string };
/**
* Cancels the connection
*/
cancelConnection(connection: IConnectionProfile): Thenable<boolean>;
/**
* Changes the database for an active connection
*/
changeDatabase(connectionUri: string, databaseName: string): Thenable<boolean>;
/**
* Cancels the connection for the editor
*/
cancelEditorConnection(owner: IConnectableInput): Thenable<boolean>;
showDashboard(connection: IConnectionProfile): Thenable<boolean>;
closeDashboard(uri: string): void;
getProviderIdFromUri(ownerUri: string): string;
hasRegisteredServers(): boolean;
canChangeConnectionConfig(profile: IConnectionProfile, newGroupID: string): boolean;
getTabColorForUri(uri: string): string;
/**
* Sends a notification that the language flavor for a given URI has changed.
* For SQL, this would be the specific SQL implementation being used.
*
* @param uri the URI of the resource whose language has changed
* @param language the base language
* @param flavor the specific language flavor that's been set
*/
doChangeLanguageFlavor(uri: string, language: string, flavor: string): void;
/**
* Ensures that a default language flavor is set for a URI, if none has already been defined.
* @param uri document identifier
*/
ensureDefaultLanguageFlavor(uri: string): void;
/**
* Refresh the IntelliSense cache for the connection with the given URI
*/
rebuildIntelliSenseCache(uri: string): Thenable<void>;
/**
* Get a copy of the connection profile with its passwords removed
* @param profile The connection profile to remove passwords from
* @returns A copy of the connection profile with passwords removed
*/
removeConnectionProfileCredentials(profile: IConnectionProfile): IConnectionProfile;
/**
* Get the credentials for a connection profile, as they would appear in the options dictionary
* @param profileId The id of the connection profile to get the password for
* @returns A dictionary containing the credentials as they would be included
* in the connection profile's options dictionary, or undefined if the profile was not found
*/
getConnectionCredentials(profileId: string): Promise<{ [name: string]: string }>;
/**
* Get the ServerInfo for a connected connection profile
* @param profileId The id of the connection profile to get the password for
* @returns ServerInfo
*/
getServerInfo(profileId: string): azdata.ServerInfo;
/**
* Get the connection string for the provided connection ID
*/
getConnectionString(connectionId: string, includePassword: boolean): Thenable<string>;
/**
* Serialize connection string with optional provider
*/
buildConnectionInfo(connectionString: string, provider?: string): Thenable<azdata.ConnectionInfo>;
providerRegistered(providerId: string): boolean;
/**
* Get connection profile by id
*/
getConnectionProfileById(profileId: string): IConnectionProfile;
getProviderProperties(providerName: string): ConnectionProviderProperties;
getProviderLanguageMode(providerName?: string): string;
getConnectionIconId(connectionId: string): string;
/**
* Get known connection profiles including active connections, recent connections and saved connections.
* @param activeConnectionsOnly Indicates whether only get the active connections, default value is false.
* @returns array of connections
*/
getConnections(activeConnectionsOnly?: boolean): ConnectionProfile[];
getConnection(uri: string): ConnectionProfile;
}
export enum RunQueryOnConnectionMode {
none = 0,
executeQuery = 1,
executeCurrentQuery = 2,
estimatedQueryPlan = 3,
actualQueryPlan = 4
}
export interface INewConnectionParams {
connectionType: ConnectionType;
input?: IConnectableInput;
runQueryOnCompletion?: RunQueryOnConnectionMode;
queryRange?: IRange;
showDashboard?: boolean;
providers?: string[];
isEditConnection?: boolean;
oldProfileId?: string; // used for edit connection
}
export interface IConnectableInput {
uri: string;
onConnectStart(): void;
onConnectReject(error?: string): void;
onConnectSuccess(params: INewConnectionParams, profile: IConnectionProfile): void;
onDisconnect(): void;
onConnectCanceled(): void;
}
export enum ConnectionType {
default = 0,
editor = 1,
temporary = 2
}
export enum MetadataType {
Table = 0,
View = 1,
SProc = 2,
Function = 3
}
export enum TaskStatus {
NotStarted = 0,
InProgress = 1,
Succeeded = 2,
SucceededWithWarning = 3,
Failed = 4,
Canceled = 5,
Canceling = 6
}
export interface IConnectionParams {
connectionUri: string;
connectionProfile: IConnectionProfile;
}