提交 28cb90be 编写于 作者: J Johannes Rieken

chore - ES6, use for-of instead of forEach

上级 a1feacf5
......@@ -440,14 +440,14 @@ class LeakageMonitor {
this._warnCountdown = threshold * 0.5;
// find most frequent listener and print warning
let topStack: string;
let topStack: string | undefined;
let topCount: number = 0;
this._stacks.forEach((count, stack) => {
for (const [stack, count] of this._stacks) {
if (!topStack || topCount < count) {
topStack = stack;
topCount = count;
}
});
}
console.warn(`[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`);
console.warn(topStack!);
......
......@@ -96,7 +96,7 @@ export class CodeLensCache implements ICodeLensCache {
private _serialize(): string {
const data: Record<string, ISerializedCacheData> = Object.create(null);
this._cache.forEach((value, key) => {
for (const [key, value] of this._cache) {
const lines = new Set<number>();
for (const d of value.data.lenses) {
lines.add(d.symbol.range.startLineNumber);
......@@ -105,7 +105,7 @@ export class CodeLensCache implements ICodeLensCache {
lineCount: value.lineCount,
lines: [...lines.values()]
};
});
}
return JSON.stringify(data);
}
......
......@@ -111,19 +111,21 @@ class DecorationsManager implements IDisposable {
return;
}
this._decorations.forEach((reference, decorationId) => {
for (let [decorationId, reference] of this._decorations) {
const newRange = model.getDecorationRange(decorationId);
if (!newRange) {
return;
continue;
}
let ignore = false;
if (Range.equalsRange(newRange, reference.range)) {
return;
continue;
} else if (Range.spansMultipleLines(newRange)) {
}
if (Range.spansMultipleLines(newRange)) {
ignore = true;
} else {
......@@ -141,7 +143,7 @@ class DecorationsManager implements IDisposable {
} else {
reference.range = newRange;
}
});
}
for (let i = 0, len = toRemove.length; i < len; i++) {
this._decorations.delete(toRemove[i]);
......@@ -150,11 +152,7 @@ class DecorationsManager implements IDisposable {
}
removeDecorations(): void {
let toRemove: string[] = [];
this._decorations.forEach((value, key) => {
toRemove.push(key);
});
this._editor.deltaDecorations(toRemove, []);
this._editor.deltaDecorations([...this._decorations.keys()], []);
this._decorations.clear();
}
}
......
......@@ -198,7 +198,7 @@ class EditorState {
dispose(): void {
this._disposables.dispose();
this._onDidChange.dispose();
this._listener.forEach(dispose);
dispose(this._listener.values());
}
private _onDidAddEditor(editor: ICodeEditor): void {
......
......@@ -64,9 +64,7 @@ export class OneSnippet {
dispose(): void {
if (this._placeholderDecorations) {
let toRemove: string[] = [];
this._placeholderDecorations.forEach(handle => toRemove.push(handle));
this._editor.deltaDecorations(toRemove, []);
this._editor.deltaDecorations([...this._placeholderDecorations.values()], []);
}
this._placeholderGroups.length = 0;
}
......@@ -169,11 +167,11 @@ export class OneSnippet {
// change stickness to never grow when typing at its edges
// so that in-active tabstops never grow
this._placeholderDecorations!.forEach((id, placeholder) => {
for (const [placeholder, id] of this._placeholderDecorations!) {
if (!activePlaceholders.has(placeholder)) {
accessor.changeDecorationOptions(id, placeholder.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive);
}
});
}
return selections;
})!;
......@@ -304,14 +302,14 @@ export class OneSnippet {
public getEnclosingRange(): Range | undefined {
let result: Range | undefined;
const model = this._editor.getModel();
this._placeholderDecorations!.forEach((decorationId) => {
for (const decorationId of this._placeholderDecorations!.values()) {
const placeholderRange = withNullAsUndefined(model.getDecorationRange(decorationId));
if (!result) {
result = placeholderRange;
} else {
result = result.plusRange(placeholderRange!);
}
});
}
return result;
}
}
......@@ -600,8 +598,7 @@ export class SnippetSession {
// that contain at least one selection. for all remaining snippets
// the same placeholder (and their ranges) must be used.
if (allPossibleSelections.size === 0) {
possibleSelections.forEach((ranges, index) => {
for (const [index, ranges] of possibleSelections) {
ranges.sort(Range.compareRangesUsingStarts);
for (const selection of selections) {
if (ranges[0].containsRange(selection)) {
......@@ -609,7 +606,7 @@ export class SnippetSession {
break;
}
}
});
}
}
if (allPossibleSelections.size === 0) {
......@@ -630,11 +627,10 @@ export class SnippetSession {
// selection
selections.sort(Range.compareRangesUsingStarts);
allPossibleSelections.forEach((ranges, index) => {
for (let [index, ranges] of allPossibleSelections) {
if (ranges.length !== selections.length) {
allPossibleSelections.delete(index);
return;
continue;
}
ranges.sort(Range.compareRangesUsingStarts);
......@@ -642,10 +638,10 @@ export class SnippetSession {
for (let i = 0; i < ranges.length; i++) {
if (!ranges[i].containsRange(selections[i])) {
allPossibleSelections.delete(index);
return;
continue;
}
}
}
});
// from all possible selections we have deleted those
// that don't match with the current selection. if we don't
......
......@@ -132,11 +132,7 @@ export class LRUMemory extends Memory {
}
toJSON(): object {
let data: [string, MemItem][] = [];
this._cache.forEach((value, key) => {
data.push([key, value]);
});
return data;
return this._cache.toJSON();
}
fromJSON(data: [string, MemItem][]): void {
......
......@@ -22,10 +22,6 @@ export class ServiceCollection {
return result;
}
forEach(callback: (id: ServiceIdentifier<any>, instanceOrDescriptor: any) => any): void {
this._entries.forEach((value, key) => callback(key, value));
}
has(id: ServiceIdentifier<any>): boolean {
return this._entries.has(id);
}
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { ICommandService, CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ExtHostContext, MainThreadCommandsShape, ExtHostCommandsShape, MainContext, IExtHostContext } from '../common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { revive } from 'vs/base/common/marshalling';
......@@ -28,7 +28,7 @@ export class MainThreadCommands implements MainThreadCommandsShape {
}
dispose() {
this._commandRegistrations.forEach(value => value.dispose());
dispose(this._commandRegistrations.values());
this._commandRegistrations.clear();
this._generateCommandsDocumentationRegistration.dispose();
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { onUnexpectedError } from 'vs/base/common/errors';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Range } from 'vs/editor/common/core/range';
......@@ -35,8 +35,8 @@ export class MainThreadDocumentContentProviders implements MainThreadDocumentCon
}
dispose(): void {
this._resourceContentProvider.forEach(p => p.dispose());
this._pendingUpdate.forEach(source => source.dispose());
dispose(this._resourceContentProvider.values());
dispose(this._pendingUpdate.values());
}
$registerTextContentProvider(handle: number, scheme: string): void {
......
......@@ -266,11 +266,11 @@ class MainThreadDocumentAndEditorStateComputer {
}
if (candidate) {
editors.forEach(snapshot => {
for (const snapshot of editors.values()) {
if (candidate === snapshot.editor) {
activeEditor = snapshot.id;
}
});
}
}
}
......
......@@ -25,7 +25,7 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
}
dispose(): void {
this._fileProvider.forEach(value => value.dispose());
dispose(this._fileProvider.values());
this._fileProvider.clear();
}
......
......@@ -28,11 +28,11 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
// dispose editor inset whenever the hosting editor goes away
this._disposables.add(_editors.onDidChangeVisibleTextEditors(() => {
const visibleEditor = _editors.getVisibleTextEditors();
this._insets.forEach(value => {
for (const value of this._insets.values()) {
if (visibleEditor.indexOf(value.editor) < 0) {
value.inset.dispose(); // will remove from `this._insets`
}
});
}
}));
}
......
......@@ -204,12 +204,12 @@ export class ExtHostCommands implements ExtHostCommandsShape {
$getContributedCommandHandlerDescriptions(): Promise<{ [id: string]: string | ICommandHandlerDescription }> {
const result: { [id: string]: string | ICommandHandlerDescription } = Object.create(null);
this._commands.forEach((command, id) => {
for (let [id, command] of this._commands) {
let { description } = command;
if (description) {
result[id] = description;
}
});
}
return Promise.resolve(result);
}
}
......
......@@ -173,9 +173,9 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
forEach(callback: (uri: URI, diagnostics: ReadonlyArray<vscode.Diagnostic>, collection: DiagnosticCollection) => any, thisArg?: any): void {
this._checkDisposed();
this._data.forEach((value, uri) => {
for (let uri of this._data.keys()) {
callback.apply(thisArg, [uri, this.get(uri), this]);
});
}
}
get(uri: URI): ReadonlyArray<vscode.Diagnostic> {
......@@ -307,7 +307,7 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
} else {
const index = new Map<string, number>();
const res: [vscode.Uri, vscode.Diagnostic[]][] = [];
this._collections.forEach(collection => {
for (const collection of this._collections.values()) {
collection.forEach((uri, diagnostics) => {
let idx = index.get(uri.toString());
if (typeof idx === 'undefined') {
......@@ -317,18 +317,18 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
}
res[idx][1] = res[idx][1].concat(...diagnostics);
});
});
}
return res;
}
}
private _getDiagnostics(resource: vscode.Uri): ReadonlyArray<vscode.Diagnostic> {
let res: vscode.Diagnostic[] = [];
this._collections.forEach(collection => {
for (let collection of this._collections.values()) {
if (collection.has(resource)) {
res = res.concat(collection.get(resource));
}
});
}
return res;
}
......
......@@ -152,9 +152,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
}
allEditors(): ExtHostTextEditor[] {
const result: ExtHostTextEditor[] = [];
this._editors.forEach(data => result.push(data));
return result;
return [...this._editors.values()];
}
}
......
......@@ -248,15 +248,15 @@ export class BulkFileOperations {
for (let file of this.fileOperations) {
if (file.type !== BulkFileOperationType.TextEdit) {
let checked = true;
file.originalEdits.forEach(edit => {
for (const edit of file.originalEdits.values()) {
if (WorkspaceFileEdit.is(edit)) {
checked = checked && this.checked.isChecked(edit);
}
});
}
if (!checked) {
file.originalEdits.forEach(edit => {
for (const edit of file.originalEdits.values()) {
this.checked.updateChecked(edit, checked);
});
}
}
}
}
......@@ -305,8 +305,7 @@ export class BulkFileOperations {
const result: IIdentifiedSingleEditOperation[] = [];
let ignoreAll = false;
file.originalEdits.forEach(edit => {
for (const edit of file.originalEdits.values()) {
if (WorkspaceTextEdit.is(edit)) {
if (this.checked.isChecked(edit)) {
result.push(EditOperation.replaceMove(Range.lift(edit.edit.range), edit.edit.text));
......@@ -316,7 +315,7 @@ export class BulkFileOperations {
// UNCHECKED WorkspaceFileEdit disables all text edits
ignoreAll = true;
}
});
}
if (ignoreAll) {
return [];
......@@ -332,18 +331,13 @@ export class BulkFileOperations {
}
getUriOfEdit(edit: WorkspaceFileEdit | WorkspaceTextEdit): URI {
for (let file of this.fileOperations) {
let found = false;
file.originalEdits.forEach(value => {
if (!found && value === edit) {
found = true;
}
});
if (found) {
for (const value of file.originalEdits.values()) {
if (value === edit) {
return file.uri;
}
}
}
throw new Error('invalid edit');
}
}
......
......@@ -61,22 +61,22 @@ export class FileElement implements ICheckable {
}
// multiple file edits -> reflect single state
this.edit.originalEdits.forEach(edit => {
for (let edit of this.edit.originalEdits.values()) {
if (WorkspaceFileEdit.is(edit)) {
checked = checked && model.checked.isChecked(edit);
}
});
}
// multiple categories and text change -> read all elements
if (this.parent instanceof CategoryElement && this.edit.type === BulkFileOperationType.TextEdit) {
for (let category of model.categories) {
for (let file of category.fileOperations) {
if (file.uri.toString() === this.edit.uri.toString()) {
file.originalEdits.forEach(edit => {
for (const edit of file.originalEdits.values()) {
if (WorkspaceFileEdit.is(edit)) {
checked = checked && model.checked.isChecked(edit);
}
});
}
}
}
}
......@@ -87,18 +87,18 @@ export class FileElement implements ICheckable {
setChecked(value: boolean): void {
let model = this.parent instanceof CategoryElement ? this.parent.parent : this.parent;
this.edit.originalEdits.forEach(edit => {
for (const edit of this.edit.originalEdits.values()) {
model.checked.updateChecked(edit, value);
});
}
// multiple categories and file change -> update all elements
if (this.parent instanceof CategoryElement && this.edit.type !== BulkFileOperationType.TextEdit) {
for (let category of model.categories) {
for (let file of category.fileOperations) {
if (file.uri.toString() === this.edit.uri.toString()) {
file.originalEdits.forEach(edit => {
for (const edit of file.originalEdits.values()) {
model.checked.updateChecked(edit, value);
});
}
}
}
}
......@@ -112,11 +112,11 @@ export class FileElement implements ICheckable {
for (let category of model.categories) {
for (let file of category.fileOperations) {
if (file.uri.toString() === this.edit.uri.toString()) {
file.originalEdits.forEach(edit => {
for (const edit of file.originalEdits.values()) {
if (WorkspaceFileEdit.is(edit)) {
checked = checked && model.checked.isChecked(edit);
}
});
}
}
}
}
......@@ -154,11 +154,11 @@ export class TextEditElement implements ICheckable {
// make sure parent is checked when this element is checked...
if (value) {
this.parent.edit.originalEdits.forEach(edit => {
for (const edit of this.parent.edit.originalEdits.values()) {
if (WorkspaceFileEdit.is(edit)) {
(<BulkFileOperations>model).checked.updateChecked(edit, value);
}
});
}
}
}
......
......@@ -174,12 +174,12 @@ class SnippetsService implements ISnippetsService {
const languageIdentifier = this._modeService.getLanguageIdentifier(languageId);
if (languageIdentifier) {
const langName = languageIdentifier.language;
this._files.forEach(file => {
for (const file of this._files.values()) {
promises.push(file.load()
.then(file => file.select(langName, result))
.catch(err => this._logService.error(err, file.location.toString()))
);
});
}
}
return Promise.all(promises).then(() => result);
});
......@@ -190,12 +190,12 @@ class SnippetsService implements ISnippetsService {
const languageIdentifier = this._modeService.getLanguageIdentifier(languageId);
if (languageIdentifier) {
const langName = languageIdentifier.language;
this._files.forEach(file => {
for (const file of this._files.values()) {
// kick off loading (which is a noop in case it's already loaded)
// and optimistically collect snippets
file.load().catch(err => { /*ignore*/ });
file.select(langName, result);
});
}
}
return result;
}
......@@ -205,11 +205,11 @@ class SnippetsService implements ISnippetsService {
private _initExtensionSnippets(): void {
snippetExt.point.setHandler(extensions => {
this._files.forEach((value, key) => {
for (let [key, value] of this._files) {
if (value.source === SnippetSource.Extension) {
this._files.delete(key);
}
});
}
for (const extension of extensions) {
for (const contribution of extension.value) {
......
......@@ -165,7 +165,7 @@ class BulkEditModel implements IDisposable {
this._tasks = [];
const promises: Promise<any>[] = [];
this._edits.forEach((value, key) => {
for (let [key, value] of this._edits) {
const promise = this._textModelResolverService.createModelReference(URI.parse(key)).then(async ref => {
let task: ModelEditTask;
let makeMinimal = false;
......@@ -195,7 +195,7 @@ class BulkEditModel implements IDisposable {
this._progress.report(undefined);
});
promises.push(promise);
});
}
await Promise.all(promises);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册