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

@@ -5,16 +5,15 @@
import { CancelablePromise, RunOnceScheduler, createCancelablePromise, disposableTimeout } from 'vs/base/common/async';
import { onUnexpectedError, onUnexpectedExternalError } from 'vs/base/common/errors';
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
import { toDisposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { StableEditorScrollState } from 'vs/editor/browser/core/editorState';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IModelDecorationsChangeAccessor } from 'vs/editor/common/model';
import { CodeLensProviderRegistry, ICodeLensSymbol } from 'vs/editor/common/modes';
import { ICodeLensData, getCodeLensData } from 'vs/editor/contrib/codelens/codelens';
import { CodeLens, CodeLensHelper } from 'vs/editor/contrib/codelens/codelensWidget';
import { CodeLensProviderRegistry, CodeLens } from 'vs/editor/common/modes';
import { CodeLensModel, getCodeLensData, CodeLensItem } from 'vs/editor/contrib/codelens/codelens';
import { CodeLensWidget, CodeLensHelper } from 'vs/editor/contrib/codelens/codelensWidget';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ICodeLensCache } from 'vs/editor/contrib/codelens/codeLensCache';
@@ -25,12 +24,14 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
private _isEnabled: boolean;
private _globalToDispose: IDisposable[];
private _localToDispose: IDisposable[];
private _lenses: CodeLens[];
private _currentFindCodeLensSymbolsPromise: CancelablePromise<ICodeLensData[]> | null;
private _modelChangeCounter: number;
private _currentResolveCodeLensSymbolsPromise: CancelablePromise<any> | null;
private readonly _globalToDispose = new DisposableStore();
private readonly _localToDispose = new DisposableStore();
private _lenses: CodeLensWidget[] = [];
private _currentFindCodeLensSymbolsPromise: CancelablePromise<CodeLensModel> | undefined;
private _oldCodeLensModels = new DisposableStore();
private _currentCodeLensModel: CodeLensModel | undefined;
private _modelChangeCounter: number = 0;
private _currentResolveCodeLensSymbolsPromise: CancelablePromise<any> | undefined;
private _detectVisibleLenses: RunOnceScheduler;
constructor(
@@ -41,41 +42,39 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
) {
this._isEnabled = this._editor.getConfiguration().contribInfo.codeLens;
this._globalToDispose = [];
this._localToDispose = [];
this._lenses = [];
this._currentFindCodeLensSymbolsPromise = null;
this._modelChangeCounter = 0;
this._globalToDispose.push(this._editor.onDidChangeModel(() => this._onModelChange()));
this._globalToDispose.push(this._editor.onDidChangeModelLanguage(() => this._onModelChange()));
this._globalToDispose.push(this._editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => {
let prevIsEnabled = this._isEnabled;
this._globalToDispose.add(this._editor.onDidChangeModel(() => this._onModelChange()));
this._globalToDispose.add(this._editor.onDidChangeModelLanguage(() => this._onModelChange()));
this._globalToDispose.add(this._editor.onDidChangeConfiguration(() => {
const prevIsEnabled = this._isEnabled;
this._isEnabled = this._editor.getConfiguration().contribInfo.codeLens;
if (prevIsEnabled !== this._isEnabled) {
this._onModelChange();
}
}));
this._globalToDispose.push(CodeLensProviderRegistry.onDidChange(this._onModelChange, this));
this._globalToDispose.add(CodeLensProviderRegistry.onDidChange(this._onModelChange, this));
this._onModelChange();
}
dispose(): void {
this._localDispose();
this._globalToDispose = dispose(this._globalToDispose);
this._globalToDispose.dispose();
this._oldCodeLensModels.dispose();
dispose(this._currentCodeLensModel);
}
private _localDispose(): void {
if (this._currentFindCodeLensSymbolsPromise) {
this._currentFindCodeLensSymbolsPromise.cancel();
this._currentFindCodeLensSymbolsPromise = null;
this._currentFindCodeLensSymbolsPromise = undefined;
this._modelChangeCounter++;
}
if (this._currentResolveCodeLensSymbolsPromise) {
this._currentResolveCodeLensSymbolsPromise.cancel();
this._currentResolveCodeLensSymbolsPromise = null;
this._currentResolveCodeLensSymbolsPromise = undefined;
}
this._localToDispose = dispose(this._localToDispose);
this._localToDispose.clear();
this._oldCodeLensModels.clear();
dispose(this._currentCodeLensModel);
}
getId(): string {
@@ -104,7 +103,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
// no provider -> return but check with
// cached lenses. they expire after 30 seconds
if (cachedLenses) {
this._localToDispose.push(disposableTimeout(() => {
this._localToDispose.add(disposableTimeout(() => {
const cachedLensesNow = this._codeLensCache.get(model);
if (cachedLenses === cachedLensesNow) {
this._codeLensCache.delete(model);
@@ -118,7 +117,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
for (const provider of CodeLensProviderRegistry.all(model)) {
if (typeof provider.onDidChange === 'function') {
let registration = provider.onDidChange(() => scheduler.schedule());
this._localToDispose.push(registration);
this._localToDispose.add(registration);
}
}
@@ -136,18 +135,26 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
this._currentFindCodeLensSymbolsPromise.then(result => {
if (counterValue === this._modelChangeCounter) { // only the last one wins
if (this._currentCodeLensModel) {
this._oldCodeLensModels.add(this._currentCodeLensModel);
}
this._currentCodeLensModel = result;
// cache model to reduce flicker
this._codeLensCache.put(model, result);
// render lenses
this._renderCodeLensSymbols(result);
this._detectVisibleLenses.schedule();
}
}, onUnexpectedError);
}, 250);
this._localToDispose.push(scheduler);
this._localToDispose.push(this._detectVisibleLenses);
this._localToDispose.push(this._editor.onDidChangeModelContent((e) => {
this._editor.changeDecorations((changeAccessor) => {
this._editor.changeViewZones((viewAccessor) => {
let toDispose: CodeLens[] = [];
this._localToDispose.add(scheduler);
this._localToDispose.add(this._detectVisibleLenses);
this._localToDispose.add(this._editor.onDidChangeModelContent(() => {
this._editor.changeDecorations(decorationsAccessor => {
this._editor.changeViewZones(viewZonesAccessor => {
let toDispose: CodeLensWidget[] = [];
let lastLensLineNumber: number = -1;
this._lenses.forEach((lens) => {
@@ -157,17 +164,17 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
toDispose.push(lens);
} else {
lens.update(viewAccessor);
lens.update(viewZonesAccessor);
lastLensLineNumber = lens.getLineNumber();
}
});
let helper = new CodeLensHelper();
toDispose.forEach((l) => {
l.dispose(helper, viewAccessor);
l.dispose(helper, viewZonesAccessor);
this._lenses.splice(this._lenses.indexOf(l), 1);
});
helper.commit(changeAccessor);
helper.commit(decorationsAccessor);
});
});
@@ -176,20 +183,20 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
// Ask for all references again
scheduler.schedule();
}));
this._localToDispose.push(this._editor.onDidScrollChange(e => {
this._localToDispose.add(this._editor.onDidScrollChange(e => {
if (e.scrollTopChanged && this._lenses.length > 0) {
this._detectVisibleLenses.schedule();
}
}));
this._localToDispose.push(this._editor.onDidLayoutChange(e => {
this._localToDispose.add(this._editor.onDidLayoutChange(() => {
this._detectVisibleLenses.schedule();
}));
this._localToDispose.push(toDisposable(() => {
this._localToDispose.add(toDisposable(() => {
if (this._editor.getModel()) {
const scrollState = StableEditorScrollState.capture(this._editor);
this._editor.changeDecorations((changeAccessor) => {
this._editor.changeViewZones((accessor) => {
this._disposeAllLenses(changeAccessor, accessor);
this._editor.changeDecorations(decorationsAccessor => {
this._editor.changeViewZones(viewZonesAccessor => {
this._disposeAllLenses(decorationsAccessor, viewZonesAccessor);
});
});
scrollState.restore(this._editor);
@@ -198,14 +205,14 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
this._disposeAllLenses(undefined, undefined);
}
}));
this._localToDispose.push(this._editor.onDidChangeConfiguration(e => {
this._localToDispose.add(this._editor.onDidChangeConfiguration(e => {
if (e.fontInfo) {
for (const lens of this._lenses) {
lens.updateHeight();
}
}
}));
this._localToDispose.push(this._editor.onMouseUp(e => {
this._localToDispose.add(this._editor.onMouseUp(e => {
if (e.target.type === editorBrowser.MouseTargetType.CONTENT_WIDGET && e.target.element && e.target.element.tagName === 'A') {
for (const lens of this._lenses) {
let command = lens.getCommand(e.target.element as HTMLLinkElement);
@@ -228,16 +235,16 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
this._lenses = [];
}
private _renderCodeLensSymbols(symbols: ICodeLensData[]): void {
private _renderCodeLensSymbols(symbols: CodeLensModel): void {
if (!this._editor.hasModel()) {
return;
}
let maxLineNumber = this._editor.getModel().getLineCount();
let groups: ICodeLensData[][] = [];
let lastGroup: ICodeLensData[] | undefined;
let groups: CodeLensItem[][] = [];
let lastGroup: CodeLensItem[] | undefined;
for (let symbol of symbols) {
for (let symbol of symbols.lenses) {
let line = symbol.symbol.range.startLineNumber;
if (line < 1 || line > maxLineNumber) {
// invalid code lens
@@ -254,10 +261,12 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
const scrollState = StableEditorScrollState.capture(this._editor);
this._editor.changeDecorations((changeAccessor) => {
this._editor.changeViewZones((accessor) => {
this._editor.changeDecorations(decorationsAccessor => {
this._editor.changeViewZones(viewZoneAccessor => {
let codeLensIndex = 0, groupsIndex = 0, helper = new CodeLensHelper();
const helper = new CodeLensHelper();
let codeLensIndex = 0;
let groupsIndex = 0;
while (groupsIndex < groups.length && codeLensIndex < this._lenses.length) {
@@ -265,14 +274,14 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
let codeLensLineNumber = this._lenses[codeLensIndex].getLineNumber();
if (codeLensLineNumber < symbolsLineNumber) {
this._lenses[codeLensIndex].dispose(helper, accessor);
this._lenses[codeLensIndex].dispose(helper, viewZoneAccessor);
this._lenses.splice(codeLensIndex, 1);
} else if (codeLensLineNumber === symbolsLineNumber) {
this._lenses[codeLensIndex].updateCodeLensSymbols(groups[groupsIndex], helper);
groupsIndex++;
codeLensIndex++;
} else {
this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, () => this._detectVisibleLenses.schedule()));
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], this._editor, helper, viewZoneAccessor, () => this._detectVisibleLenses.schedule()));
codeLensIndex++;
groupsIndex++;
}
@@ -280,17 +289,17 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
// Delete extra code lenses
while (codeLensIndex < this._lenses.length) {
this._lenses[codeLensIndex].dispose(helper, accessor);
this._lenses[codeLensIndex].dispose(helper, viewZoneAccessor);
this._lenses.splice(codeLensIndex, 1);
}
// Create extra symbols
while (groupsIndex < groups.length) {
this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, () => this._detectVisibleLenses.schedule()));
this._lenses.push(new CodeLensWidget(groups[groupsIndex], this._editor, helper, viewZoneAccessor, () => this._detectVisibleLenses.schedule()));
groupsIndex++;
}
helper.commit(changeAccessor);
helper.commit(decorationsAccessor);
});
});
@@ -300,7 +309,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
private _onViewportChanged(): void {
if (this._currentResolveCodeLensSymbolsPromise) {
this._currentResolveCodeLensSymbolsPromise.cancel();
this._currentResolveCodeLensSymbolsPromise = null;
this._currentResolveCodeLensSymbolsPromise = undefined;
}
const model = this._editor.getModel();
@@ -308,8 +317,8 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
return;
}
const toResolve: ICodeLensData[][] = [];
const lenses: CodeLens[] = [];
const toResolve: CodeLensItem[][] = [];
const lenses: CodeLensWidget[] = [];
this._lenses.forEach((lens) => {
const request = lens.computeIfNecessary(model);
if (request) {
@@ -326,7 +335,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
const promises = toResolve.map((request, i) => {
const resolvedSymbols = new Array<ICodeLensSymbol | undefined | null>(request.length);
const resolvedSymbols = new Array<CodeLens | undefined | null>(request.length);
const promises = request.map((request, i) => {
if (!request.symbol.command && typeof request.provider.resolveCodeLens === 'function') {
return Promise.resolve(request.provider.resolveCodeLens(model, request.symbol, token)).then(symbol => {
@@ -339,7 +348,9 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
});
return Promise.all(promises).then(() => {
lenses[i].updateCommands(resolvedSymbols);
if (!token.isCancellationRequested) {
lenses[i].updateCommands(resolvedSymbols);
}
});
});
@@ -347,10 +358,11 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
});
this._currentResolveCodeLensSymbolsPromise.then(() => {
this._currentResolveCodeLensSymbolsPromise = null;
}).catch(err => {
this._currentResolveCodeLensSymbolsPromise = null;
onUnexpectedError(err);
this._oldCodeLensModels.clear(); // dispose old models once we have updated the UI with the current model
this._currentResolveCodeLensSymbolsPromise = undefined;
}, err => {
onUnexpectedError(err); // can also be cancellation!
this._currentResolveCodeLensSymbolsPromise = undefined;
});
}
}