Skip to content

Commit d0dd9fb

Browse files
authored
Merge pull request microsoft#257175 from mjbvz/ideological-swallow
Move off of AsyncIterableObject
2 parents a472377 + ab9c8e8 commit d0dd9fb

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

src/vs/editor/contrib/hover/browser/getHover.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ async function executeProvider(provider: HoverProvider, ordinal: number, model:
3434
return new HoverProviderResult(provider, result, ordinal);
3535
}
3636

37-
export function getHoverProviderResultsAsAsyncIterable(registry: LanguageFeatureRegistry<HoverProvider>, model: ITextModel, position: Position, token: CancellationToken, recursive = false): AsyncIterableObject<HoverProviderResult> {
37+
export function getHoverProviderResultsAsAsyncIterable(registry: LanguageFeatureRegistry<HoverProvider>, model: ITextModel, position: Position, token: CancellationToken, recursive = false): AsyncIterable<HoverProviderResult> {
3838
const providers = registry.ordered(model, recursive);
3939
const promises = providers.map((provider, index) => executeProvider(provider, index, model, position, token));
4040
return AsyncIterableObject.fromPromisesResolveOrder(promises).coalesce();
4141
}
4242

43-
export function getHoversPromise(registry: LanguageFeatureRegistry<HoverProvider>, model: ITextModel, position: Position, token: CancellationToken, recursive = false): Promise<Hover[]> {
44-
return getHoverProviderResultsAsAsyncIterable(registry, model, position, token, recursive).map(item => item.hover).toPromise();
43+
export async function getHoversPromise(registry: LanguageFeatureRegistry<HoverProvider>, model: ITextModel, position: Position, token: CancellationToken, recursive = false): Promise<Hover[]> {
44+
const out: Hover[] = [];
45+
for await (const item of getHoverProviderResultsAsAsyncIterable(registry, model, position, token, recursive)) {
46+
out.push(item.hover);
47+
}
48+
return out;
4549
}
4650

4751
registerModelAndPositionCommand('_executeHoverProvider', (accessor, model, position): Promise<Hover[]> => {

src/vs/editor/contrib/hover/browser/hoverTypes.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Dimension } from '../../../../base/browser/dom.js';
7-
import { AsyncIterableObject } from '../../../../base/common/async.js';
87
import { CancellationToken } from '../../../../base/common/cancellation.js';
98
import { IDisposable } from '../../../../base/common/lifecycle.js';
9+
import { ScrollEvent } from '../../../../base/common/scrollable.js';
10+
import { BrandedService, IConstructorSignature } from '../../../../platform/instantiation/common/instantiation.js';
1011
import { ICodeEditor, IEditorMouseEvent } from '../../../browser/editorBrowser.js';
1112
import { Position } from '../../../common/core/position.js';
1213
import { Range } from '../../../common/core/range.js';
1314
import { IModelDecoration } from '../../../common/model.js';
14-
import { BrandedService, IConstructorSignature } from '../../../../platform/instantiation/common/instantiation.js';
1515
import { HoverStartSource } from './hoverOperation.js';
16-
import { ScrollEvent } from '../../../../base/common/scrollable.js';
1716

1817
export interface IHoverPart {
1918
/**
@@ -163,7 +162,7 @@ export interface IEditorHoverParticipant<T extends IHoverPart = IHoverPart> {
163162
readonly hoverOrdinal: number;
164163
suggestHoverAnchor?(mouseEvent: IEditorMouseEvent): HoverAnchor | null;
165164
computeSync(anchor: HoverAnchor, lineDecorations: IModelDecoration[], source: HoverStartSource): T[];
166-
computeAsync?(anchor: HoverAnchor, lineDecorations: IModelDecoration[], source: HoverStartSource, token: CancellationToken): AsyncIterableObject<T>;
165+
computeAsync?(anchor: HoverAnchor, lineDecorations: IModelDecoration[], source: HoverStartSource, token: CancellationToken): AsyncIterable<T>;
167166
createLoadingMessage?(anchor: HoverAnchor): T | null;
168167
renderHoverParts(context: IEditorHoverRenderContext, hoverParts: T[]): IRenderedHoverParts<T>;
169168
getAccessibleContent(hoverPart: T): string;

src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
153153
return result;
154154
}
155155

156-
public computeAsync(anchor: HoverAnchor, lineDecorations: IModelDecoration[], source: HoverStartSource, token: CancellationToken): AsyncIterableObject<MarkdownHover> {
156+
public computeAsync(anchor: HoverAnchor, lineDecorations: IModelDecoration[], source: HoverStartSource, token: CancellationToken): AsyncIterable<MarkdownHover> {
157157
if (!this._editor.hasModel() || anchor.type !== HoverAnchorType.Range) {
158158
return AsyncIterableObject.EMPTY;
159159
}
@@ -164,20 +164,20 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
164164
if (!hoverProviderRegistry.has(model)) {
165165
return AsyncIterableObject.EMPTY;
166166
}
167-
const markdownHovers = this._getMarkdownHovers(hoverProviderRegistry, model, anchor, token);
168-
return markdownHovers;
167+
return this._getMarkdownHovers(hoverProviderRegistry, model, anchor, token);
169168
}
170169

171-
private _getMarkdownHovers(hoverProviderRegistry: LanguageFeatureRegistry<HoverProvider>, model: ITextModel, anchor: HoverRangeAnchor, token: CancellationToken): AsyncIterableObject<MarkdownHover> {
170+
private async *_getMarkdownHovers(hoverProviderRegistry: LanguageFeatureRegistry<HoverProvider>, model: ITextModel, anchor: HoverRangeAnchor, token: CancellationToken): AsyncIterable<MarkdownHover> {
172171
const position = anchor.range.getStartPosition();
173172
const hoverProviderResults = getHoverProviderResultsAsAsyncIterable(hoverProviderRegistry, model, position, token);
174-
const markdownHovers = hoverProviderResults.filter(item => !isEmptyMarkdownString(item.hover.contents))
175-
.map(item => {
173+
174+
for await (const item of hoverProviderResults) {
175+
if (!isEmptyMarkdownString(item.hover.contents)) {
176176
const range = item.hover.range ? Range.lift(item.hover.range) : anchor.range;
177177
const hoverSource = new HoverSource(item.hover, item.provider, position);
178-
return new MarkdownHover(this, range, item.hover.contents, false, item.ordinal, hoverSource);
179-
});
180-
return markdownHovers;
178+
yield new MarkdownHover(this, range, item.hover.contents, false, item.ordinal, hoverSource);
179+
}
180+
}
181181
}
182182

183183
public renderHoverParts(context: IEditorHoverRenderContext, hoverParts: MarkdownHover[]): IRenderedHoverParts<MarkdownHover> {

src/vs/editor/contrib/inlayHints/browser/inlayHintsHover.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,31 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
143143

144144

145145
// (3) Inlay Label Part Location tooltip
146-
const iterable = await this._resolveInlayHintLabelPartHover(part, token);
146+
const iterable = this._resolveInlayHintLabelPartHover(part, token);
147147
for await (const item of iterable) {
148148
executor.emitOne(item);
149149
}
150150
});
151151
}
152152

153-
private async _resolveInlayHintLabelPartHover(part: RenderedInlayHintLabelPart, token: CancellationToken): Promise<AsyncIterableObject<MarkdownHover>> {
153+
private async *_resolveInlayHintLabelPartHover(part: RenderedInlayHintLabelPart, token: CancellationToken): AsyncIterable<MarkdownHover> {
154154
if (!part.part.location) {
155-
return AsyncIterableObject.EMPTY;
155+
return;
156156
}
157+
157158
const { uri, range } = part.part.location;
158159
const ref = await this._resolverService.createModelReference(uri);
159160
try {
160161
const model = ref.object.textEditorModel;
161162
if (!this._languageFeaturesService.hoverProvider.has(model)) {
162-
return AsyncIterableObject.EMPTY;
163+
return;
164+
}
165+
166+
for await (const item of getHoverProviderResultsAsAsyncIterable(this._languageFeaturesService.hoverProvider, model, new Position(range.startLineNumber, range.startColumn), token)) {
167+
if (!isEmptyMarkdownString(item.hover.contents)) {
168+
yield new MarkdownHover(this, part.item.anchor.range, item.hover.contents, false, 2 + item.ordinal);
169+
}
163170
}
164-
return getHoverProviderResultsAsAsyncIterable(this._languageFeaturesService.hoverProvider, model, new Position(range.startLineNumber, range.startColumn), token)
165-
.filter(item => !isEmptyMarkdownString(item.hover.contents))
166-
.map(item => new MarkdownHover(this, part.item.anchor.range, item.hover.contents, false, 2 + item.ordinal));
167171
} finally {
168172
ref.dispose();
169173
}

0 commit comments

Comments
 (0)