From 5849361f31f3affe436c41a791112e3c7352c98c Mon Sep 17 00:00:00 2001 From: bk1012 Date: Mon, 18 Nov 2024 18:41:24 +0800 Subject: [PATCH] feat: support api (#4172) --- .../extension/src/common/vscode/ext-types.ts | 23 +++++++ .../hosted/api/vscode/ext.host.language.ts | 10 +++ packages/types/vscode.d.ts | 1 + .../types/vscode/typings/vscode.language.d.ts | 1 + ...oposed.multiDocumentHighlightProvider.d.ts | 63 +++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 packages/types/vscode/typings/vscode.proposed.multiDocumentHighlightProvider.d.ts diff --git a/packages/extension/src/common/vscode/ext-types.ts b/packages/extension/src/common/vscode/ext-types.ts index b682c27917..f1f0fad4bc 100644 --- a/packages/extension/src/common/vscode/ext-types.ts +++ b/packages/extension/src/common/vscode/ext-types.ts @@ -1459,6 +1459,29 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { } } +@es5ClassCompat +export class MultiDocumentHighlight { + /** + * The URI of the document containing the highlights. + */ + uri: Uri; + + /** + * The highlights for the document. + */ + highlights: DocumentHighlight[]; + + /** + * Creates a new instance of MultiDocumentHighlight. + * @param uri The URI of the document containing the highlights. + * @param highlights The highlights for the document. + */ + constructor(uri: Uri, highlights: DocumentHighlight[]) { + this.uri = uri; + this.highlights = highlights; + } +} + @es5ClassCompat export class DocumentLink { range: Range; diff --git a/packages/extension/src/hosted/api/vscode/ext.host.language.ts b/packages/extension/src/hosted/api/vscode/ext.host.language.ts index aea7c96a18..5dbc846061 100644 --- a/packages/extension/src/hosted/api/vscode/ext.host.language.ts +++ b/packages/extension/src/hosted/api/vscode/ext.host.language.ts @@ -361,6 +361,16 @@ export function createLanguagesApiFactory( ): vscode.Disposable { return extHostLanguages.registerDocumentPasteEditProvider(extension, selector, provider, metadata); }, + /** + * @monaco-todo: wait until API is available in Monaco (1.85.0+) + */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + registerMultiDocumentHighlightProvider( + selector: vscode.DocumentSelector, + provider: vscode.MultiDocumentHighlightProvider, + ): vscode.Disposable { + return toDisposable(() => {}); + }, }; } diff --git a/packages/types/vscode.d.ts b/packages/types/vscode.d.ts index d190076180..32cfd369c7 100644 --- a/packages/types/vscode.d.ts +++ b/packages/types/vscode.d.ts @@ -43,6 +43,7 @@ /// /// /// +/// /// /// /// diff --git a/packages/types/vscode/typings/vscode.language.d.ts b/packages/types/vscode/typings/vscode.language.d.ts index d9dcfdcdea..ff8f0f5dde 100644 --- a/packages/types/vscode/typings/vscode.language.d.ts +++ b/packages/types/vscode/typings/vscode.language.d.ts @@ -2447,6 +2447,7 @@ declare module 'vscode' { * @param token A cancellation token. * @returns A set of text edits or a thenable that resolves to such. The lack of a result can be * signaled by returning `undefined`, `null`, or an empty array. + * @monaco-todo the current monaco version does not yet use this API */ provideDocumentRangesFormattingEdits?(document: TextDocument, ranges: Range[], options: FormattingOptions, token: CancellationToken): ProviderResult; } diff --git a/packages/types/vscode/typings/vscode.proposed.multiDocumentHighlightProvider.d.ts b/packages/types/vscode/typings/vscode.proposed.multiDocumentHighlightProvider.d.ts new file mode 100644 index 0000000000..e03250799f --- /dev/null +++ b/packages/types/vscode/typings/vscode.proposed.multiDocumentHighlightProvider.d.ts @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'vscode' { + + /** + * Represents a collection of document highlights from multiple documents. + */ + export class MultiDocumentHighlight { + + /** + * The URI of the document containing the highlights. + */ + uri: Uri; + + /** + * The highlights for the document. + */ + highlights: DocumentHighlight[]; + + /** + * Creates a new instance of MultiDocumentHighlight. + * @param uri The URI of the document containing the highlights. + * @param highlights The highlights for the document. + */ + constructor(uri: Uri, highlights: DocumentHighlight[]); + } + + export interface MultiDocumentHighlightProvider { + + /** + * Provide a set of document highlights, like all occurrences of a variable or + * all exit-points of a function. + * + * @param document The document in which the command was invoked. + * @param position The position at which the command was invoked. + * @param otherDocuments An array of additional valid documents for which highlights should be provided. + * @param token A cancellation token. + * @returns A Map containing a mapping of the Uri of a document to the document highlights or a thenable that resolves to such. The lack of a result can be + * signaled by returning `undefined`, `null`, or an empty map. + */ + provideMultiDocumentHighlights(document: TextDocument, position: Position, otherDocuments: TextDocument[], token: CancellationToken): ProviderResult; + } + + namespace languages { + + /** + * Register a multi document highlight provider. + * + * Multiple providers can be registered for a language. In that case providers are sorted + * by their {@link languages.match score} and groups sequentially asked for document highlights. + * The process stops when a provider returns a `non-falsy` or `non-failure` result. + * + * @param selector A selector that defines the documents this provider is applicable to. + * @param provider A multi-document highlight provider. + * @returns A {@link Disposable} that unregisters this provider when being disposed. + */ + export function registerMultiDocumentHighlightProvider(selector: DocumentSelector, provider: MultiDocumentHighlightProvider): Disposable; + } + +}