diff --git a/src/sql/azdata.d.ts b/src/sql/azdata.d.ts index 291875523c..95eb9f1388 100644 --- a/src/sql/azdata.d.ts +++ b/src/sql/azdata.d.ts @@ -2000,7 +2000,7 @@ declare module 'azdata' { /** * Event values */ - values: {}; + values: { [key: string]: any }; } /** diff --git a/src/sql/base/browser/ui/selectBox/selectBox.ts b/src/sql/base/browser/ui/selectBox/selectBox.ts index 71dc09558c..6e3e02ba0e 100644 --- a/src/sql/base/browser/ui/selectBox/selectBox.ts +++ b/src/sql/base/browser/ui/selectBox/selectBox.ts @@ -172,8 +172,11 @@ export class SelectBox extends vsSelectBox { this.applyStyles(); } - public selectWithOptionName(optionName: string): void { - const option = this._optionsDictionary.get(optionName); + public selectWithOptionName(optionName?: string): void { + let option: number | undefined; + if (optionName) { + option = this._optionsDictionary.get(optionName); + } if (option) { this.select(option); } else { diff --git a/src/sql/workbench/browser/editor/profiler/profilerInput.ts b/src/sql/workbench/browser/editor/profiler/profilerInput.ts index df20a460fe..d466197fa8 100644 --- a/src/sql/workbench/browser/editor/profiler/profilerInput.ts +++ b/src/sql/workbench/browser/editor/profiler/profilerInput.ts @@ -12,7 +12,6 @@ import * as azdata from 'azdata'; import * as nls from 'vs/nls'; import { EditorInput } from 'vs/workbench/common/editor'; -import { IEditorModel } from 'vs/platform/editor/common/editor'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { Event, Emitter } from 'vs/base/common/event'; import { generateUuid } from 'vs/base/common/uuid'; @@ -22,16 +21,20 @@ import { FilterData } from 'sql/workbench/services/profiler/browser/profilerFilt import { uriPrefixes } from 'sql/platform/connection/common/utils'; import { find } from 'vs/base/common/arrays'; +export interface ColumnDefinition extends Slick.Column { + name: string; +} + export class ProfilerInput extends EditorInput implements IProfilerSession { public static ID: string = 'workbench.editorinputs.profilerinputs'; public static SCHEMA: string = 'profiler'; private _data: TableDataView; - private _id: ProfilerSessionID; + private _id?: ProfilerSessionID; private _state: ProfilerState; private _columns: string[] = []; - private _sessionName: string; - private _viewTemplate: IProfilerViewTemplate; + private _sessionName?: string; + private _viewTemplate?: IProfilerViewTemplate; // mapping of event categories to what column they display under // used for coallescing multiple events with different names to the same column private _columnMapping: { [event: string]: string } = {}; @@ -79,11 +82,11 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { this._data = new TableDataView(undefined, searchFn, undefined, filterFn); } - public get providerType(): string { + public get providerType(): string | undefined { return this.connection ? this.connection.providerName : undefined; } - public set viewTemplate(template: IProfilerViewTemplate) { + public setViewTemplate(template: IProfilerViewTemplate) { this._data.clear(); this._viewTemplate = template; @@ -101,17 +104,17 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { this.setColumnMapping(newColumns, newMapping); } - public get viewTemplate(): IProfilerViewTemplate { + public get viewTemplate(): IProfilerViewTemplate | undefined { return this._viewTemplate; } - public set sessionName(name: string) { + public setSessionName(name: string) { if (!this.state.isRunning || !this.state.isPaused) { this._sessionName = name; } } - public get sessionName(): string { + public get sessionName(): string | undefined { return this._sessionName; } @@ -119,10 +122,6 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { return ProfilerInput.ID; } - public resolve(refresh?: boolean): Promise { - return undefined; - } - public getName(): string { let name: string = nls.localize('profilerInput.profiler', "Profiler"); if (!this.connection) { @@ -143,10 +142,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { return this._data; } - public get columns(): Slick.Column[] { + public get columns(): ColumnDefinition[] { if (this._columns) { return this._columns.map(i => { - return >{ + return { id: i, field: i, name: i, @@ -183,7 +182,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { } public get id(): ProfilerSessionID { - return this._id; + return this._id!; } public get state(): ProfilerState { @@ -214,10 +213,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { }); if (!types.isUndefinedOrNull(sessionTemplate)) { let newView = find(this._profilerService.getViewTemplates(), (view) => { - return view.name === sessionTemplate.defaultView; + return view.name === sessionTemplate!.defaultView; }); if (!types.isUndefinedOrNull(newView)) { - this.viewTemplate = newView; + this.setViewTemplate(newView); } } @@ -242,7 +241,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { let newEvents = []; for (let i: number = 0; i < eventMessage.events.length && i < 500; ++i) { let e: azdata.ProfilerEvent = eventMessage.events[i]; - let data = {}; + let data: { [key: string]: any } = {}; data['EventClass'] = e.name; data['StartTime'] = e.timestamp; @@ -280,7 +279,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { } isDirty(): boolean { - return this.state.isRunning || this.state.isPaused; + return this.state.isRunning || !!this.state.isPaused; } dispose() { diff --git a/src/sql/workbench/browser/modal/modal.ts b/src/sql/workbench/browser/modal/modal.ts index 675a2d6491..a6bcd0bf84 100644 --- a/src/sql/workbench/browser/modal/modal.ts +++ b/src/sql/workbench/browser/modal/modal.ts @@ -264,14 +264,14 @@ export abstract class Modal extends Disposable implements IThemable { /** * Overridable to change behavior of escape key */ - protected onClose(e: StandardKeyboardEvent) { + protected onClose(e?: StandardKeyboardEvent) { this.hide(); } /** * Overridable to change behavior of enter key */ - protected onAccept(e: StandardKeyboardEvent) { + protected onAccept(e?: StandardKeyboardEvent) { this.hide(); } diff --git a/src/sql/workbench/contrib/profiler/browser/profilerEditor.ts b/src/sql/workbench/contrib/profiler/browser/profilerEditor.ts index 6f04b3aa49..24df69040a 100644 --- a/src/sql/workbench/contrib/profiler/browser/profilerEditor.ts +++ b/src/sql/workbench/contrib/profiler/browser/profilerEditor.ts @@ -239,7 +239,7 @@ export class ProfilerEditor extends BaseEditor { this._viewTemplateSelector.setAriaLabel(nls.localize('profiler.viewSelectAccessibleName', "Select View")); this._register(this._viewTemplateSelector.onDidSelect(e => { if (this.input) { - this.input.viewTemplate = find(this._viewTemplates, i => i.name === e.selected); + this.input.setViewTemplate(find(this._viewTemplates, i => i.name === e.selected)); } })); let viewTemplateContainer = document.createElement('div'); @@ -252,7 +252,7 @@ export class ProfilerEditor extends BaseEditor { this._sessionSelector.setAriaLabel(nls.localize('profiler.sessionSelectAccessibleName', "Select Session")); this._register(this._sessionSelector.onDidSelect(e => { if (this.input) { - this.input.sessionName = e.selected; + this.input.setSessionName(e.selected); } })); let sessionsContainer = document.createElement('div'); @@ -466,7 +466,7 @@ export class ProfilerEditor extends BaseEditor { if (input.viewTemplate) { this._viewTemplateSelector.selectWithOptionName(input.viewTemplate.name); } else { - input.viewTemplate = find(this._viewTemplates, i => i.name === 'Standard View'); + input.setViewTemplate(find(this._viewTemplates, i => i.name === 'Standard View')); } this._actionBar.context = input; @@ -581,11 +581,11 @@ export class ProfilerEditor extends BaseEditor { this._sessionsList = r; if (this._sessionsList.length > 0) { if (!this.input.sessionName) { - this.input.sessionName = previousSessionName; + this.input.setSessionName(previousSessionName); } if (this._sessionsList.indexOf(this.input.sessionName) === -1) { - this.input.sessionName = this._sessionsList[0]; + this.input.setSessionName(this._sessionsList[0]); } this._sessionSelector.selectWithOptionName(this.input.sessionName); diff --git a/src/sql/workbench/services/profiler/browser/interfaces.ts b/src/sql/workbench/services/profiler/browser/interfaces.ts index 4b8690a661..2fafadc861 100644 --- a/src/sql/workbench/services/profiler/browser/interfaces.ts +++ b/src/sql/workbench/services/profiler/browser/interfaces.ts @@ -27,19 +27,19 @@ export interface IProfilerSession { /** * Called by the service when more rows are available to render */ - onMoreRows(events: azdata.ProfilerSessionEvents); + onMoreRows(events: azdata.ProfilerSessionEvents): void; /** * Called by the service when the session is closed unexpectedly */ - onSessionStopped(events: azdata.ProfilerSessionStoppedParams); + onSessionStopped(events: azdata.ProfilerSessionStoppedParams): void; /** * Called by the service when a new profiler session is created by the dialog */ - onProfilerSessionCreated(events: azdata.ProfilerSessionCreatedParams); + onProfilerSessionCreated(events: azdata.ProfilerSessionCreatedParams): void; /** * Called by the service when the session state is changed */ - onSessionStateChanged(newState: INewProfilerState); + onSessionStateChanged(newState: INewProfilerState): void; } /** @@ -83,7 +83,7 @@ export interface IProfilerService { /** * Gets a list of running XEvent sessions on the Profiler Session's target */ - getXEventSessions(sessionId: ProfilerSessionID): Thenable; + getXEventSessions(sessionId: ProfilerSessionID): Promise; /** * The method called by the service provider for when more rows are available to render */ @@ -95,7 +95,7 @@ export interface IProfilerService { /** * Called by the service when a new profiler session is created by the dialog */ - onProfilerSessionCreated(events: azdata.ProfilerSessionCreatedParams); + onProfilerSessionCreated(events: azdata.ProfilerSessionCreatedParams): void; /** * Gets a list of the view templates that are specified in the settings * @param provider An optional string to limit the view templates to a specific provider diff --git a/src/sql/workbench/services/profiler/browser/profilerColumnEditorDialog.ts b/src/sql/workbench/services/profiler/browser/profilerColumnEditorDialog.ts index 1a644ec934..b958cba41f 100644 --- a/src/sql/workbench/services/profiler/browser/profilerColumnEditorDialog.ts +++ b/src/sql/workbench/services/profiler/browser/profilerColumnEditorDialog.ts @@ -33,11 +33,8 @@ class EventItem { constructor( private _name: string, private _parent: SessionItem, - private _columns?: Array, + private _columns: Array = new Array(), ) { - if (!_columns) { - this._columns = new Array(); - } } public hasChildren(): boolean { @@ -74,7 +71,7 @@ class EventItem { } class ColumnItem { - public selected: boolean; + public selected?: boolean; public readonly indeterminate = false; constructor( private _name: string, @@ -131,19 +128,15 @@ class SessionItem { constructor( private _name: string, private _sort: 'event' | 'column', - private _events?: Array + private _events: Array = new Array() ) { - if (!_events) { - this._events = new Array(); - } else { - _events.forEach(e => { - e.getChildren().forEach(c => { - if (!this._sortedColumnItems.some(i => i.id === c.id)) { - this._sortedColumnItems.push(new ColumnSortedColumnItem(c.id, this)); - } - }); + this._events.forEach(e => { + e.getChildren().forEach(c => { + if (!this._sortedColumnItems.some(i => i.id === c.id)) { + this._sortedColumnItems.push(new ColumnSortedColumnItem(c.id, this)); + } }); - } + }); } public get id(): string { @@ -152,9 +145,9 @@ class SessionItem { public hasChildren(): boolean { if (this._sort === 'event') { - return this._events && this._events.length > 0; + return !!this._events && this._events.length > 0; } else { - return this._events && this._events.some(i => i.hasChildren()); + return !!this._events && this._events.some(i => i.hasChildren()); } } @@ -202,10 +195,8 @@ class TreeRenderer implements IRenderer { return 'event'; } else if (element instanceof ColumnItem) { return 'column'; - } else if (element instanceof ColumnSortedColumnItem) { - return 'columnSorted'; } else { - return undefined; + return 'columnSorted'; } } @@ -253,12 +244,8 @@ class TreeDataSource implements IDataSource { return element.parent.id + element.id; } else if (element instanceof ColumnItem) { return element.parent.parent.id + element.parent.id + element.id; - } else if (element instanceof SessionItem) { - return element.id; - } else if (element instanceof ColumnSortedColumnItem) { - return element.id; } else { - return undefined; + return element.id; } } @@ -268,7 +255,7 @@ class TreeDataSource implements IDataSource { } else if (element instanceof EventItem) { return element.hasChildren(); } else { - return undefined; + return false; } } @@ -278,7 +265,7 @@ class TreeDataSource implements IDataSource { } else if (element instanceof SessionItem) { return Promise.resolve(element.getChildren()); } else { - return Promise.resolve(null); + return Promise.resolve([]); } } @@ -301,14 +288,14 @@ class TreeDataSource implements IDataSource { export class ProfilerColumnEditorDialog extends Modal { - private _selectBox: SelectBox; + private _selectBox?: SelectBox; private readonly _options = [ { text: nls.localize('eventSort', "Sort by event") }, { text: nls.localize('nameColumn', "Sort by column") } ]; - private _tree: Tree; - private _element: SessionItem; - private _treeContainer: HTMLElement; + private _tree?: Tree; + private _element?: SessionItem; + private _treeContainer?: HTMLElement; constructor( @ILayoutService layoutService: ILayoutService, @@ -335,22 +322,22 @@ export class ProfilerColumnEditorDialog extends Modal { this._selectBox = new SelectBox(this._options, 0, this._contextViewService); this._selectBox.render(body); this._register(this._selectBox.onDidSelect(e => { - this._element.changeSort(e.index === 0 ? 'event' : 'column'); - this._tree.refresh(this._element, true); + this._element!.changeSort(e.index === 0 ? 'event' : 'column'); + this._tree!.refresh(this._element!, true); })); this._treeContainer = DOM.append(body, DOM.$('.profiler-column-tree')); const renderer = new TreeRenderer(); this._tree = new Tree(this._treeContainer, { dataSource: new TreeDataSource(), renderer }); - this._register(renderer.onSelectedChange(e => this._tree.refresh(e, true))); + this._register(renderer.onSelectedChange(e => this._tree!.refresh(e, true))); this._register(attachListStyler(this._tree, this._themeService)); } - public open(input: ProfilerInput): void { + public open(_input?: ProfilerInput): void { super.show(); this._updateList(); } - protected onAccept(e: StandardKeyboardEvent): void { + protected onAccept(e?: StandardKeyboardEvent): void { this._updateInput(); super.onAccept(e); } @@ -408,7 +395,9 @@ export class ProfilerColumnEditorDialog extends Modal { } protected layout(height?: number): void { - this._tree.layout(DOM.getContentHeight(this._treeContainer)); + if (this._tree) { + this._tree.layout(DOM.getContentHeight(this._treeContainer!)); + } } } diff --git a/src/sql/workbench/services/profiler/browser/profilerFilter.ts b/src/sql/workbench/services/profiler/browser/profilerFilter.ts index c6dd688080..7cc5fb73e7 100644 --- a/src/sql/workbench/services/profiler/browser/profilerFilter.ts +++ b/src/sql/workbench/services/profiler/browser/profilerFilter.ts @@ -68,7 +68,7 @@ function matches(item: any, clauses: ProfilerFilterClause[]): boolean { match = actualValue !== undefined && actualValue !== null && actualValue !== ''; break; case ProfilerFilterClauseOperator.Contains: - match = actualValueString && actualValueString.indexOf(expectedValueString) > -1; + match = !!actualValueString && actualValueString.indexOf(expectedValueString) > -1; break; case ProfilerFilterClauseOperator.NotContains: match = !actualValueString || !(actualValueString.indexOf(expectedValueString) > -1); diff --git a/src/sql/workbench/services/profiler/browser/profilerFilterDialog.ts b/src/sql/workbench/services/profiler/browser/profilerFilterDialog.ts index 8f58bc474f..49999fa31b 100644 --- a/src/sql/workbench/services/profiler/browser/profilerFilterDialog.ts +++ b/src/sql/workbench/services/profiler/browser/profilerFilterDialog.ts @@ -63,13 +63,13 @@ const Operators = [Equals, NotEquals, LessThan, LessThanOrEquals, GreaterThan, G export class ProfilerFilterDialog extends Modal { - private _clauseBuilder: HTMLElement; - private _okButton: Button; - private _cancelButton: Button; - private _applyButton: Button; - private _loadFilterButton: Button; - private _saveFilterButton: Button; - private _input: ProfilerInput; + private _clauseBuilder?: HTMLElement; + private _okButton?: Button; + private _cancelButton?: Button; + private _applyButton?: Button; + private _loadFilterButton?: Button; + private _saveFilterButton?: Button; + private _input?: ProfilerInput; private _clauseRows: ClauseRowUI[] = []; @@ -80,7 +80,7 @@ export class ProfilerFilterDialog extends Modal { @IAdsTelemetryService telemetryService: IAdsTelemetryService, @IContextKeyService contextKeyService: IContextKeyService, @ILogService logService: ILogService, - @IContextViewService private contextViewService: IContextViewService, + @IContextViewService private readonly contextViewService: IContextViewService, @IProfilerService private profilerService: IProfilerService, @ITextResourcePropertiesService textResourcePropertiesService: ITextResourcePropertiesService ) { @@ -91,7 +91,7 @@ export class ProfilerFilterDialog extends Modal { this._input = input; this.render(); this.show(); - this._okButton.focus(); + this._okButton!.focus(); } public dispose(): void { @@ -125,7 +125,7 @@ export class ProfilerFilterDialog extends Modal { DOM.append(headerRow, DOM.$('td')).innerText = ValueText; DOM.append(headerRow, DOM.$('td')).innerText = ''; - this._input.filter.clauses.forEach(clause => { + this._input!.filter.clauses.forEach(clause => { this.addClauseRow(true, clause.field, this.convertToOperatorString(clause.operator), clause.value); }); @@ -182,7 +182,7 @@ export class ProfilerFilterDialog extends Modal { } private filterSession(): void { - this._input.filterSession(this.getFilter()); + this._input!.filterSession(this.getFilter()); } private saveFilter(): void { @@ -222,19 +222,19 @@ export class ProfilerFilterDialog extends Modal { } private addClauseRow(setInitialValue: boolean, field?: string, operator?: string, value?: string): void { - const columns = this._input.columns.map(column => column.name); + const columns = this._input!.columns.map(column => column.name); if (field && !find(columns, x => x === field)) { return; } - const row = DOM.append(this._clauseBuilder, DOM.$('tr')); + const row = DOM.append(this._clauseBuilder!, DOM.$('tr')); const clauseId = generateUuid(); const fieldDropDown = this.createSelectBox(DOM.append(row, DOM.$('td')), columns, columns[0], FieldText); const operatorDropDown = this.createSelectBox(DOM.append(row, DOM.$('td')), Operators, Operators[0], OperatorText); - const valueText = new InputBox(DOM.append(row, DOM.$('td')), undefined, {}); + const valueText = new InputBox(DOM.append(row, DOM.$('td')), this.contextViewService, {}); this._register(attachInputBoxStyler(valueText, this._themeService)); const removeCell = DOM.append(row, DOM.$('td')); @@ -259,7 +259,7 @@ export class ProfilerFilterDialog extends Modal { if (setInitialValue) { fieldDropDown.selectWithOptionName(field); operatorDropDown.selectWithOptionName(operator); - valueText.value = value; + valueText.value = value ?? ''; } this._clauseRows.push({ diff --git a/src/sql/workbench/services/profiler/browser/profilerService.ts b/src/sql/workbench/services/profiler/browser/profilerService.ts index 6aa6c82b1d..8048875dc6 100644 --- a/src/sql/workbench/services/profiler/browser/profilerService.ts +++ b/src/sql/workbench/services/profiler/browser/profilerService.ts @@ -29,11 +29,19 @@ class TwoWayMap { this.reverseMap = new Map(); } - get(input: T): K { + has(input: T): boolean { + return this.forwardMap.has(input); + } + + reverseHas(input: K): boolean { + return this.reverseMap.has(input); + } + + get(input: T): K | undefined { return this.forwardMap.get(input); } - reverseGet(input: K): T { + reverseGet(input: K): T | undefined { return this.reverseMap.get(input); } @@ -51,7 +59,7 @@ export class ProfilerService implements IProfilerService { private _idMap = new TwoWayMap(); private _sessionMap = new Map(); private _connectionMap = new Map(); - private _editColumnDialog: ProfilerColumnEditorDialog; + private _editColumnDialog?: ProfilerColumnEditorDialog; private _memento: any; private _context: Memento; @@ -91,67 +99,100 @@ export class ProfilerService implements IProfilerService { } public onMoreRows(params: azdata.ProfilerSessionEvents): void { - this._sessionMap.get(this._idMap.reverseGet(params.sessionId)).onMoreRows(params); + if (this._idMap.reverseHas(params.sessionId)) { + this._sessionMap.get(this._idMap.reverseGet(params.sessionId)!)!.onMoreRows(params); + } } public onSessionStopped(params: azdata.ProfilerSessionStoppedParams): void { - this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onSessionStopped(params); + if (this._idMap.reverseHas(params.ownerUri)) { + this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)!)!.onSessionStopped(params); + } } public onProfilerSessionCreated(params: azdata.ProfilerSessionCreatedParams): void { - this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onProfilerSessionCreated(params); - this.updateMemento(params.ownerUri, { previousSessionName: params.sessionName }); + if (this._idMap.reverseHas(params.ownerUri)) { + this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)!)!.onProfilerSessionCreated(params); + this.updateMemento(params.ownerUri, { previousSessionName: params.sessionName }); + } } - public connectSession(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.connectSession(this._idMap.get(id))); + public async connectSession(id: ProfilerSessionID): Promise { + if (this._idMap.has(id)) { + return this._runAction(id, provider => provider.connectSession(this._idMap.get(id)!)); + } + return false; } - public disconnectSession(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.disconnectSession(this._idMap.get(id))); + public async disconnectSession(id: ProfilerSessionID): Promise { + if (this._idMap.has(id)) { + return this._runAction(id, provider => provider.disconnectSession(this._idMap.get(id)!)); + } + return false; } - public createSession(id: string, createStatement: string, template: azdata.ProfilerSessionTemplate): Thenable { - return this._runAction(id, provider => provider.createSession(this._idMap.get(id), createStatement, template)).then(() => { - this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); - return true; - }, (reason) => { - this._notificationService.error(reason.message); - }); + public async createSession(id: string, createStatement: string, template: azdata.ProfilerSessionTemplate): Promise { + if (this._idMap.has(id)) { + try { + await this._runAction(id, provider => provider.createSession(this._idMap.get(id)!, createStatement, template)); + this._sessionMap.get(this._idMap.reverseGet(id)!)!.onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); + return true; + } catch (reason) { + this._notificationService.error(reason.message); + return false; + } + } + return false; } - public startSession(id: ProfilerSessionID, sessionName: string): Thenable { - this.updateMemento(id, { previousSessionName: sessionName }); - return this._runAction(id, provider => provider.startSession(this._idMap.get(id), sessionName)).then(() => { - this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); - return true; - }, (reason) => { - this._notificationService.error(reason.message); - }); + public async startSession(id: ProfilerSessionID, sessionName: string): Promise { + if (this._idMap.has(id)) { + this.updateMemento(id, { previousSessionName: sessionName }); + try { + await this._runAction(id, provider => provider.startSession(this._idMap.get(id)!, sessionName)); + this._sessionMap.get(this._idMap.reverseGet(id)!)!.onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); + return true; + } catch (reason) { + this._notificationService.error(reason.message); + return false; + } + } + return false; } - public pauseSession(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.pauseSession(this._idMap.get(id))); + public async pauseSession(id: ProfilerSessionID): Promise { + if (this._idMap.has(id)) { + return this._runAction(id, provider => provider.pauseSession(this._idMap.get(id)!)); + } else { + return false; + } } - public stopSession(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.stopSession(this._idMap.get(id))).then(() => { - this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false }); - return true; - }, (reason) => { - // The error won't be actionable to the user, so only log it to console. - // In case of error, the state of the UI is not usable, makes more sense to - // set it to stopped so that user can restart it or pick a different session - this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false }); - }); + public async stopSession(id: ProfilerSessionID): Promise { + if (this._idMap.has(id)) { + try { + await this._runAction(id, provider => provider.stopSession(this._idMap.get(id)!)); + this._sessionMap.get(this._idMap.reverseGet(id)!)!.onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false }); + return true; + } catch (e) { + this._sessionMap.get(this._idMap.reverseGet(id)!)!.onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false }); + return false; + } + } else { + return false; + } } - public getXEventSessions(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.getXEventSessions(this._idMap.get(id))).then((r) => { - return r; - }, (reason) => { - this._notificationService.error(reason.message); - }); + public async getXEventSessions(id: ProfilerSessionID): Promise { + if (this._idMap.get(id)) { + return this._runAction(id, provider => provider.getXEventSessions(this._idMap.get(id)!)).then((r) => { + return r; + }, (reason) => { + this._notificationService.error(reason.message); + return undefined; + }); + } + return undefined; } private _runAction(id: ProfilerSessionID, action: (handler: azdata.ProfilerProvider) => Thenable): Thenable { @@ -192,9 +233,9 @@ export class ProfilerService implements IProfilerService { return undefined; } - private getMementoKey(ownerUri: string): string { + private getMementoKey(ownerUri: string): string | undefined { let mementoKey = undefined; - let connectionProfile: IConnectionProfile = this._connectionMap.get(ownerUri); + let connectionProfile = this._connectionMap.get(ownerUri); if (connectionProfile) { mementoKey = connectionProfile.serverName; } @@ -219,7 +260,7 @@ export class ProfilerService implements IProfilerService { } this._editColumnDialog.open(input); - return Promise.resolve(null); + return Promise.resolve(); } public launchCreateSessionDialog(input: ProfilerInput): Thenable { diff --git a/src/tsconfig.vscode.json b/src/tsconfig.vscode.json index ea79413397..d2650fbea2 100644 --- a/src/tsconfig.vscode.json +++ b/src/tsconfig.vscode.json @@ -23,35 +23,88 @@ // "./vs/code/**/*.ts", "./vs/editor/**/*.ts", "./vs/platform/**/*.ts", - // "./vs/workbench/contrib/debug/common/debugProtocol.d.ts", - // "./vs/workbench/services/**/*.ts", + "./vs/workbench/services/**/*.ts", "./sql/base/**/*.ts", "./sql/editor/**/*.ts", "./sql/platform/**/*.ts", "./sql/workbench/common/**/*.ts", - "./sql/workbench/services/accountManagement/**/*.ts", - "./sql/workbench/services/admin/**/*.ts", - "./sql/workbench/services/assessment/**/*.ts", - "./sql/workbench/services/bootstrap/**/*.ts", - // "./sql/workbench/services/connection/**/*.ts", - "./sql/workbench/services/dashboard/**/*.ts", - // "./sql/workbench/services/dialog/**/*.ts", - "./sql/workbench/services/editData/**/*.ts", - "./sql/workbench/services/errorMessage/**/*.ts", - // "./sql/workbench/services/fileBrowser/**/*.ts", - // "./sql/workbench/services/insights/**/*.ts", - "./sql/workbench/services/jobManagement/**/*.ts", - "./sql/workbench/services/languageAssociation/**/*.ts", - // "./sql/workbench/services/notebook/**/*.ts", 201 errors - // "./sql/workbench/services/objectExplorer/**/*.ts", 326 errors - // "./sql/workbench/services/profiler/**/*.ts", 66 errors - "./sql/workbench/services/progress/**/*.ts", - // "./sql/workbench/services/query/**/*.ts", - // "./sql/workbench/services/queryEditor/**/*.ts", - "./sql/workbench/services/queryHistory/**/*.ts", - "./sql/workbench/services/resourceProvider/**/*.ts", - // "./sql/workbench/services/restore/**/*.ts", 125 errors - "./sql/workbench/services/serverGroup/**/*.ts", - "./sql/workbench/services/tasks/**/*.ts", + "./sql/workbench/services/**/*.ts", + "./sql/workbench/contrib/**/*.ts", + ], + "exclude": [ + "./sql/workbench/contrib/assessment/**/*.ts", // 3255 errors + "./sql/workbench/contrib/azure/**/*.ts", // 118 errors + "./sql/workbench/contrib/backup/**/*.ts", // 249 errors + "./sql/workbench/contrib/charts/**/*.ts", // 3253 errors + "./sql/workbench/contrib/commandLine/**/*.ts", // 3276 errors + "./sql/workbench/contrib/configuration/**/*.ts", // 2 errors + "./sql/workbench/contrib/connection/**/*.ts", // 355 errors + "./sql/workbench/contrib/dashboard/**/*.ts", // 1292 errors + "./sql/workbench/contrib/dataExplorer/**/*.ts", // 3275 errors + "./sql/workbench/contrib/editData/**/*.ts", // 579 errors + "./sql/workbench/contrib/editorReplacement/**/*.ts", // 3315 errors + "./sql/workbench/contrib/extensions/**/*.ts", // 45 errors + "./sql/workbench/contrib/jobManagement/**/*.ts", // 315 errors + "./sql/workbench/contrib/modelView/**/*.ts", // 3253 errors + "./sql/workbench/contrib/notebook/**/*.ts", // 3740 errors + "./sql/workbench/contrib/objectExplorer/**/*.ts", // 3330 errors + "./sql/workbench/contrib/preferences/**/*.ts", // 1 errors + "./sql/workbench/contrib/profiler/**/*.ts", // 204 errors + "./sql/workbench/contrib/query/**/*.ts", // 3342 errors + "./sql/workbench/contrib/queryHistory/**/*.ts", // 432 errors + "./sql/workbench/contrib/queryPlan/**/*.ts", // 52 errors + "./sql/workbench/contrib/restore/**/*.ts", // 142 errors + "./sql/workbench/contrib/scripting/**/*.ts", // 280 errors + "./sql/workbench/contrib/tasks/**/*.ts", // 100 errors + "./sql/workbench/contrib/views/**/*.ts", // 133 errors + "./sql/workbench/contrib/webview/**/*.ts", // 6 errors + "./sql/workbench/contrib/welcome/**/*.ts", // 66 errors + "./sql/workbench/services/connection/**/*.ts", // 3402 errors + "./sql/workbench/services/dialog/**/*.ts", // 3260 errors + "./sql/workbench/services/fileBrowser/**/*.ts", // 3253 errors + "./sql/workbench/services/insights/**/*.ts", // 3264 errors + "./sql/workbench/services/notebook/**/*.ts", // 201 errors + "./sql/workbench/services/objectExplorer/**/*.ts", // 384 errors + "./sql/workbench/services/query/**/*.ts", // 3278 errors + "./sql/workbench/services/queryEditor/**/*.ts", // 3278 errors + "./sql/workbench/services/restore/**/*.ts", // 173 errors + "./sql/workbench/update/**/*.ts", // 3253 errors + "./vs/workbench/services/accessibility/**/*.ts", // 3143 errors + "./vs/workbench/services/authentication/**/*.ts", // 3143 errors + "./vs/workbench/services/backup/**/*.ts", // 3143 errors + "./vs/workbench/services/configuration/**/*.ts", // 3143 errors + "./vs/workbench/services/configurationResolver/**/*.ts", // 3143 errors + "./vs/workbench/services/credentials/**/*.ts", // 3143 errors + "./vs/workbench/services/dialogs/**/*.ts", // 3143 errors + "./vs/workbench/services/editor/**/*.ts", // 3143 errors + "./vs/workbench/services/environment/**/*.ts", // 3143 errors + "./vs/workbench/services/extensionManagement/**/*.ts", // 3143 errors + "./vs/workbench/services/extensions/**/*.ts", // 3368 errors + "./vs/workbench/services/history/**/*.ts", // 3143 errors + "./vs/workbench/services/host/**/*.ts", // 3143 errors + "./vs/workbench/services/keybinding/**/*.ts", // 3143 errors + "./vs/workbench/services/label/**/*.ts", // 3143 errors + "./vs/workbench/services/log/**/*.ts", // 3143 errors + "./vs/workbench/services/output/**/*.ts", // 3143 errors + "./vs/workbench/services/path/**/*.ts", // 3143 errors + "./vs/workbench/services/progress/**/*.ts", // 3143 errors + "./vs/workbench/services/remote/**/*.ts", // 3143 errors + "./vs/workbench/services/sharedProcess/**/*.ts", // 3143 errors + "./vs/workbench/services/telemetry/**/*.ts", // 3143 errors + "./vs/workbench/services/textfile/**/*.ts", // 3143 errors + "./vs/workbench/services/textMate/**/*.ts", // 3143 errors + "./vs/workbench/services/textmodelResolver/**/*.ts", // 3143 errors + "./vs/workbench/services/textresourceProperties/**/*.ts", // 3143 errors + "./vs/workbench/services/themes/**/*.ts", // 3143 errors + "./vs/workbench/services/timer/**/*.ts", // 3143 errors + "./vs/workbench/services/title/**/*.ts", // 3143 errors + "./vs/workbench/services/untitled/**/*.ts", // 3143 errors + "./vs/workbench/services/update/**/*.ts", // 3143 errors + "./vs/workbench/services/url/**/*.ts", // 3143 errors + "./vs/workbench/services/userData/**/*.ts", // 3143 errors + "./vs/workbench/services/userDataSync/**/*.ts", // 3143 errors + "./vs/workbench/services/views/**/*.ts", // 3143 errors + "./vs/workbench/services/workingCopy/**/*.ts", // 3143 errors + "./vs/workbench/services/workspaces/**/*.ts", // 3143 errors ] }