mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
support to resolve inlay hints for hover and for future display parts, https://github.com/microsoft/vscode/issues/129528
This commit is contained in:
@@ -421,7 +421,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
|
||||
$registerSuggestSupport(handle: number, selector: IDocumentFilterDto[], triggerCharacters: string[], supportsResolveDetails: boolean, displayName: string): void;
|
||||
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerSignatureHelpProvider(handle: number, selector: IDocumentFilterDto[], metadata: ISignatureHelpProviderMetadataDto): void;
|
||||
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], eventHandle: number | undefined): void;
|
||||
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined): void;
|
||||
$emitInlayHintsEvent(eventHandle: number): void;
|
||||
$registerDocumentLinkProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean): void;
|
||||
$registerDocumentColorProvider(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
@@ -1503,7 +1503,9 @@ export interface ISignatureHelpContextDto {
|
||||
}
|
||||
|
||||
export interface IInlayHintDto {
|
||||
text: string;
|
||||
cacheId?: ChainedCacheId;
|
||||
label: string;
|
||||
tooltip?: string | IMarkdownString;
|
||||
position: IPosition;
|
||||
kind: modes.InlayHintKind;
|
||||
whitespaceBefore?: boolean;
|
||||
@@ -1511,6 +1513,7 @@ export interface IInlayHintDto {
|
||||
}
|
||||
|
||||
export interface IInlayHintsDto {
|
||||
cacheId?: CacheId
|
||||
hints: IInlayHintDto[]
|
||||
}
|
||||
|
||||
@@ -1722,6 +1725,8 @@ export interface ExtHostLanguageFeaturesShape {
|
||||
$provideSignatureHelp(handle: number, resource: UriComponents, position: IPosition, context: modes.SignatureHelpContext, token: CancellationToken): Promise<ISignatureHelpDto | undefined>;
|
||||
$releaseSignatureHelp(handle: number, id: number): void;
|
||||
$provideInlayHints(handle: number, resource: UriComponents, range: IRange, token: CancellationToken): Promise<IInlayHintsDto | undefined>
|
||||
$resolveInlayHint(handle: number, id: ChainedCacheId, token: CancellationToken): Promise<IInlayHintDto | undefined>;
|
||||
$releaseInlayHints(handle: number, id: number): void;
|
||||
$provideDocumentLinks(handle: number, resource: UriComponents, token: CancellationToken): Promise<ILinksListDto | undefined>;
|
||||
$resolveDocumentLink(handle: number, id: ChainedCacheId, token: CancellationToken): Promise<ILinkDto | undefined>;
|
||||
$releaseDocumentLinks(handle: number, id: number): void;
|
||||
|
||||
@@ -1171,6 +1171,9 @@ class SignatureHelpAdapter {
|
||||
}
|
||||
|
||||
class InlayHintsAdapter {
|
||||
|
||||
private _cache = new Cache<vscode.InlayHint>('InlayHints');
|
||||
|
||||
constructor(
|
||||
private readonly _documents: ExtHostDocuments,
|
||||
private readonly _provider: vscode.InlayHintsProvider,
|
||||
@@ -1178,8 +1181,51 @@ class InlayHintsAdapter {
|
||||
|
||||
async provideInlayHints(resource: URI, range: IRange, token: CancellationToken): Promise<extHostProtocol.IInlayHintsDto | undefined> {
|
||||
const doc = this._documents.getDocument(resource);
|
||||
const value = await this._provider.provideInlayHints(doc, typeConvert.Range.to(range), token);
|
||||
return value ? { hints: value.map(typeConvert.InlayHint.from) } : undefined;
|
||||
|
||||
const hints = await this._provider.provideInlayHints(doc, typeConvert.Range.to(range), token);
|
||||
if (!Array.isArray(hints) || hints.length === 0) {
|
||||
// bad result
|
||||
return undefined;
|
||||
}
|
||||
if (token.isCancellationRequested) {
|
||||
// cancelled -> return without further ado, esp no caching
|
||||
// of results as they will leak
|
||||
return undefined;
|
||||
}
|
||||
if (typeof this._provider.resolveInlayHint !== 'function') {
|
||||
// no resolve -> no caching
|
||||
return { hints: hints.map(typeConvert.InlayHint.from) };
|
||||
|
||||
} else {
|
||||
// cache links for future resolving
|
||||
const pid = this._cache.add(hints);
|
||||
const result: extHostProtocol.IInlayHintsDto = { hints: [], cacheId: pid };
|
||||
for (let i = 0; i < hints.length; i++) {
|
||||
const dto: extHostProtocol.IInlayHintDto = typeConvert.InlayHint.from(hints[i]);
|
||||
dto.cacheId = [pid, i];
|
||||
result.hints.push(dto);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
async resolveInlayHint(id: extHostProtocol.ChainedCacheId, token: CancellationToken) {
|
||||
if (typeof this._provider.resolveInlayHint !== 'function') {
|
||||
return undefined;
|
||||
}
|
||||
const item = this._cache.get(...id);
|
||||
if (!item) {
|
||||
return undefined;
|
||||
}
|
||||
const hint = await this._provider.resolveInlayHint!(item, token);
|
||||
if (!hint) {
|
||||
return undefined;
|
||||
}
|
||||
return typeConvert.InlayHint.from(hint);
|
||||
}
|
||||
|
||||
releaseHints(id: number): any {
|
||||
this._cache.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1986,7 +2032,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
|
||||
const eventHandle = typeof provider.onDidChangeInlayHints === 'function' ? this._nextHandle() : undefined;
|
||||
const handle = this._addNewAdapter(new InlayHintsAdapter(this._documents, provider), extension);
|
||||
|
||||
this._proxy.$registerInlayHintsProvider(handle, this._transformDocumentSelector(selector), eventHandle);
|
||||
this._proxy.$registerInlayHintsProvider(handle, this._transformDocumentSelector(selector), typeof provider.resolveInlayHint === 'function', eventHandle);
|
||||
let result = this._createDisposable(handle);
|
||||
|
||||
if (eventHandle !== undefined) {
|
||||
@@ -2000,6 +2046,14 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
|
||||
return this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.provideInlayHints(URI.revive(resource), range, token), undefined);
|
||||
}
|
||||
|
||||
$resolveInlayHint(handle: number, id: extHostProtocol.ChainedCacheId, token: CancellationToken): Promise<extHostProtocol.IInlayHintDto | undefined> {
|
||||
return this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.resolveInlayHint(id, token), undefined);
|
||||
}
|
||||
|
||||
$releaseInlayHints(handle: number, id: number): void {
|
||||
this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.releaseHints(id), undefined);
|
||||
}
|
||||
|
||||
// --- links
|
||||
|
||||
registerDocumentLinkProvider(extension: IExtensionDescription | undefined, selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
|
||||
|
||||
@@ -1154,7 +1154,7 @@ export namespace InlayHint {
|
||||
|
||||
export function from(hint: vscode.InlayHint): modes.InlayHint {
|
||||
return {
|
||||
text: hint.text,
|
||||
label: hint.text,
|
||||
tooltip: hint.tooltip && MarkdownString.from(hint.tooltip),
|
||||
position: Position.from(hint.position),
|
||||
kind: InlayHintKind.from(hint.kind ?? types.InlayHintKind.Other),
|
||||
@@ -1165,7 +1165,7 @@ export namespace InlayHint {
|
||||
|
||||
export function to(hint: modes.InlayHint): vscode.InlayHint {
|
||||
const res = new types.InlayHint(
|
||||
hint.text,
|
||||
hint.label,
|
||||
Position.to(hint.position),
|
||||
InlayHintKind.to(hint.kind)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user