提交 45e859bf 编写于 作者: M Martin Aeschlimann

monaco folding api (for #47808)

上级 7bc218f9
......@@ -830,30 +830,19 @@ export interface DocumentColorProvider {
*/
provideColorPresentations(model: model.ITextModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
}
/**
* @internal
*/
export interface FoldingContext {
}
/**
* A provider of colors for editor models.
*/
/**
* @internal
*/
export interface FoldingRangeProvider {
/**
* Provides the color ranges for a specific model.
*/
provideFoldingRanges(model: model.ITextModel, context: FoldingContext, token: CancellationToken): IFoldingRange[] | Thenable<IFoldingRange[]>;
provideFoldingRanges(model: model.ITextModel, context: FoldingContext, token: CancellationToken): FoldingRange[] | Thenable<FoldingRange[]>;
}
/**
* @internal
*/
export interface IFoldingRange {
export interface FoldingRange {
/**
* The zero-based start line of the range to fold. The folded area starts after the line's last character.
......@@ -873,9 +862,6 @@ export interface IFoldingRange {
*/
kind?: FoldingRangeKind;
}
/**
* @internal
*/
export class FoldingRangeKind {
/**
* Kind for folding range representing a comment. The value of the kind is 'comment'.
......
......@@ -5,7 +5,7 @@
'use strict';
import { FoldingRangeProvider, IFoldingRange, FoldingContext } from 'vs/editor/common/modes';
import { FoldingRangeProvider, FoldingRange, FoldingContext } from 'vs/editor/common/modes';
import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { toThenable } from 'vs/base/common/async';
import { ITextModel } from 'vs/editor/common/model';
......@@ -16,7 +16,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
const MAX_FOLDING_REGIONS_FOR_INDENT_LIMIT = 5000;
export interface IFoldingRangeData extends IFoldingRange {
export interface IFoldingRangeData extends FoldingRange {
rank: number;
}
......
......@@ -391,12 +391,11 @@ export function registerColorProvider(languageId: string, provider: modes.Docume
}
/**
* Register a folding provider
* Register a folding range provider
*/
/*export function registerFoldingProvider(languageId: string, provider: modes.FoldingProvider): IDisposable {
return modes.FoldingProviderRegistry.register(languageId, provider);
}*/
export function registerFoldingRangeProvider(languageId: string, provider: modes.FoldingRangeProvider): IDisposable {
return modes.FoldingRangeProviderRegistry.register(languageId, provider);
}
/**
* Contains additional diagnostic information about the context in which
......@@ -787,12 +786,14 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
registerOnTypeFormattingEditProvider: registerOnTypeFormattingEditProvider,
registerLinkProvider: registerLinkProvider,
registerColorProvider: registerColorProvider,
registerFoldingRangeProvider: registerFoldingRangeProvider,
// enums
DocumentHighlightKind: modes.DocumentHighlightKind,
CompletionItemKind: CompletionItemKind,
SymbolKind: modes.SymbolKind,
IndentAction: IndentAction,
SuggestTriggerKind: modes.SuggestTriggerKind
SuggestTriggerKind: modes.SuggestTriggerKind,
FoldingRangeKind: modes.FoldingRangeKind
};
}
......@@ -4105,8 +4105,10 @@ declare namespace monaco.languages {
export function registerColorProvider(languageId: string, provider: DocumentColorProvider): IDisposable;
/**
* Register a folding provider
* Register a folding range provider
*/
export function registerFoldingRangeProvider(languageId: string, provider: FoldingRangeProvider): IDisposable;
/**
* Contains additional diagnostic information about the context in which
* a [code action](#CodeActionProvider.provideCodeActions) is run.
......@@ -5000,6 +5002,60 @@ declare namespace monaco.languages {
provideColorPresentations(model: editor.ITextModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
}
export interface FoldingContext {
}
/**
* A provider of colors for editor models.
*/
export interface FoldingRangeProvider {
/**
* Provides the color ranges for a specific model.
*/
provideFoldingRanges(model: editor.ITextModel, context: FoldingContext, token: CancellationToken): FoldingRange[] | Thenable<FoldingRange[]>;
}
export interface FoldingRange {
/**
* The zero-based start line of the range to fold. The folded area starts after the line's last character.
*/
start: number;
/**
* The zero-based end line of the range to fold. The folded area ends with the line's last character.
*/
end: number;
/**
* Describes the [Kind](#FoldingRangeKind) of the folding range such as [Comment](#FoldingRangeKind.Comment) or
* [Region](#FoldingRangeKind.Region). The kind is used to categorize folding ranges and used by commands
* like 'Fold all comments'. See
* [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
*/
kind?: FoldingRangeKind;
}
export class FoldingRangeKind {
value: string;
/**
* Kind for folding range representing a comment. The value of the kind is 'comment'.
*/
static readonly Comment: FoldingRangeKind;
/**
* Kind for folding range representing a import. The value of the kind is 'imports'.
*/
static readonly Imports: FoldingRangeKind;
/**
* Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
* The value of the kind is 'region'.
*/
static readonly Region: FoldingRangeKind;
/**
* Creates a new [FoldingRangeKind](#FoldingRangeKind).
*
* @param value of the kind.
*/
constructor(value: string);
}
export interface ResourceFileEdit {
oldUri: Uri;
newUri: Uri;
......
......@@ -723,7 +723,7 @@ export interface ExtHostLanguageFeaturesShape {
$resolveDocumentLink(handle: number, link: modes.ILink): TPromise<modes.ILink>;
$provideDocumentColors(handle: number, resource: UriComponents): TPromise<IRawColorInfo[]>;
$provideColorPresentations(handle: number, resource: UriComponents, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]>;
$provideFoldingRanges(handle: number, resource: UriComponents, context: modes.FoldingContext): TPromise<modes.IFoldingRange[]>;
$provideFoldingRanges(handle: number, resource: UriComponents, context: modes.FoldingContext): TPromise<modes.FoldingRange[]>;
}
export interface ExtHostQuickOpenShape {
......
......@@ -820,7 +820,7 @@ class FoldingProviderAdapter {
private _provider: vscode.FoldingRangeProvider
) { }
provideFoldingRanges(resource: URI, context: modes.FoldingContext): TPromise<modes.IFoldingRange[]> {
provideFoldingRanges(resource: URI, context: modes.FoldingContext): TPromise<modes.FoldingRange[]> {
const doc = this._documents.getDocumentData(resource).document;
return asWinJsPromise(token => this._provider.provideFoldingRanges(doc, context, token)).then(ranges => {
if (!Array.isArray(ranges)) {
......@@ -1184,7 +1184,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
return this._createDisposable(handle);
}
$provideFoldingRanges(handle: number, resource: UriComponents, context: vscode.FoldingContext): TPromise<modes.IFoldingRange[]> {
$provideFoldingRanges(handle: number, resource: UriComponents, context: vscode.FoldingContext): TPromise<modes.FoldingRange[]> {
return this._withAdapter(handle, FoldingProviderAdapter, adapter => adapter.provideFoldingRanges(URI.revive(resource), context));
}
......
......@@ -624,7 +624,7 @@ export namespace ProgressLocation {
}
export namespace FoldingRange {
export function from(r: vscode.FoldingRange): modes.IFoldingRange {
export function from(r: vscode.FoldingRange): modes.FoldingRange {
return { start: r.start + 1, end: r.end + 1, kind: r.kind };
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册