Remove logging and clone utlities (#5309)

* remove log utility functions; remove custom mixin

* fix tests

* add log service as required by telemetry utils

* remove unused code

* replace some console.logs with logservice
This commit is contained in:
Anthony Dresser
2019-05-04 22:37:15 -07:00
committed by GitHub
parent df7645e4e5
commit ab0cd71d10
80 changed files with 439 additions and 383 deletions

View File

@@ -32,6 +32,7 @@ import { OVERRIDE_EDITOR_THEMING_SETTING } from 'sql/workbench/services/notebook
import * as notebookUtils from 'sql/workbench/parts/notebook/notebookUtils';
import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ILogService } from 'vs/platform/log/common/log';
export const CODE_SELECTOR: string = 'code-component';
const MARKDOWN_CLASS = 'markdown';
@@ -102,7 +103,8 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange
@Inject(IModelService) private _modelService: IModelService,
@Inject(IModeService) private _modeService: IModeService,
@Inject(IConfigurationService) private _configurationService: IConfigurationService,
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@Inject(ILogService) private readonly logService: ILogService
) {
super();
this._cellToggleMoreActions = this._instantiationService.createInstance(CellToggleMoreActions);
@@ -141,9 +143,9 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange
let cellUri = this.cellModel.cellUri.toString();
let connectionService = this.connectionService;
if (!shouldConnect && connectionService && connectionService.isConnected(cellUri)) {
connectionService.disconnect(cellUri).catch(e => console.log(e));
connectionService.disconnect(cellUri).catch(e => this.logService.error(e));
} else if (shouldConnect && this._model.activeConnection && this._model.activeConnection.id !== '-1') {
connectionService.connect(this._model.activeConnection, cellUri).catch(e => console.log(e));
connectionService.connect(this._model.activeConnection, cellUri).catch(e => this.logService.error(e));
}
}
}

View File

@@ -15,6 +15,7 @@ import { ICellModel, CellExecutionState } from 'sql/workbench/parts/notebook/mod
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { MultiStateAction, IMultiStateData } from 'sql/workbench/parts/notebook/notebookActions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ILogService } from 'vs/platform/log/common/log';
let notebookMoreActionMsg = localize('notebook.failed', "Please select active cell and try again");
const emptyExecutionCountLabel = '[ ]';
@@ -69,13 +70,15 @@ export class RunCellAction extends MultiStateAction<CellExecutionState> {
private _context: CellContext;
constructor(context: CellContext, @INotificationService private notificationService: INotificationService,
@IConnectionManagementService private connectionManagementService: IConnectionManagementService,
@IKeybindingService private keybindingService: IKeybindingService) {
@IKeybindingService keybindingService: IKeybindingService,
@ILogService logService: ILogService
) {
super(RunCellAction.ID, new IMultiStateData<CellExecutionState>([
{ key: CellExecutionState.Hidden, value: { label: emptyExecutionCountLabel, className: '', tooltip: '', hideIcon: true } },
{ key: CellExecutionState.Stopped, value: { label: '', className: 'toolbarIconRun', tooltip: localize('runCell', "Run cell"), commandId: 'notebook.command.runactivecell' } },
{ key: CellExecutionState.Running, value: { label: '', className: 'toolbarIconStop', tooltip: localize('stopCell', "Cancel execution") } },
{ key: CellExecutionState.Error, value: { label: '', className: 'toolbarIconRunError', tooltip: localize('errorRunCell', "Error on last run. Click to run again") } },
], CellExecutionState.Hidden), keybindingService);
], CellExecutionState.Hidden), keybindingService, logService);
this.ensureContextIsUpdated(context);
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { nb, connection } from 'azdata';
import { localize } from 'vs/nls';
@@ -24,6 +22,7 @@ import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHos
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { uriPrefixes } from 'sql/platform/connection/common/utils';
import { keys } from 'vs/base/common/map';
import { ILogService } from 'vs/platform/log/common/log';
/*
* Used to control whether a message in a dialog/wizard is displayed as an error,
@@ -74,7 +73,11 @@ export class NotebookModel extends Disposable implements INotebookModel {
private _clientSessionListeners: IDisposable[] = [];
private _connectionUrisToDispose: string[] = [];
constructor(private _notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, public connectionProfile?: IConnectionProfile) {
constructor(
private _notebookOptions: INotebookModelOptions,
public connectionProfile: IConnectionProfile | undefined,
@ILogService private readonly logService: ILogService
) {
super();
if (!_notebookOptions || !_notebookOptions.notebookUri || !_notebookOptions.notebookManagers) {
throw new Error('path or notebook service not defined');
@@ -588,7 +591,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
await this.updateKernelInfoOnKernelChange(kernel);
} catch (err2) {
// TODO should we handle this in any way?
console.log(`doChangeKernel: ignoring error ${notebookUtils.getErrorMessage(err2)}`);
this.logService.error(`doChangeKernel: ignoring error ${notebookUtils.getErrorMessage(err2)}`);
}
}
}
@@ -777,7 +780,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
}
await this.shutdownActiveSession();
} catch (err) {
console.log('An error occurred when closing the notebook: {0}', notebookUtils.getErrorMessage(err));
this.logService.error('An error occurred when closing the notebook: {0}', notebookUtils.getErrorMessage(err));
}
}
@@ -895,14 +898,14 @@ export class NotebookModel extends Disposable implements INotebookModel {
private async disconnectNotebookConnection(conn: ConnectionProfile): Promise<void> {
if (this.notebookOptions.connectionService.getConnectionUri(conn).includes(uriPrefixes.notebook)) {
let uri = this._notebookOptions.connectionService.getConnectionUri(conn);
await this.notebookOptions.connectionService.disconnect(uri).catch(e => console.log(e));
await this.notebookOptions.connectionService.disconnect(uri).catch(e => this.logService.error(e));
}
}
// Disconnect any connections that were added through the "Add new connection" functionality in the Attach To dropdown
private async disconnectAttachToConnections(): Promise<void> {
notebookUtils.asyncForEach(this._connectionUrisToDispose, async conn => {
await this.notebookOptions.connectionService.disconnect(conn).catch(e => console.log(e));
await this.notebookOptions.connectionService.disconnect(conn).catch(e => this.logService.error(e));
});
this._connectionUrisToDispose = [];
}

View File

@@ -41,12 +41,12 @@ import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilit
import { CellMagicMapper } from 'sql/workbench/parts/notebook/models/cellMagicMapper';
import { IExtensionsViewlet, VIEWLET_ID } from 'vs/workbench/contrib/extensions/common/extensions';
import { CellModel } from 'sql/workbench/parts/notebook/models/cell';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files';
import { isValidBasename } from 'vs/base/common/extpath';
import { basename } from 'vs/base/common/resources';
import { createErrorWithActions, isErrorWithActions } from 'vs/base/common/errorsWithActions';
import { createErrorWithActions } from 'vs/base/common/errorsWithActions';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { ILogService } from 'vs/platform/log/common/log';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
@@ -93,8 +93,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
@Inject(IKeybindingService) private keybindingService: IKeybindingService,
@Inject(IViewletService) private viewletService: IViewletService,
@Inject(ICapabilitiesService) private capabilitiesService: ICapabilitiesService,
@Inject(ICommandService) private commandService: ICommandService,
@Inject(ITextFileService) private textFileService: ITextFileService
@Inject(ITextFileService) private textFileService: ITextFileService,
@Inject(ILogService) private readonly logService: ILogService
) {
super();
this.updateProfile();
@@ -292,7 +292,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
defaultKernel: this._notebookParams.input.defaultKernel,
layoutChanged: this._notebookParams.input.layoutChanged,
capabilitiesService: this.capabilitiesService
}, false, this.profile);
}, this.profile, this.logService);
model.onError((errInfo: INotification) => this.handleModelError(errInfo));
await model.requestModelLoad(this._notebookParams.isTrusted);
model.contentChanged((change) => this.handleContentChanged(change));
@@ -400,7 +400,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
let attachToContainer = document.createElement('div');
let attachToDropdown = new AttachToDropdown(attachToContainer, this.contextViewService, this.modelReady,
this.connectionManagementService, this.connectionDialogService, this.notificationService, this.capabilitiesService);
this.connectionManagementService, this.connectionDialogService, this.notificationService, this.capabilitiesService, this.logService);
attachToDropdown.render(attachToContainer);
attachSelectBoxStyler(attachToDropdown, this.themeService);

View File

@@ -23,6 +23,7 @@ import { IConnectionDialogService } from 'sql/workbench/services/connection/comm
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
import { generateUri } from 'sql/platform/connection/common/utils';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ILogService } from 'vs/platform/log/common/log';
const msgLoading = localize('loading', "Loading kernels...");
const msgChanging = localize('changing', "Changing kernel...");
@@ -164,7 +165,11 @@ export class IMultiStateData<T> {
export abstract class MultiStateAction<T> extends Action {
constructor(id: string, protected states: IMultiStateData<T>, private _keybindingService: IKeybindingService) {
constructor(
id: string,
protected states: IMultiStateData<T>,
private _keybindingService: IKeybindingService,
private readonly logService: ILogService) {
super(id, '');
this.updateLabelAndIcon();
}
@@ -178,7 +183,7 @@ export abstract class MultiStateAction<T> extends Action {
keyboardShortcut = binding ? binding.getLabel() : undefined;
}
} catch (error) {
console.log(error);
this.logService.error(error);
}
this.label = this.states.label;
this.tooltip = keyboardShortcut ? this.states.tooltip + ` (${keyboardShortcut})` : this.states.tooltip;
@@ -313,11 +318,14 @@ export class KernelsDropdown extends SelectBox {
export class AttachToDropdown extends SelectBox {
private model: NotebookModel;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, modelReady: Promise<INotebookModel>,
constructor(
container: HTMLElement, contextViewProvider: IContextViewProvider, modelReady: Promise<INotebookModel>,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IConnectionDialogService private _connectionDialogService: IConnectionDialogService,
@INotificationService private _notificationService: INotificationService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService) {
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
@ILogService private readonly logService: ILogService
) {
super([msgLoadingContexts], msgLoadingContexts, contextViewProvider, container, { labelText: attachToLabel, labelOnTop: false } as ISelectBoxOptionsWithLabel);
if (modelReady) {
modelReady
@@ -366,7 +374,7 @@ export class AttachToDropdown extends SelectBox {
this.openConnectionDialog(true);
}
}).catch(err =>
console.log(err));
this.logService.error(err));
}
model.onValidConnectionSelected(validConnection => {
this.handleContextsChanged(!validConnection);