mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
remove generic type, move API additions to separate proposals file, enforce proposal
This commit is contained in:
parent
a47c78516c
commit
99d65cd47c
|
@ -536,8 +536,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
|
||||
return extHostLanguageFeatures.registerDocumentFormattingEditProvider(extension, checkSelector(selector), provider);
|
||||
},
|
||||
registerDocumentRangeFormattingEditProvider<T extends vscode.Range | vscode.Range[]>(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider, metadata?: vscode.DocumentRangeFormattingEditProviderMetadata): vscode.Disposable {
|
||||
return extHostLanguageFeatures.registerDocumentRangeFormattingEditProvider<T>(extension, checkSelector(selector), provider, metadata);
|
||||
registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider, metadata?: vscode.DocumentRangeFormattingEditProviderMetadata): vscode.Disposable {
|
||||
return extHostLanguageFeatures.registerDocumentRangeFormattingEditProvider(extension, checkSelector(selector), provider, metadata);
|
||||
},
|
||||
registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, firstTriggerCharacter: string, ...moreTriggerCharacters: string[]): vscode.Disposable {
|
||||
return extHostLanguageFeatures.registerOnTypeFormattingEditProvider(extension, checkSelector(selector), provider, [firstTriggerCharacter].concat(moreTriggerCharacters));
|
||||
|
|
|
@ -33,7 +33,7 @@ import { Cache } from './cache';
|
|||
import { StopWatch } from 'vs/base/common/stopwatch';
|
||||
import { isCancellationError, NotImplementedError } from 'vs/base/common/errors';
|
||||
import { raceCancellationError } from 'vs/base/common/async';
|
||||
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
|
||||
|
||||
// --- adapter
|
||||
|
@ -2064,8 +2064,12 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
|
|||
return this._withAdapter(handle, DocumentFormattingAdapter, adapter => adapter.provideDocumentFormattingEdits(URI.revive(resource), options, token), undefined, token);
|
||||
}
|
||||
|
||||
registerDocumentRangeFormattingEditProvider<T extends vscode.Range | vscode.Range[]>(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider, metadata?: vscode.DocumentRangeFormattingEditProviderMetadata): vscode.Disposable {
|
||||
const handle = this._addNewAdapter(new RangeFormattingAdapter(this._documents, provider, metadata?.canFormatMultipleRanges ?? false), extension);
|
||||
registerDocumentRangeFormattingEditProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider, metadata?: vscode.DocumentRangeFormattingEditProviderMetadata): vscode.Disposable {
|
||||
const canFormatMultipleRanges = metadata?.canFormatMultipleRanges ?? false;
|
||||
if (canFormatMultipleRanges) {
|
||||
checkProposedApiEnabled(extension, 'formatMultipleRanges');
|
||||
}
|
||||
const handle = this._addNewAdapter(new RangeFormattingAdapter(this._documents, provider, canFormatMultipleRanges), extension);
|
||||
this._proxy.$registerRangeFormattingSupport(handle, this._transformDocumentSelector(selector), extension.identifier, extension.displayName || extension.name, metadata ?? { canFormatMultipleRanges: false });
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ export const allApiProposals = Object.freeze({
|
|||
fileComments: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.fileComments.d.ts',
|
||||
fileSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.fileSearchProvider.d.ts',
|
||||
findTextInFiles: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.findTextInFiles.d.ts',
|
||||
formatMultipleRanges: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.formatMultipleRanges.d.ts',
|
||||
fsChunks: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.fsChunks.d.ts',
|
||||
getSessions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.getSessions.d.ts',
|
||||
idToken: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.idToken.d.ts',
|
||||
|
|
20
src/vscode-dts/vscode.d.ts
vendored
20
src/vscode-dts/vscode.d.ts
vendored
|
@ -4089,15 +4089,10 @@ declare module 'vscode' {
|
|||
*/
|
||||
insertSpaces: boolean;
|
||||
|
||||
/**
|
||||
* The list of multiple ranges to format at once, if the provider supports it.
|
||||
*/
|
||||
ranges?: Range[];
|
||||
|
||||
/**
|
||||
* Signature for further properties.
|
||||
*/
|
||||
[key: string]: boolean | number | string | Range[] | undefined;
|
||||
[key: string]: boolean | number | string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4141,16 +4136,6 @@ declare module 'vscode' {
|
|||
provideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata about a registered {@linkcode DocumentRangeFormattingEditProvider}.
|
||||
*/
|
||||
export interface DocumentRangeFormattingEditProviderMetadata {
|
||||
/**
|
||||
* `true` if the range formatting provider supports formatting multiple ranges at once.
|
||||
*/
|
||||
readonly canFormatMultipleRanges?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* The document formatting provider interface defines the contract between extensions and
|
||||
* the formatting-feature.
|
||||
|
@ -13095,10 +13080,9 @@ declare module 'vscode' {
|
|||
*
|
||||
* @param selector A selector that defines the documents this provider is applicable to.
|
||||
* @param provider A document range formatting edit provider.
|
||||
* @param metadata Metadata about the provider.
|
||||
* @return A {@link Disposable} that unregisters this provider when being disposed.
|
||||
*/
|
||||
export function registerDocumentRangeFormattingEditProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider, metadata?: DocumentRangeFormattingEditProviderMetadata): Disposable;
|
||||
export function registerDocumentRangeFormattingEditProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider): Disposable;
|
||||
|
||||
/**
|
||||
* Register a formatting provider that works on type. The provider is active when the user enables the setting `editor.formatOnType`.
|
||||
|
|
43
src/vscode-dts/vscode.proposed.formatMultipleRanges.d.ts
vendored
Normal file
43
src/vscode-dts/vscode.proposed.formatMultipleRanges.d.ts
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/158776
|
||||
|
||||
/**
|
||||
* Metadata about a registered {@linkcode DocumentRangeFormattingEditProvider}.
|
||||
*/
|
||||
export interface DocumentRangeFormattingEditProviderMetadata {
|
||||
/**
|
||||
* `true` if the range formatting provider supports formatting multiple ranges at once.
|
||||
*/
|
||||
readonly canFormatMultipleRanges?: boolean;
|
||||
}
|
||||
|
||||
export interface FormattingOptions2 {
|
||||
|
||||
/**
|
||||
* The list of multiple ranges to format at once, if the provider supports it.
|
||||
*/
|
||||
// TODO@API should this all ranges or all except for the first range?
|
||||
// TODO@API needs a name that is more descriptive
|
||||
ranges?: Range[];
|
||||
|
||||
[key: string]: boolean | number | string | undefined | object;
|
||||
}
|
||||
|
||||
export interface DocumentRangeFormattingEditProvider {
|
||||
provideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions & FormattingOptions2, token: CancellationToken): ProviderResult<TextEdit[]>;
|
||||
}
|
||||
|
||||
export namespace languages {
|
||||
/**
|
||||
*
|
||||
* @param metadata Metadata about the provider.
|
||||
*/
|
||||
export function registerDocumentRangeFormattingEditProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider, metadata?: DocumentRangeFormattingEditProviderMetadata): Disposable;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue