Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -4,14 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/flavorStatus';
import { $, append, show, hide } from 'vs/base/browser/dom';
import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { Disposable } from 'vs/base/common/lifecycle';
import { IEditorCloseEvent } from 'vs/workbench/common/editor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Action } from 'vs/base/common/actions';
import errors = require('vs/base/common/errors');
import { getCodeEditor } from 'vs/editor/browser/editorBrowser';
import * as nls from 'vs/nls';
@@ -24,6 +20,8 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
export interface ISqlProviderEntry extends IQuickPickItem {
providerId: string;
@@ -59,53 +57,54 @@ class SqlProviderEntry implements ISqlProviderEntry {
}
// Shows SQL flavor status in the editor
export class SqlFlavorStatusbarItem implements IStatusbarItem {
export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchContribution {
private static readonly ID = 'status.query.flavor';
private statusItem: IStatusbarEntryAccessor;
private _element: HTMLElement;
private _flavorElement: HTMLElement;
private _sqlStatusEditors: { [editorUri: string]: SqlProviderEntry };
private _toDispose: IDisposable[];
constructor(
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IEditorService private _editorService: EditorServiceImpl,
@IInstantiationService private _instantiationService: IInstantiationService,
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IEditorService private readonly editorService: EditorServiceImpl,
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService
) {
super();
this._sqlStatusEditors = {};
}
public render(container: HTMLElement): IDisposable {
this._element = append(container, $('.query-statusbar-group'));
this._flavorElement = append(this._element, $('a.editor-status-selection'));
this._flavorElement.title = nls.localize('changeProvider', "Change SQL language provider");
this._flavorElement.onclick = () => this._onSelectionClick();
hide(this._flavorElement);
this.statusItem = this._register(
this.statusbarService.addEntry({
text: nls.localize('changeProvider', "Change SQL language provider"),
this._toDispose = [];
this._toDispose.push(
this._connectionManagementService.onLanguageFlavorChanged((changeParams: DidChangeLanguageFlavorParams) => this._onFlavorChanged(changeParams)),
this._editorService.onDidVisibleEditorsChange(() => this._onEditorsChanged()),
this._editorService.onDidCloseEditor(event => this._onEditorClosed(event))
},
SqlFlavorStatusbarItem.ID,
nls.localize('status.query.flavor', "SQL Language Flavor"),
StatusbarAlignment.RIGHT, 100)
);
return combinedDisposable(this._toDispose);
this._register(this.connectionManagementService.onLanguageFlavorChanged((changeParams: DidChangeLanguageFlavorParams) => this._onFlavorChanged(changeParams)));
this._register(this.editorService.onDidVisibleEditorsChange(() => this._onEditorsChanged()));
this._register(this.editorService.onDidCloseEditor(event => this._onEditorClosed(event)));
}
private _onSelectionClick() {
const action = this._instantiationService.createInstance(ChangeFlavorAction, ChangeFlavorAction.ID, ChangeFlavorAction.LABEL);
private hide() {
this.statusbarService.updateEntryVisibility(SqlFlavorStatusbarItem.ID, false);
}
action.run().then(null, errors.onUnexpectedError);
action.dispose();
private show() {
this.statusbarService.updateEntryVisibility(SqlFlavorStatusbarItem.ID, true);
}
private _onEditorClosed(event: IEditorCloseEvent): void {
let uri = WorkbenchUtils.getEditorUri(event.editor);
if (uri && uri in this._sqlStatusEditors) {
// If active editor is being closed, hide the query status.
let activeEditor = this._editorService.activeControl;
let activeEditor = this.editorService.activeControl;
if (activeEditor) {
let currentUri = WorkbenchUtils.getEditorUri(activeEditor.input);
if (uri === currentUri) {
hide(this._flavorElement);
this.hide();
}
}
// note: intentionally not removing language flavor. This is preserved across close/open events at present
@@ -114,7 +113,7 @@ export class SqlFlavorStatusbarItem implements IStatusbarItem {
}
private _onEditorsChanged(): void {
let activeEditor = this._editorService.activeControl;
let activeEditor = this.editorService.activeControl;
if (activeEditor) {
let uri = WorkbenchUtils.getEditorUri(activeEditor.input);
@@ -122,10 +121,10 @@ export class SqlFlavorStatusbarItem implements IStatusbarItem {
if (uri) {
this._showStatus(uri);
} else {
hide(this._flavorElement);
this.hide();
}
} else {
hide(this._flavorElement);
this.hide();
}
}
@@ -145,17 +144,17 @@ export class SqlFlavorStatusbarItem implements IStatusbarItem {
// Show/hide query status for active editor
private _showStatus(uri: string): void {
let activeEditor = this._editorService.activeControl;
let activeEditor = this.editorService.activeControl;
if (activeEditor) {
let currentUri = WorkbenchUtils.getEditorUri(activeEditor.input);
if (uri === currentUri) {
let flavor: SqlProviderEntry = this._sqlStatusEditors[uri];
if (flavor) {
this._flavorElement.textContent = flavor.label;
this.statusItem.update({ text: flavor.label });
} else {
this._flavorElement.textContent = SqlProviderEntry.getDefaultLabel();
this.statusItem.update({ text: SqlProviderEntry.getDefaultLabel() });
}
show(this._flavorElement);
this.show();
}
}
}

View File

@@ -29,6 +29,11 @@ import * as gridActions from 'sql/workbench/parts/grid/views/gridActions';
import * as gridCommands from 'sql/workbench/parts/grid/views/gridCommands';
import * as Constants from 'sql/workbench/parts/query/common/constants';
import { localize } from 'vs/nls';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { TimeElapsedStatusBarContributions, RowCountStatusBarContributions, QueryStatusStatusBarContributions } from 'sql/workbench/parts/query/browser/statusBarItems';
import { SqlFlavorStatusbarItem } from 'sql/workbench/parts/query/browser/flavorStatus';
const gridCommandsWeightBonus = 100; // give our commands a little bit more weight over other default list/tree commands
@@ -514,3 +519,10 @@ configurationRegistry.registerConfiguration({
'type': 'object',
'properties': registryProperties
});
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(TimeElapsedStatusBarContributions, LifecyclePhase.Restored);
workbenchRegistry.registerWorkbenchContribution(RowCountStatusBarContributions, LifecyclePhase.Restored);
workbenchRegistry.registerWorkbenchContribution(QueryStatusStatusBarContributions, LifecyclePhase.Restored);
workbenchRegistry.registerWorkbenchContribution(SqlFlavorStatusbarItem, LifecyclePhase.Restored);

View File

@@ -184,7 +184,7 @@ export class QueryEditor extends BaseEditor {
this.setTaskbarContent();
this._toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectedKeys.includes('workbench.enablePreviewFeatures')) {
this.setTaskbarContent();
}

View File

@@ -1,117 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { $, append, show, hide } from 'vs/base/browser/dom';
import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { IEditorCloseEvent } from 'vs/workbench/common/editor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import * as LocalizedConstants from 'sql/workbench/parts/query/common/localizedConstants';
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
// Query execution status
enum QueryExecutionStatus {
Executing,
Completed
}
// Shows query status in the editor
export class QueryStatusbarItem implements IStatusbarItem {
private _element: HTMLElement;
private _queryElement: HTMLElement;
private _queryStatusEditors: { [editorUri: string]: QueryExecutionStatus };
private _toDispose: IDisposable[];
constructor(
@IQueryModelService private _queryModelService: IQueryModelService,
@IEditorService private _editorService: EditorServiceImpl
) {
this._queryStatusEditors = {};
}
public render(container: HTMLElement): IDisposable {
this._element = append(container, $('.query-statusbar-group'));
this._queryElement = append(this._element, $('div.query-statusbar-item'));
hide(this._queryElement);
this._toDispose = [];
this._toDispose.push(
this._queryModelService.onRunQueryStart((uri: string) => this._onRunQueryStart(uri)),
this._queryModelService.onRunQueryComplete((uri: string) => this._onRunQueryComplete(uri)),
this._editorService.onDidVisibleEditorsChange(() => this._onEditorsChanged()),
this._editorService.onDidCloseEditor(event => this._onEditorClosed(event))
);
return combinedDisposable(this._toDispose);
}
private _onEditorClosed(event: IEditorCloseEvent): void {
let uri = WorkbenchUtils.getEditorUri(event.editor);
if (uri && uri in this._queryStatusEditors) {
// If active editor is being closed, hide the query status.
let activeEditor = this._editorService.activeControl;
if (activeEditor) {
let currentUri = WorkbenchUtils.getEditorUri(activeEditor.input);
if (uri === currentUri) {
hide(this._queryElement);
}
}
delete this._queryStatusEditors[uri];
}
}
private _onEditorsChanged(): void {
let activeEditor = this._editorService.activeControl;
if (activeEditor) {
let uri = WorkbenchUtils.getEditorUri(activeEditor.input);
// Show active editor's query status
if (uri && uri in this._queryStatusEditors) {
this._showStatus(uri);
} else {
hide(this._queryElement);
}
} else {
hide(this._queryElement);
}
}
private _onRunQueryStart(uri: string): void {
this._updateStatus(uri, QueryExecutionStatus.Executing);
}
private _onRunQueryComplete(uri: string): void {
this._updateStatus(uri, QueryExecutionStatus.Completed);
}
// Update query status for the editor
private _updateStatus(uri: string, newStatus: QueryExecutionStatus) {
if (uri) {
this._queryStatusEditors[uri] = newStatus;
this._showStatus(uri);
}
}
// Show/hide query status for active editor
private _showStatus(uri: string): void {
let activeEditor = this._editorService.activeControl;
if (activeEditor) {
let currentUri = WorkbenchUtils.getEditorUri(activeEditor.input);
if (uri === currentUri) {
switch (this._queryStatusEditors[uri]) {
case QueryExecutionStatus.Executing:
this._queryElement.textContent = LocalizedConstants.msgStatusRunQueryInProgress;
show(this._queryElement);
break;
default:
hide(this._queryElement);
}
}
}
}
}

View File

@@ -1,99 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import QueryRunner from 'sql/platform/query/common/queryRunner';
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorCloseEvent } from 'vs/workbench/common/editor';
import { append, $, hide, show } from 'vs/base/browser/dom';
import * as nls from 'vs/nls';
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
export class RowCountStatusBarItem implements IStatusbarItem {
private _element: HTMLElement;
private _flavorElement: HTMLElement;
private dispose: IDisposable[];
constructor(
@IEditorService private _editorService: EditorServiceImpl,
@IQueryModelService private _queryModelService: IQueryModelService
) { }
render(container: HTMLElement): IDisposable {
let disposables = [
this._editorService.onDidVisibleEditorsChange(() => this._onEditorsChanged()),
this._editorService.onDidCloseEditor(event => this._onEditorClosed(event))
];
this._element = append(container, $('.query-statusbar-group'));
this._flavorElement = append(this._element, $('.editor-status-selection'));
this._flavorElement.title = nls.localize('rowStatus', "Row Count");
hide(this._flavorElement);
this._showStatus();
return combinedDisposable(disposables);
}
private _onEditorsChanged() {
this._showStatus();
}
private _onEditorClosed(event: IEditorCloseEvent) {
hide(this._flavorElement);
}
// Show/hide query status for active editor
private _showStatus(): void {
hide(this._flavorElement);
dispose(this.dispose);
this.dispose = [];
let activeEditor = this._editorService.activeControl;
if (activeEditor) {
let currentUri = WorkbenchUtils.getEditorUri(activeEditor.input);
if (currentUri) {
let queryRunner = this._queryModelService.getQueryRunner(currentUri);
if (queryRunner) {
if (queryRunner.hasCompleted) {
this._displayValue(queryRunner);
}
this.dispose.push(queryRunner.onQueryEnd(e => {
this._displayValue(queryRunner);
}));
this.dispose.push(queryRunner.onQueryStart(e => {
hide(this._flavorElement);
}));
} else {
this.dispose.push(this._queryModelService.onRunQueryComplete(e => {
if (e === currentUri) {
this._displayValue(this._queryModelService.getQueryRunner(currentUri));
}
}));
this.dispose.push(this._queryModelService.onRunQueryStart(e => {
if (e === currentUri) {
hide(this._flavorElement);
}
}));
}
}
}
}
private _displayValue(runner: QueryRunner) {
let rowCount = runner.batchSets.reduce((p, c) => {
return p + c.resultSetSummaries.reduce((rp, rc) => {
return rp + rc.rowCount;
}, 0);
}, 0);
this._flavorElement.innerText = nls.localize('rowCount', "{0} rows", rowCount);
show(this._flavorElement);
}
}

View File

@@ -0,0 +1,238 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import { IntervalTimer } from 'vs/base/common/async';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { localize } from 'vs/nls';
import { QueryInput } from 'sql/workbench/parts/query/common/queryInput';
import QueryRunner from 'sql/platform/query/common/queryRunner';
import { parseNumAsTimeString } from 'sql/platform/connection/common/utils';
import { Event } from 'vs/base/common/event';
export class TimeElapsedStatusBarContributions extends Disposable implements IWorkbenchContribution {
private static readonly ID = 'status.query.timeElapsed';
private statusItem: IStatusbarEntryAccessor;
private intervalTimer = new IntervalTimer();
private disposable = this._register(new DisposableStore());
constructor(
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IEditorService private readonly editorService: IEditorService,
@IQueryModelService private readonly queryModelService: IQueryModelService
) {
super();
this.statusItem = this._register(
this.statusbarService.addEntry({
text: '',
},
TimeElapsedStatusBarContributions.ID,
localize('status.query.timeElapsed', "Time Elapsed"),
StatusbarAlignment.RIGHT, 100)
);
this._register(editorService.onDidActiveEditorChange(this.update, this));
this.update();
}
private hide() {
this.statusbarService.updateEntryVisibility(TimeElapsedStatusBarContributions.ID, false);
}
private show() {
this.statusbarService.updateEntryVisibility(TimeElapsedStatusBarContributions.ID, true);
}
private update() {
this.intervalTimer.cancel();
this.disposable.clear();
this.hide();
const activeInput = this.editorService.activeEditor;
if (activeInput && activeInput instanceof QueryInput && activeInput.uri) {
const uri = activeInput.uri;
const runner = this.queryModelService.getQueryRunner(uri);
if (runner) {
if (runner.hasCompleted || runner.isExecuting) {
this._displayValue(runner);
}
this.disposable.add(runner.onQueryStart(e => {
this._displayValue(runner);
}));
this.disposable.add(runner.onQueryEnd(e => {
this._displayValue(runner);
}));
} else {
this.disposable.add(this.queryModelService.onRunQueryStart(e => {
if (e === uri) {
this._displayValue(this.queryModelService.getQueryRunner(uri));
}
}));
this.disposable.add(this.queryModelService.onRunQueryComplete(e => {
if (e === uri) {
this._displayValue(this.queryModelService.getQueryRunner(uri));
}
}));
}
}
}
private _displayValue(runner: QueryRunner) {
this.intervalTimer.cancel();
if (runner.isExecuting) {
this.intervalTimer.cancelAndSet(() => {
const value = runner.queryStartTime ? Date.now() - runner.queryStartTime.getTime() : 0;
this.statusItem.update({
text: parseNumAsTimeString(value, false)
});
}, 1000);
const value = runner.queryStartTime ? Date.now() - runner.queryStartTime.getTime() : 0;
this.statusItem.update({
text: parseNumAsTimeString(value, false)
});
} else {
const value = runner.queryStartTime && runner.queryEndTime
? runner.queryEndTime.getTime() - runner.queryStartTime.getTime() : 0;
this.statusItem.update({
text: parseNumAsTimeString(value, false)
});
}
this.show();
}
}
export class RowCountStatusBarContributions extends Disposable implements IWorkbenchContribution {
private static readonly ID = 'status.query.rowCount';
private statusItem: IStatusbarEntryAccessor;
private disposable = this._register(new DisposableStore());
constructor(
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IEditorService private readonly editorService: IEditorService,
@IQueryModelService private readonly queryModelService: IQueryModelService
) {
super();
this.statusItem = this._register(
this.statusbarService.addEntry({
text: '',
},
RowCountStatusBarContributions.ID,
localize('status.query.rowCount', "Row Count"),
StatusbarAlignment.RIGHT, 100)
);
this._register(editorService.onDidActiveEditorChange(this.update, this));
this.update();
}
private hide() {
this.statusbarService.updateEntryVisibility(RowCountStatusBarContributions.ID, false);
}
private show() {
this.statusbarService.updateEntryVisibility(RowCountStatusBarContributions.ID, true);
}
private update() {
this.disposable.clear();
this.hide();
const activeInput = this.editorService.activeEditor;
if (activeInput && activeInput instanceof QueryInput && activeInput.uri) {
const uri = activeInput.uri;
const runner = this.queryModelService.getQueryRunner(uri);
if (runner) {
if (runner.hasCompleted || runner.isExecuting) {
this._displayValue(runner);
}
this.disposable.add(runner.onQueryStart(e => {
this._displayValue(runner);
}));
this.disposable.add(runner.onQueryEnd(e => {
this._displayValue(runner);
}));
} else {
this.disposable.add(this.queryModelService.onRunQueryStart(e => {
if (e === uri) {
this._displayValue(this.queryModelService.getQueryRunner(uri));
}
}));
this.disposable.add(this.queryModelService.onRunQueryComplete(e => {
if (e === uri) {
this._displayValue(this.queryModelService.getQueryRunner(uri));
}
}));
}
}
}
private _displayValue(runner: QueryRunner) {
const rowCount = runner.batchSets.reduce((p, c) => {
return p + c.resultSetSummaries.reduce((rp, rc) => {
return rp + rc.rowCount;
}, 0);
}, 0);
const text = localize('rowCount', "{0} rows", rowCount);
this.statusItem.update({ text });
this.show();
}
}
export class QueryStatusStatusBarContributions extends Disposable implements IWorkbenchContribution {
private static readonly ID = 'status.query.status';
private visisbleUri: string | undefined;
constructor(
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IEditorService private readonly editorService: IEditorService,
@IQueryModelService private readonly queryModelService: IQueryModelService
) {
super();
this._register(
this.statusbarService.addEntry({
text: localize('query.status.executing', 'Executing query...'),
},
QueryStatusStatusBarContributions.ID,
localize('status.query.status', "Execution Status"),
StatusbarAlignment.RIGHT, 100)
);
this._register(Event.filter(this.queryModelService.onRunQueryStart, uri => uri === this.visisbleUri)(this.update, this));
this._register(Event.filter(this.queryModelService.onRunQueryComplete, uri => uri === this.visisbleUri)(this.update, this));
this._register(this.editorService.onDidActiveEditorChange(this.update, this));
this.update();
}
private update() {
this.hide();
this.visisbleUri = undefined;
const activeInput = this.editorService.activeEditor;
if (activeInput && activeInput instanceof QueryInput && activeInput.uri) {
this.visisbleUri = activeInput.uri;
const runner = this.queryModelService.getQueryRunner(this.visisbleUri);
if (runner && runner.isExecuting) {
this.show();
}
}
}
private hide() {
this.statusbarService.updateEntryVisibility(QueryStatusStatusBarContributions.ID, false);
}
private show() {
this.statusbarService.updateEntryVisibility(QueryStatusStatusBarContributions.ID, true);
}
}

View File

@@ -1,112 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import QueryRunner from 'sql/platform/query/common/queryRunner';
import { parseNumAsTimeString } from 'sql/platform/connection/common/utils';
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorCloseEvent } from 'vs/workbench/common/editor';
import { append, $, hide, show } from 'vs/base/browser/dom';
import * as nls from 'vs/nls';
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { IntervalTimer } from 'vs/base/common/async';
export class TimeElapsedStatusBarItem implements IStatusbarItem {
private _element: HTMLElement;
private _flavorElement: HTMLElement;
private dispose: IDisposable[] = [];
private intervalTimer = new IntervalTimer();
constructor(
@IEditorService private _editorService: EditorServiceImpl,
@IQueryModelService private _queryModelService: IQueryModelService
) { }
render(container: HTMLElement): IDisposable {
let disposables = [
this._editorService.onDidVisibleEditorsChange(() => this._onEditorsChanged()),
this._editorService.onDidCloseEditor(event => this._onEditorClosed(event))
];
this._element = append(container, $('.query-statusbar-group'));
this._flavorElement = append(this._element, $('.editor-status-selection'));
this._flavorElement.title = nls.localize('timeElapsed', "Time Elapsed");
hide(this._flavorElement);
this._showStatus();
return combinedDisposable(disposables);
}
private _onEditorsChanged() {
this._showStatus();
}
private _onEditorClosed(event: IEditorCloseEvent) {
hide(this._flavorElement);
}
// Show/hide query status for active editor
private _showStatus(): void {
this.intervalTimer.cancel();
hide(this._flavorElement);
dispose(this.dispose);
this._flavorElement.innerText = '';
this.dispose = [];
let activeEditor = this._editorService.activeControl;
if (activeEditor) {
let currentUri = WorkbenchUtils.getEditorUri(activeEditor.input);
if (currentUri) {
let queryRunner = this._queryModelService.getQueryRunner(currentUri);
if (queryRunner) {
if (queryRunner.hasCompleted || queryRunner.isExecuting) {
this._displayValue(queryRunner);
}
this.dispose.push(queryRunner.onQueryStart(e => {
this._displayValue(queryRunner);
}));
this.dispose.push(queryRunner.onQueryEnd(e => {
this._displayValue(queryRunner);
}));
} else {
this.dispose.push(this._queryModelService.onRunQueryStart(e => {
if (e === currentUri) {
this._displayValue(this._queryModelService.getQueryRunner(currentUri));
}
}));
this.dispose.push(this._queryModelService.onRunQueryComplete(e => {
if (e === currentUri) {
this._displayValue(this._queryModelService.getQueryRunner(currentUri));
}
}));
}
}
}
}
private _displayValue(runner: QueryRunner) {
this.intervalTimer.cancel();
if (runner.isExecuting) {
this.intervalTimer.cancelAndSet(() => {
let value = runner.queryStartTime ? Date.now() - runner.queryStartTime.getTime() : 0;
this._flavorElement.innerText = parseNumAsTimeString(value, false);
}, 1000);
let value = runner.queryStartTime ? Date.now() - runner.queryStartTime.getTime() : 0;
this._flavorElement.innerText = parseNumAsTimeString(value, false);
} else {
let value = runner.queryStartTime && runner.queryEndTime
? runner.queryEndTime.getTime() - runner.queryStartTime.getTime() : 0;
this._flavorElement.innerText = parseNumAsTimeString(value, false);
}
show(this._flavorElement);
}
}

View File

@@ -210,6 +210,13 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
public getResource(): URI { return this._sql.getResource(); }
public getEncoding(): string { return this._sql.getEncoding(); }
public suggestFileName(): string { return this._sql.suggestFileName(); }
hasBackup(): boolean {
if (this.sql) {
return this.sql.hasBackup();
}
return false;
}
public getName(longForm?: boolean): string {
if (this._configurationService.getValue('sql.showConnectionInfoInTitle')) {