Add strict compiling for profiler service (#11898)

* add strict compiling for profiler

* fix up strict

* add contrib
This commit is contained in:
Anthony Dresser
2020-08-21 12:52:24 -07:00
committed by GitHub
parent 31323d6efb
commit 1b02fb6906
11 changed files with 248 additions and 163 deletions

2
src/sql/azdata.d.ts vendored
View File

@@ -2000,7 +2000,7 @@ declare module 'azdata' {
/** /**
* Event values * Event values
*/ */
values: {}; values: { [key: string]: any };
} }
/** /**

View File

@@ -172,8 +172,11 @@ export class SelectBox extends vsSelectBox {
this.applyStyles(); this.applyStyles();
} }
public selectWithOptionName(optionName: string): void { public selectWithOptionName(optionName?: string): void {
const option = this._optionsDictionary.get(optionName); let option: number | undefined;
if (optionName) {
option = this._optionsDictionary.get(optionName);
}
if (option) { if (option) {
this.select(option); this.select(option);
} else { } else {

View File

@@ -12,7 +12,6 @@ import * as azdata from 'azdata';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { EditorInput } from 'vs/workbench/common/editor'; import { EditorInput } from 'vs/workbench/common/editor';
import { IEditorModel } from 'vs/platform/editor/common/editor';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import { generateUuid } from 'vs/base/common/uuid'; 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 { uriPrefixes } from 'sql/platform/connection/common/utils';
import { find } from 'vs/base/common/arrays'; import { find } from 'vs/base/common/arrays';
export interface ColumnDefinition extends Slick.Column<Slick.SlickData> {
name: string;
}
export class ProfilerInput extends EditorInput implements IProfilerSession { export class ProfilerInput extends EditorInput implements IProfilerSession {
public static ID: string = 'workbench.editorinputs.profilerinputs'; public static ID: string = 'workbench.editorinputs.profilerinputs';
public static SCHEMA: string = 'profiler'; public static SCHEMA: string = 'profiler';
private _data: TableDataView<Slick.SlickData>; private _data: TableDataView<Slick.SlickData>;
private _id: ProfilerSessionID; private _id?: ProfilerSessionID;
private _state: ProfilerState; private _state: ProfilerState;
private _columns: string[] = []; private _columns: string[] = [];
private _sessionName: string; private _sessionName?: string;
private _viewTemplate: IProfilerViewTemplate; private _viewTemplate?: IProfilerViewTemplate;
// mapping of event categories to what column they display under // mapping of event categories to what column they display under
// used for coallescing multiple events with different names to the same column // used for coallescing multiple events with different names to the same column
private _columnMapping: { [event: string]: string } = {}; private _columnMapping: { [event: string]: string } = {};
@@ -79,11 +82,11 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
this._data = new TableDataView<Slick.SlickData>(undefined, searchFn, undefined, filterFn); this._data = new TableDataView<Slick.SlickData>(undefined, searchFn, undefined, filterFn);
} }
public get providerType(): string { public get providerType(): string | undefined {
return this.connection ? this.connection.providerName : undefined; return this.connection ? this.connection.providerName : undefined;
} }
public set viewTemplate(template: IProfilerViewTemplate) { public setViewTemplate(template: IProfilerViewTemplate) {
this._data.clear(); this._data.clear();
this._viewTemplate = template; this._viewTemplate = template;
@@ -101,17 +104,17 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
this.setColumnMapping(newColumns, newMapping); this.setColumnMapping(newColumns, newMapping);
} }
public get viewTemplate(): IProfilerViewTemplate { public get viewTemplate(): IProfilerViewTemplate | undefined {
return this._viewTemplate; return this._viewTemplate;
} }
public set sessionName(name: string) { public setSessionName(name: string) {
if (!this.state.isRunning || !this.state.isPaused) { if (!this.state.isRunning || !this.state.isPaused) {
this._sessionName = name; this._sessionName = name;
} }
} }
public get sessionName(): string { public get sessionName(): string | undefined {
return this._sessionName; return this._sessionName;
} }
@@ -119,10 +122,6 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
return ProfilerInput.ID; return ProfilerInput.ID;
} }
public resolve(refresh?: boolean): Promise<IEditorModel> {
return undefined;
}
public getName(): string { public getName(): string {
let name: string = nls.localize('profilerInput.profiler', "Profiler"); let name: string = nls.localize('profilerInput.profiler', "Profiler");
if (!this.connection) { if (!this.connection) {
@@ -143,10 +142,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
return this._data; return this._data;
} }
public get columns(): Slick.Column<Slick.SlickData>[] { public get columns(): ColumnDefinition[] {
if (this._columns) { if (this._columns) {
return this._columns.map(i => { return this._columns.map(i => {
return <Slick.Column<Slick.SlickData>>{ return <ColumnDefinition>{
id: i, id: i,
field: i, field: i,
name: i, name: i,
@@ -183,7 +182,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
} }
public get id(): ProfilerSessionID { public get id(): ProfilerSessionID {
return this._id; return this._id!;
} }
public get state(): ProfilerState { public get state(): ProfilerState {
@@ -214,10 +213,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
}); });
if (!types.isUndefinedOrNull(sessionTemplate)) { if (!types.isUndefinedOrNull(sessionTemplate)) {
let newView = find(this._profilerService.getViewTemplates(), (view) => { let newView = find(this._profilerService.getViewTemplates(), (view) => {
return view.name === sessionTemplate.defaultView; return view.name === sessionTemplate!.defaultView;
}); });
if (!types.isUndefinedOrNull(newView)) { if (!types.isUndefinedOrNull(newView)) {
this.viewTemplate = newView; this.setViewTemplate(newView);
} }
} }
@@ -242,7 +241,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
let newEvents = []; let newEvents = [];
for (let i: number = 0; i < eventMessage.events.length && i < 500; ++i) { for (let i: number = 0; i < eventMessage.events.length && i < 500; ++i) {
let e: azdata.ProfilerEvent = eventMessage.events[i]; let e: azdata.ProfilerEvent = eventMessage.events[i];
let data = {}; let data: { [key: string]: any } = {};
data['EventClass'] = e.name; data['EventClass'] = e.name;
data['StartTime'] = e.timestamp; data['StartTime'] = e.timestamp;
@@ -280,7 +279,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
} }
isDirty(): boolean { isDirty(): boolean {
return this.state.isRunning || this.state.isPaused; return this.state.isRunning || !!this.state.isPaused;
} }
dispose() { dispose() {

View File

@@ -264,14 +264,14 @@ export abstract class Modal extends Disposable implements IThemable {
/** /**
* Overridable to change behavior of escape key * Overridable to change behavior of escape key
*/ */
protected onClose(e: StandardKeyboardEvent) { protected onClose(e?: StandardKeyboardEvent) {
this.hide(); this.hide();
} }
/** /**
* Overridable to change behavior of enter key * Overridable to change behavior of enter key
*/ */
protected onAccept(e: StandardKeyboardEvent) { protected onAccept(e?: StandardKeyboardEvent) {
this.hide(); this.hide();
} }

