Check for valid uri/resource (#9593)

* Check for valid uri/resource

* Add a few other cases
This commit is contained in:
Charles Gagnon
2020-03-13 11:19:25 -07:00
committed by GitHub
parent d5fdec5699
commit 1699dd0729
2 changed files with 8 additions and 8 deletions

View File

@@ -57,7 +57,7 @@ export function replaceConnection(oldUri: string, newUri: string, connectionServ
* *
* @param topLevelOnly If true, only return top-level (i.e. connected) Object Explorer connections instead of database connections when appropriate * @param topLevelOnly If true, only return top-level (i.e. connected) Object Explorer connections instead of database connections when appropriate
*/ */
export function getCurrentGlobalConnection(objectExplorerService: IObjectExplorerService, connectionManagementService: IConnectionManagementService, workbenchEditorService: IEditorService, topLevelOnly: boolean = false): IConnectionProfile { export function getCurrentGlobalConnection(objectExplorerService: IObjectExplorerService, connectionManagementService: IConnectionManagementService, workbenchEditorService: IEditorService, topLevelOnly: boolean = false): IConnectionProfile | undefined {
let connection: IConnectionProfile; let connection: IConnectionProfile;
// object Explorer Connection // object Explorer Connection
let objectExplorerSelection = objectExplorerService.getSelectedProfileAndDatabase(); let objectExplorerSelection = objectExplorerService.getSelectedProfileAndDatabase();
@@ -78,9 +78,9 @@ export function getCurrentGlobalConnection(objectExplorerService: IObjectExplore
let activeInput = workbenchEditorService.activeEditor; let activeInput = workbenchEditorService.activeEditor;
if (activeInput) { if (activeInput) {
// dashboard Connection // dashboard Connection
if (activeInput instanceof DashboardInput) { if (activeInput instanceof DashboardInput && activeInput.uri) {
connection = connectionManagementService.getConnectionProfile(activeInput.uri.toString()); connection = connectionManagementService.getConnectionProfile(activeInput.uri.toString());
} else { } else if (activeInput.resource) {
// editor Connection // editor Connection
connection = connectionManagementService.getConnectionProfile(activeInput.resource.toString()); connection = connectionManagementService.getConnectionProfile(activeInput.resource.toString());
} }

View File

@@ -96,12 +96,12 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
} }
private _onEditorClosed(event: IEditorCloseEvent): void { private _onEditorClosed(event: IEditorCloseEvent): void {
let uri = event.editor.resource.toString(); let uri = event.editor.resource?.toString();
if (uri && uri in this._sqlStatusEditors) { if (uri && uri in this._sqlStatusEditors) {
// If active editor is being closed, hide the query status. // If active editor is being closed, hide the query status.
let activeEditor = this.editorService.activeEditorPane; let activeEditor = this.editorService.activeEditorPane;
if (activeEditor) { if (activeEditor) {
let currentUri = activeEditor.input.resource.toString(); let currentUri = activeEditor.input.resource?.toString();
if (uri === currentUri) { if (uri === currentUri) {
this.hide(); this.hide();
} }
@@ -114,7 +114,7 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
private _onEditorsChanged(): void { private _onEditorsChanged(): void {
let activeEditor = this.editorService.activeEditorPane; let activeEditor = this.editorService.activeEditorPane;
if (activeEditor) { if (activeEditor) {
let uri = activeEditor.input.resource.toString(); let uri = activeEditor.input.resource?.toString();
// Show active editor's language flavor status // Show active editor's language flavor status
if (uri) { if (uri) {
@@ -145,7 +145,7 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont
private _showStatus(uri: string): void { private _showStatus(uri: string): void {
let activeEditor = this.editorService.activeEditorPane; let activeEditor = this.editorService.activeEditorPane;
if (activeEditor) { if (activeEditor) {
let currentUri = activeEditor.input.resource.toString(); let currentUri = activeEditor.input.resource?.toString();
if (uri === currentUri) { if (uri === currentUri) {
let flavor: SqlProviderEntry = this._sqlStatusEditors[uri]; let flavor: SqlProviderEntry = this._sqlStatusEditors[uri];
if (flavor) { if (flavor) {
@@ -186,7 +186,7 @@ export class ChangeFlavorAction extends Action {
public run(): Promise<any> { public run(): Promise<any> {
let activeEditor = this._editorService.activeEditorPane; let activeEditor = this._editorService.activeEditorPane;
let currentUri = activeEditor?.input.resource.toString(); let currentUri = activeEditor?.input.resource?.toString();
if (this._connectionManagementService.isConnected(currentUri)) { if (this._connectionManagementService.isConnected(currentUri)) {
let currentProvider = this._connectionManagementService.getProviderIdFromUri(currentUri); let currentProvider = this._connectionManagementService.getProviderIdFromUri(currentUri);
return this._showMessage(Severity.Info, nls.localize('alreadyConnected', return this._showMessage(Severity.Info, nls.localize('alreadyConnected',