Skip to content

Commit

Permalink
feat: support api (#4172)
Browse files Browse the repository at this point in the history
  • Loading branch information
bk1012 authored Nov 18, 2024
1 parent 72365ba commit 5849361
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/extension/src/common/vscode/ext-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions packages/extension/src/hosted/api/vscode/ext.host.language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});
},
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/// <reference path='./vscode/typings/vscode.proposed.chatAgents2Additions.d.ts' />
/// <reference path='./vscode/typings/vscode.proposed.chatVariables.d.ts' />
/// <reference path='./vscode/typings/vscode.proposed.interactive.d.ts' />
/// <reference path='./vscode/typings/vscode.proposed.multiDocumentHighlightProvider.d.ts' />
/// <reference path='./vscode/typings/vscode.proposed.inlineCompletionsAdditions.d.ts' />
/// <reference path='./vscode/typings/vscode.proposed.codeActionAI.d.ts' />
/// <reference path='./vscode/typings/vscode.proposed.codeActionRanges.d.ts' />
Expand Down
1 change: 1 addition & 0 deletions packages/types/vscode/typings/vscode.language.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextEdit[]>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<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;
}

}

1 comment on commit 5849361

@opensumi
Copy link
Contributor

@opensumi opensumi bot commented on 5849361 Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Next publish successful!

3.5.1-next-1731935606.0

Please sign in to comment.