View File

@@ -239,7 +239,7 @@ export class ProfilerEditor extends BaseEditor {
this._viewTemplateSelector.setAriaLabel(nls.localize('profiler.viewSelectAccessibleName', "Select View")); this._viewTemplateSelector.setAriaLabel(nls.localize('profiler.viewSelectAccessibleName', "Select View"));
this._register(this._viewTemplateSelector.onDidSelect(e => { this._register(this._viewTemplateSelector.onDidSelect(e => {
if (this.input) { 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'); let viewTemplateContainer = document.createElement('div');
@@ -252,7 +252,7 @@ export class ProfilerEditor extends BaseEditor {
this._sessionSelector.setAriaLabel(nls.localize('profiler.sessionSelectAccessibleName', "Select Session")); this._sessionSelector.setAriaLabel(nls.localize('profiler.sessionSelectAccessibleName', "Select Session"));
this._register(this._sessionSelector.onDidSelect(e => { this._register(this._sessionSelector.onDidSelect(e => {
if (this.input) { if (this.input) {
this.input.sessionName = e.selected; this.input.setSessionName(e.selected);
} }
})); }));
let sessionsContainer = document.createElement('div'); let sessionsContainer = document.createElement('div');
@@ -466,7 +466,7 @@ export class ProfilerEditor extends BaseEditor {
if (input.viewTemplate) { if (input.viewTemplate) {
this._viewTemplateSelector.selectWithOptionName(input.viewTemplate.name); this._viewTemplateSelector.selectWithOptionName(input.viewTemplate.name);
} else { } 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; this._actionBar.context = input;
@@ -581,11 +581,11 @@ export class ProfilerEditor extends BaseEditor {
this._sessionsList = r; this._sessionsList = r;
if (this._sessionsList.length > 0) { if (this._sessionsList.length > 0) {
if (!this.input.sessionName) { if (!this.input.sessionName) {
this.input.sessionName = previousSessionName; this.input.setSessionName(previousSessionName);
} }
if (this._sessionsList.indexOf(this.input.sessionName) === -1) { 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); this._sessionSelector.selectWithOptionName(this.input.sessionName);

View File

@@ -27,19 +27,19 @@ export interface IProfilerSession {
/** /**
* Called by the service when more rows are available to render * 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 * 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 * 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 * 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 * Gets a list of running XEvent sessions on the Profiler Session's target
*/ */
getXEventSessions(sessionId: ProfilerSessionID): Thenable<string[]>; getXEventSessions(sessionId: ProfilerSessionID): Promise<string[] | undefined>;
/** /**
* The method called by the service provider for when more rows are available to render * 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 * 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 * 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 * @param provider An optional string to limit the view templates to a specific provider

View File

@@ -33,11 +33,8 @@ class EventItem {
constructor( constructor(
private _name: string, private _name: string,
private _parent: SessionItem, private _parent: SessionItem,
private _columns?: Array<ColumnItem>, private _columns: Array<ColumnItem> = new Array<ColumnItem>(),
) { ) {
if (!_columns) {
this._columns = new Array<ColumnItem>();
}
} }
public hasChildren(): boolean { public hasChildren(): boolean {
@@ -74,7 +71,7 @@ class EventItem {
} }
class ColumnItem { class ColumnItem {
public selected: boolean; public selected?: boolean;
public readonly indeterminate = false; public readonly indeterminate = false;
constructor( constructor(
private _name: string, private _name: string,
@@ -131,12 +128,9 @@ class SessionItem {
constructor( constructor(
private _name: string, private _name: string,
private _sort: 'event' | 'column', private _sort: 'event' | 'column',
private _events?: Array<EventItem> private _events: Array<EventItem> = new Array<EventItem>()
) { ) {
if (!_events) { this._events.forEach(e => {
this._events = new Array<EventItem>();
} else {
_events.forEach(e => {
e.getChildren().forEach(c => { e.getChildren().forEach(c => {
if (!this._sortedColumnItems.some(i => i.id === c.id)) { if (!this._sortedColumnItems.some(i => i.id === c.id)) {
this._sortedColumnItems.push(new ColumnSortedColumnItem(c.id, this)); this._sortedColumnItems.push(new ColumnSortedColumnItem(c.id, this));
@@ -144,7 +138,6 @@ class SessionItem {
}); });
}); });
} }
}
public get id(): string { public get id(): string {
return this._name; return this._name;
@@ -152,9 +145,9 @@ class SessionItem {
public hasChildren(): boolean { public hasChildren(): boolean {
if (this._sort === 'event') { if (this._sort === 'event') {
return this._events && this._events.length > 0; return !!this._events && this._events.length > 0;
} else { } 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'; return 'event';
} else if (element instanceof ColumnItem) { } else if (element instanceof ColumnItem) {
return 'column'; return 'column';
} else if (element instanceof ColumnSortedColumnItem) {
return 'columnSorted';
} else { } else {
return undefined; return 'columnSorted';
} }
} }
@@ -253,12 +244,8 @@ class TreeDataSource implements IDataSource {
return element.parent.id + element.id; return element.parent.id + element.id;
} else if (element instanceof ColumnItem) { } else if (element instanceof ColumnItem) {
return element.parent.parent.id + element.parent.id + element.id; 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 { } else {
return undefined; return element.id;
} }
} }
@@ -268,7 +255,7 @@ class TreeDataSource implements IDataSource {
} else if (element instanceof EventItem) { } else if (element instanceof EventItem) {
return element.hasChildren(); return element.hasChildren();
} else { } else {
return undefined; return false;
} }
} }
@@ -278,7 +265,7 @@ class TreeDataSource implements IDataSource {
} else if (element instanceof SessionItem) { } else if (element instanceof SessionItem) {
return Promise.resolve(element.getChildren()); return Promise.resolve(element.getChildren());
} else { } else {
return Promise.resolve(null); return Promise.resolve([]);
} }
} }
@@ -301,14 +288,14 @@ class TreeDataSource implements IDataSource {
export class ProfilerColumnEditorDialog extends Modal { export class ProfilerColumnEditorDialog extends Modal {
private _selectBox: SelectBox; private _selectBox?: SelectBox;
private readonly _options = [ private readonly _options = [
{ text: nls.localize('eventSort', "Sort by event") }, { text: nls.localize('eventSort', "Sort by event") },
{ text: nls.localize('nameColumn', "Sort by column") } { text: nls.localize('nameColumn', "Sort by column") }
]; ];
private _tree: Tree; private _tree?: Tree;
private _element: SessionItem; private _element?: SessionItem;
private _treeContainer: HTMLElement; private _treeContainer?: HTMLElement;
constructor( constructor(
@ILayoutService layoutService: ILayoutService, @ILayoutService layoutService: ILayoutService,
@@ -335,22 +322,22 @@ export class ProfilerColumnEditorDialog extends Modal {
this._selectBox = new SelectBox(this._options, 0, this._contextViewService); this._selectBox = new SelectBox(this._options, 0, this._contextViewService);
this._selectBox.render(body); this._selectBox.render(body);
this._register(this._selectBox.onDidSelect(e => { this._register(this._selectBox.onDidSelect(e => {
this._element.changeSort(e.index === 0 ? 'event' : 'column'); this._element!.changeSort(e.index === 0 ? 'event' : 'column');
this._tree.refresh(this._element, true); this._tree!.refresh(this._element!, true);
})); }));
this._treeContainer = DOM.append(body, DOM.$('.profiler-column-tree')); this._treeContainer = DOM.append(body, DOM.$('.profiler-column-tree'));
const renderer = new TreeRenderer(); const renderer = new TreeRenderer();
this._tree = new Tree(this._treeContainer, { dataSource: new TreeDataSource(), renderer }); 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)); this._register(attachListStyler(this._tree, this._themeService));
} }
public open(input: ProfilerInput): void { public open(_input?: ProfilerInput): void {
super.show(); super.show();
this._updateList(); this._updateList();
} }
protected onAccept(e: StandardKeyboardEvent): void { protected onAccept(e?: StandardKeyboardEvent): void {
this._updateInput(); this._updateInput();
super.onAccept(e); super.onAccept(e);
} }
@@ -408,7 +395,9 @@ export class ProfilerColumnEditorDialog extends Modal {
} }
protected layout(height?: number): void { protected layout(height?: number): void {
this._tree.layout(DOM.getContentHeight(this._treeContainer)); if (this._tree) {
this._tree.layout(DOM.getContentHeight(this._treeContainer!));
}
} }
} }

View File

@@ -68,7 +68,7 @@ function matches(item: any, clauses: ProfilerFilterClause[]): boolean {
match = actualValue !== undefined && actualValue !== null && actualValue !== ''; match = actualValue !== undefined && actualValue !== null && actualValue !== '';
break; break;
case ProfilerFilterClauseOperator.Contains: case ProfilerFilterClauseOperator.Contains:
match = actualValueString && actualValueString.indexOf(expectedValueString) > -1; match = !!actualValueString && actualValueString.indexOf(expectedValueString) > -1;
break; break;
case ProfilerFilterClauseOperator.NotContains: case ProfilerFilterClauseOperator.NotContains:
match = !actualValueString || !(actualValueString.indexOf(expectedValueString) > -1); match = !actualValueString || !(actualValueString.indexOf(expectedValueString) > -1);

View File

@@ -63,13 +63,13 @@ const Operators = [Equals, NotEquals, LessThan, LessThanOrEquals, GreaterThan, G
export class ProfilerFilterDialog extends Modal { export class ProfilerFilterDialog extends Modal {
private _clauseBuilder: HTMLElement; private _clauseBuilder?: HTMLElement;
private _okButton: Button; private _okButton?: Button;
private _cancelButton: Button; private _cancelButton?: Button;
private _applyButton: Button; private _applyButton?: Button;
private _loadFilterButton: Button; private _loadFilterButton?: Button;
private _saveFilterButton: Button; private _saveFilterButton?: Button;
private _input: ProfilerInput; private _input?: ProfilerInput;
private _clauseRows: ClauseRowUI[] = []; private _clauseRows: ClauseRowUI[] = [];
@@ -80,7 +80,7 @@ export class ProfilerFilterDialog extends Modal {
@IAdsTelemetryService telemetryService: IAdsTelemetryService, @IAdsTelemetryService telemetryService: IAdsTelemetryService,
@IContextKeyService contextKeyService: IContextKeyService, @IContextKeyService contextKeyService: IContextKeyService,
@ILogService logService: ILogService, @ILogService logService: ILogService,
@IContextViewService private contextViewService: IContextViewService, @IContextViewService private readonly contextViewService: IContextViewService,
@IProfilerService private profilerService: IProfilerService, @IProfilerService private profilerService: IProfilerService,
@ITextResourcePropertiesService textResourcePropertiesService: ITextResourcePropertiesService @ITextResourcePropertiesService textResourcePropertiesService: ITextResourcePropertiesService
) { ) {
@@ -91,7 +91,7 @@ export class ProfilerFilterDialog extends Modal {
this._input = input; this._input = input;
this.render(); this.render();
this.show(); this.show();
this._okButton.focus(); this._okButton!.focus();
} }
public dispose(): void { 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 = ValueText;
DOM.append(headerRow, DOM.$('td')).innerText = ''; 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); this.addClauseRow(true, clause.field, this.convertToOperatorString(clause.operator), clause.value);
}); });
@@ -182,7 +182,7 @@ export class ProfilerFilterDialog extends Modal {
} }
private filterSession(): void { private filterSession(): void {
this._input.filterSession(this.getFilter()); this._input!.filterSession(this.getFilter());
} }
private saveFilter(): void { private saveFilter(): void {
@@ -222,19 +222,19 @@ export class ProfilerFilterDialog extends Modal {
} }
private addClauseRow(setInitialValue: boolean, field?: string, operator?: string, value?: string): void { 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)) { if (field && !find(columns, x => x === field)) {
return; return;
} }
const row = DOM.append(this._clauseBuilder, DOM.$('tr')); const row = DOM.append(this._clauseBuilder!, DOM.$('tr'));
const clauseId = generateUuid(); const clauseId = generateUuid();
const fieldDropDown = this.createSelectBox(DOM.append(row, DOM.$('td')), columns, columns[0], FieldText); 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 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)); this._register(attachInputBoxStyler(valueText, this._themeService));
const removeCell = DOM.append(row, DOM.$('td')); const removeCell = DOM.append(row, DOM.$('td'));
@@ -259,7 +259,7 @@ export class ProfilerFilterDialog extends Modal {
if (setInitialValue) { if (setInitialValue) {
fieldDropDown.selectWithOptionName(field); fieldDropDown.selectWithOptionName(field);
operatorDropDown.selectWithOptionName(operator); operatorDropDown.selectWithOptionName(operator);
valueText.value = value; valueText.value = value ?? '';
} }
this._clauseRows.push({ this._clauseRows.push({

View File

@@ -29,11 +29,19 @@ class TwoWayMap<T, K> {
this.reverseMap = new Map<K, T>(); this.reverseMap = new Map<K, T>();
} }
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); return this.forwardMap.get(input);
} }
reverseGet(input: K): T { reverseGet(input: K): T | undefined {
return this.reverseMap.get(input); return this.reverseMap.get(input);
} }
@@ -51,7 +59,7 @@ export class ProfilerService implements IProfilerService {
private _idMap = new TwoWayMap<ProfilerSessionID, string>(); private _idMap = new TwoWayMap<ProfilerSessionID, string>();
private _sessionMap = new Map<ProfilerSessionID, IProfilerSession>(); private _sessionMap = new Map<ProfilerSessionID, IProfilerSession>();
private _connectionMap = new Map<ProfilerSessionID, IConnectionProfile>(); private _connectionMap = new Map<ProfilerSessionID, IConnectionProfile>();
private _editColumnDialog: ProfilerColumnEditorDialog; private _editColumnDialog?: ProfilerColumnEditorDialog;
private _memento: any; private _memento: any;
private _context: Memento; private _context: Memento;
@@ -91,68 +99,101 @@ export class ProfilerService implements IProfilerService {
} }
public onMoreRows(params: azdata.ProfilerSessionEvents): void { 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 { 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 { public onProfilerSessionCreated(params: azdata.ProfilerSessionCreatedParams): void {
this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onProfilerSessionCreated(params); if (this._idMap.reverseHas(params.ownerUri)) {
this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)!)!.onProfilerSessionCreated(params);
this.updateMemento(params.ownerUri, { previousSessionName: params.sessionName }); this.updateMemento(params.ownerUri, { previousSessionName: params.sessionName });
} }
public connectSession(id: ProfilerSessionID): Thenable<boolean> {
return this._runAction(id, provider => provider.connectSession(this._idMap.get(id)));
} }
public disconnectSession(id: ProfilerSessionID): Thenable<boolean> { public async connectSession(id: ProfilerSessionID): Promise<boolean> {
return this._runAction(id, provider => provider.disconnectSession(this._idMap.get(id))); if (this._idMap.has(id)) {
return this._runAction(id, provider => provider.connectSession(this._idMap.get(id)!));
}
return false;
} }
public createSession(id: string, createStatement: string, template: azdata.ProfilerSessionTemplate): Thenable<boolean> { public async disconnectSession(id: ProfilerSessionID): Promise<boolean> {
return this._runAction(id, provider => provider.createSession(this._idMap.get(id), createStatement, template)).then(() => { if (this._idMap.has(id)) {
this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); return this._runAction(id, provider => provider.disconnectSession(this._idMap.get(id)!));
}
return false;
}
public async createSession(id: string, createStatement: string, template: azdata.ProfilerSessionTemplate): Promise<boolean> {
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; return true;
}, (reason) => { } catch (reason) {
this._notificationService.error(reason.message); this._notificationService.error(reason.message);
}); return false;
}
}
return false;
} }
public startSession(id: ProfilerSessionID, sessionName: string): Thenable<boolean> { public async startSession(id: ProfilerSessionID, sessionName: string): Promise<boolean> {
if (this._idMap.has(id)) {
this.updateMemento(id, { previousSessionName: sessionName }); this.updateMemento(id, { previousSessionName: sessionName });
return this._runAction(id, provider => provider.startSession(this._idMap.get(id), sessionName)).then(() => { try {
this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); 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; return true;
}, (reason) => { } catch (reason) {
this._notificationService.error(reason.message); this._notificationService.error(reason.message);
}); return false;
}
}
return false;
} }
public pauseSession(id: ProfilerSessionID): Thenable<boolean> { public async pauseSession(id: ProfilerSessionID): Promise<boolean> {
return this._runAction(id, provider => provider.pauseSession(this._idMap.get(id))); if (this._idMap.has(id)) {
return this._runAction(id, provider => provider.pauseSession(this._idMap.get(id)!));
} else {
return false;
}
} }
public stopSession(id: ProfilerSessionID): Thenable<boolean> { public async stopSession(id: ProfilerSessionID): Promise<boolean> {
return this._runAction(id, provider => provider.stopSession(this._idMap.get(id))).then(() => { if (this._idMap.has(id)) {
this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false }); 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; return true;
}, (reason) => { } catch (e) {
// The error won't be actionable to the user, so only log it to console. this._sessionMap.get(this._idMap.reverseGet(id)!)!.onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false });
// In case of error, the state of the UI is not usable, makes more sense to return false;
// 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 }); } else {
}); return false;
}
} }
public getXEventSessions(id: ProfilerSessionID): Thenable<string[]> { public async getXEventSessions(id: ProfilerSessionID): Promise<string[] | undefined> {
return this._runAction(id, provider => provider.getXEventSessions(this._idMap.get(id))).then((r) => { if (this._idMap.get(id)) {
return this._runAction(id, provider => provider.getXEventSessions(this._idMap.get(id)!)).then((r) => {
return r; return r;
}, (reason) => { }, (reason) => {
this._notificationService.error(reason.message); this._notificationService.error(reason.message);
return undefined;
}); });
} }
return undefined;
}
private _runAction<T>(id: ProfilerSessionID, action: (handler: azdata.ProfilerProvider) => Thenable<T>): Thenable<T> { private _runAction<T>(id: ProfilerSessionID, action: (handler: azdata.ProfilerProvider) => Thenable<T>): Thenable<T> {
let handler = this._providers.get(mssqlProviderName); let handler = this._providers.get(mssqlProviderName);
@@ -192,9 +233,9 @@ export class ProfilerService implements IProfilerService {
return undefined; return undefined;
} }
private getMementoKey(ownerUri: string): string { private getMementoKey(ownerUri: string): string | undefined {
let mementoKey = undefined; let mementoKey = undefined;
let connectionProfile: IConnectionProfile = this._connectionMap.get(ownerUri); let connectionProfile = this._connectionMap.get(ownerUri);
if (connectionProfile) { if (connectionProfile) {
mementoKey = connectionProfile.serverName; mementoKey = connectionProfile.serverName;
} }
@@ -219,7 +260,7 @@ export class ProfilerService implements IProfilerService {
} }
this._editColumnDialog.open(input); this._editColumnDialog.open(input);
return Promise.resolve(null); return Promise.resolve();
} }
public launchCreateSessionDialog(input: ProfilerInput): Thenable<void> { public launchCreateSessionDialog(input: ProfilerInput): Thenable<void> {

View File

@@ -23,35 +23,88 @@
// "./vs/code/**/*.ts", // "./vs/code/**/*.ts",
"./vs/editor/**/*.ts", "./vs/editor/**/*.ts",
"./vs/platform/**/*.ts", "./vs/platform/**/*.ts",
// "./vs/workbench/contrib/debug/common/debugProtocol.d.ts", "./vs/workbench/services/**/*.ts",
// "./vs/workbench/services/**/*.ts",
"./sql/base/**/*.ts", "./sql/base/**/*.ts",
"./sql/editor/**/*.ts", "./sql/editor/**/*.ts",
"./sql/platform/**/*.ts", "./sql/platform/**/*.ts",
"./sql/workbench/common/**/*.ts", "./sql/workbench/common/**/*.ts",
"./sql/workbench/services/accountManagement/**/*.ts", "./sql/workbench/services/**/*.ts",
"./sql/workbench/services/admin/**/*.ts", "./sql/workbench/contrib/**/*.ts",
"./sql/workbench/services/assessment/**/*.ts", ],
"./sql/workbench/services/bootstrap/**/*.ts", "exclude": [
// "./sql/workbench/services/connection/**/*.ts", "./sql/workbench/contrib/assessment/**/*.ts", // 3255 errors
"./sql/workbench/services/dashboard/**/*.ts", "./sql/workbench/contrib/azure/**/*.ts", // 118 errors
// "./sql/workbench/services/dialog/**/*.ts", "./sql/workbench/contrib/backup/**/*.ts", // 249 errors
"./sql/workbench/services/editData/**/*.ts", "./sql/workbench/contrib/charts/**/*.ts", // 3253 errors
"./sql/workbench/services/errorMessage/**/*.ts", "./sql/workbench/contrib/commandLine/**/*.ts", // 3276 errors
// "./sql/workbench/services/fileBrowser/**/*.ts", "./sql/workbench/contrib/configuration/**/*.ts", // 2 errors
// "./sql/workbench/services/insights/**/*.ts", "./sql/workbench/contrib/connection/**/*.ts", // 355 errors
"./sql/workbench/services/jobManagement/**/*.ts", "./sql/workbench/contrib/dashboard/**/*.ts", // 1292 errors
"./sql/workbench/services/languageAssociation/**/*.ts", "./sql/workbench/contrib/dataExplorer/**/*.ts", // 3275 errors
// "./sql/workbench/services/notebook/**/*.ts", 201 errors "./sql/workbench/contrib/editData/**/*.ts", // 579 errors
// "./sql/workbench/services/objectExplorer/**/*.ts", 326 errors "./sql/workbench/contrib/editorReplacement/**/*.ts", // 3315 errors
// "./sql/workbench/services/profiler/**/*.ts", 66 errors "./sql/workbench/contrib/extensions/**/*.ts", // 45 errors
"./sql/workbench/services/progress/**/*.ts", "./sql/workbench/contrib/jobManagement/**/*.ts", // 315 errors
// "./sql/workbench/services/query/**/*.ts", "./sql/workbench/contrib/modelView/**/*.ts", // 3253 errors
// "./sql/workbench/services/queryEditor/**/*.ts", "./sql/workbench/contrib/notebook/**/*.ts", // 3740 errors
"./sql/workbench/services/queryHistory/**/*.ts", "./sql/workbench/contrib/objectExplorer/**/*.ts", // 3330 errors
"./sql/workbench/services/resourceProvider/**/*.ts", "./sql/workbench/contrib/preferences/**/*.ts", // 1 errors
// "./sql/workbench/services/restore/**/*.ts", 125 errors "./sql/workbench/contrib/profiler/**/*.ts", // 204 errors
"./sql/workbench/services/serverGroup/**/*.ts", "./sql/workbench/contrib/query/**/*.ts", // 3342 errors
"./sql/workbench/services/tasks/**/*.ts", "./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
] ]
} }