diff --git a/src/vs/editor/contrib/hover/markdownHoverParticipant.ts b/src/vs/editor/contrib/hover/markdownHoverParticipant.ts index c1a413edf37708e74703d0c0c9f15ba1c534f453..250aab419a578c3a73fdea6a598946795a2dd30d 100644 --- a/src/vs/editor/contrib/hover/markdownHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/markdownHoverParticipant.ts @@ -15,6 +15,10 @@ import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IModelDecoration, ITextModel } from 'vs/editor/common/model'; import { IEditorHover, IEditorHoverParticipant, IHoverPart } from 'vs/editor/contrib/hover/modesContentHover'; +import { HoverProviderRegistry } from 'vs/editor/common/modes'; +import { getHover } from 'vs/editor/contrib/hover/getHover'; +import { Position } from 'vs/editor/common/core/position'; +import { CancellationToken } from 'vs/base/common/cancellation'; const $ = dom.$; @@ -42,11 +46,11 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant { + if (!this._editor.hasModel() || !range) { + return Promise.resolve([]); + } + + const model = this._editor.getModel(); + + if (!HoverProviderRegistry.has(model)) { + return Promise.resolve([]); + } + + const hovers = await getHover(model, new Position( + range.startLineNumber, + range.startColumn + ), token); + + const result: MarkdownHover[] = []; + for (const hover of hovers) { + if (isEmptyMarkdownString(hover.contents)) { + continue; + } + const rng = hover.range ? Range.lift(hover.range) : range; + result.push(new MarkdownHover(rng, hover.contents)); + } + return result; + } + + public renderHoverParts(hoverParts: MarkdownHover[], fragment: DocumentFragment): IDisposable { const disposables = new DisposableStore(); for (const hoverPart of hoverParts) { for (const contents of hoverPart.contents) { diff --git a/src/vs/editor/contrib/hover/markerHoverParticipant.ts b/src/vs/editor/contrib/hover/markerHoverParticipant.ts index 28021a2b2061d28b1d7b3ab917169ed6b90b3fa1..eaced514126d8d603e04b050e4f25f2b05e803c3 100644 --- a/src/vs/editor/contrib/hover/markerHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/markerHoverParticipant.ts @@ -62,7 +62,7 @@ export class MarkerHoverParticipant implements IEditorHoverParticipant { - computeHoverPart(hoverRange: Range, model: ITextModel, decoration: IModelDecoration): T | null; + computeSync(hoverRange: Range, model: ITextModel, decoration: IModelDecoration): T | null; + computeAsync?(range: Range, token: CancellationToken): Promise; renderHoverParts(hoverParts: T[], fragment: DocumentFragment): IDisposable; } @@ -99,26 +99,8 @@ class ModesContentComputer implements IHoverComputer { return Promise.resolve([]); } - const model = this._editor.getModel(); - - if (!HoverProviderRegistry.has(model)) { - return Promise.resolve([]); - } - - const hovers = await getHover(model, new Position( - this._range.startLineNumber, - this._range.startColumn - ), token); - - const result: HoverPartInfo[] = []; - for (const hover of hovers) { - const range = hover.range ? Range.lift(hover.range) : this._range; - if (!range) { - continue; - } - result.push(new HoverPartInfo(this._markdownHoverParticipant, false, new MarkdownHover(range, hover.contents))); - } - return result; + const markdownHovers = await this._markdownHoverParticipant.computeAsync(this._range, token); + return markdownHovers.map(h => new HoverPartInfo(this._markdownHoverParticipant, false, h)); } public computeSync(): HoverPartInfo[] { @@ -148,7 +130,7 @@ class ModesContentComputer implements IHoverComputer { return null; } - const markerHover = this._markerHoverParticipant.computeHoverPart(hoverRange, model, d); + const markerHover = this._markerHoverParticipant.computeSync(hoverRange, model, d); if (markerHover) { return new HoverPartInfo(this._markerHoverParticipant, true, markerHover); } @@ -162,7 +144,7 @@ class ModesContentComputer implements IHoverComputer { return new HoverPartInfo(null, true, new ColorHover(Range.lift(range), color, colorData.provider)); } - const markdownHover = this._markdownHoverParticipant.computeHoverPart(hoverRange, model, d); + const markdownHover = this._markdownHoverParticipant.computeSync(hoverRange, model, d); if (markdownHover) { return new HoverPartInfo(this._markdownHoverParticipant, true, markdownHover); }