Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose an API that enables extensions to drive multi document highlights #196354

Open
jrieken opened this issue Oct 24, 2023 · 2 comments
Open
Assignees
Labels
api-proposal editor-highlight Editor selection/word highlight issues feature-request Request for new features or functionality

Comments

@jrieken
Copy link
Member

jrieken commented Oct 24, 2023

Testing #196342

We have an internal API to support X-document highlights. Our current implementation is very clever but we should propose an API/LSP spec so that extensions can drive this feature all the way

@Yoyokrazy
Copy link
Contributor

Yoyokrazy commented Nov 14, 2023

This is being worked on in conjunction with #196240. This API is being proposed to drive the development of semantic multi-document highlights, rather than the current textual functionality. The shape is as proposed as follows:

/**
 * 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<MultiDocumentHighlight[]>;
}

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;
}

@jrieken
Copy link
Member Author

jrieken commented Apr 3, 2024

@Yoyokrazy let's keep this issue open and use it for the finalization of the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-proposal editor-highlight Editor selection/word highlight issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants