Replace FoldingRangeKind type with normal enum. Fixes #48956
This commit is contained in:
parent
638c9c3764
commit
f2d37611f1
6 changed files with 68 additions and 74 deletions
|
@ -10,7 +10,7 @@ const localize = nls.loadMessageBundle();
|
|||
|
||||
import { languages, window, commands, ExtensionContext, Range, Position, TextDocument, CompletionItem, CompletionItemKind, TextEdit, SnippetString, FoldingRangeKind, FoldingRange, FoldingContext, CancellationToken } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Disposable } from 'vscode-languageclient';
|
||||
import { FoldingRangeRequest, FoldingRangeRequestParam, FoldingRangeClientCapabilities } from 'vscode-languageserver-protocol-foldingprovider';
|
||||
import { FoldingRangeRequest, FoldingRangeRequestParam, FoldingRangeClientCapabilities, FoldingRangeKind as LSFoldingRangeKind } from 'vscode-languageserver-protocol-foldingprovider';
|
||||
|
||||
// this method is called when vs code is activated
|
||||
export function activate(context: ExtensionContext) {
|
||||
|
@ -124,17 +124,18 @@ export function activate(context: ExtensionContext) {
|
|||
}
|
||||
|
||||
function initFoldingProvider(): Disposable {
|
||||
const kinds: { [value: string]: FoldingRangeKind } = Object.create(null);
|
||||
function getKind(value: string | undefined) {
|
||||
if (!value) {
|
||||
return void 0;
|
||||
function getKind(kind: string | undefined): FoldingRangeKind | undefined {
|
||||
if (kind) {
|
||||
switch (kind) {
|
||||
case LSFoldingRangeKind.Comment:
|
||||
return FoldingRangeKind.Comment;
|
||||
case LSFoldingRangeKind.Imports:
|
||||
return FoldingRangeKind.Imports;
|
||||
case LSFoldingRangeKind.Region:
|
||||
return FoldingRangeKind.Region;
|
||||
}
|
||||
}
|
||||
let kind = kinds[value];
|
||||
if (!kind) {
|
||||
kind = new FoldingRangeKind(value);
|
||||
kinds[value] = kind;
|
||||
}
|
||||
return kind;
|
||||
return void 0;
|
||||
}
|
||||
return languages.registerFoldingRangeProvider(documentSelector, {
|
||||
provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
|
|||
import { activateTagClosing } from './tagClosing';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
import { FoldingRangeRequest, FoldingRangeRequestParam, FoldingRangeClientCapabilities } from 'vscode-languageserver-protocol-foldingprovider';
|
||||
import { FoldingRangeRequest, FoldingRangeRequestParam, FoldingRangeClientCapabilities, FoldingRangeKind as LSFoldingRangeKind } from 'vscode-languageserver-protocol-foldingprovider';
|
||||
|
||||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string, any, any> = new RequestType('html/tag');
|
||||
|
@ -181,17 +181,18 @@ export function activate(context: ExtensionContext) {
|
|||
});
|
||||
|
||||
function initFoldingProvider(): Disposable {
|
||||
const kinds: { [value: string]: FoldingRangeKind } = Object.create(null);
|
||||
function getKind(value: string | undefined) {
|
||||
if (!value) {
|
||||
return void 0;
|
||||
function getKind(kind: string | undefined): FoldingRangeKind | undefined {
|
||||
if (kind) {
|
||||
switch (kind) {
|
||||
case LSFoldingRangeKind.Comment:
|
||||
return FoldingRangeKind.Comment;
|
||||
case LSFoldingRangeKind.Imports:
|
||||
return FoldingRangeKind.Imports;
|
||||
case LSFoldingRangeKind.Region:
|
||||
return FoldingRangeKind.Region;
|
||||
}
|
||||
}
|
||||
let kind = kinds[value];
|
||||
if (!kind) {
|
||||
kind = new FoldingRangeKind(value);
|
||||
kinds[value] = kind;
|
||||
}
|
||||
return kind;
|
||||
return void 0;
|
||||
}
|
||||
return languages.registerFoldingRangeProvider(documentSelector, {
|
||||
provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import { workspace, languages, ExtensionContext, extensions, Uri, LanguageConfig
|
|||
import { LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType, DidChangeConfigurationNotification, CancellationToken } from 'vscode-languageclient';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
import { FoldingRangeRequest, FoldingRangeRequestParam, FoldingRangeClientCapabilities } from 'vscode-languageserver-protocol-foldingprovider';
|
||||
import { FoldingRangeRequest, FoldingRangeRequestParam, FoldingRangeClientCapabilities, FoldingRangeKind as LSFoldingRangeKind } from 'vscode-languageserver-protocol-foldingprovider';
|
||||
|
||||
import { hash } from './utils/hash';
|
||||
|
||||
|
@ -156,17 +156,18 @@ export function activate(context: ExtensionContext) {
|
|||
languages.setLanguageConfiguration('jsonc', languageConfiguration);
|
||||
|
||||
function initFoldingProvider(): Disposable {
|
||||
const kinds: { [value: string]: FoldingRangeKind } = Object.create(null);
|
||||
function getKind(value: string | undefined) {
|
||||
if (!value) {
|
||||
return void 0;
|
||||
function getKind(kind: string | undefined): FoldingRangeKind | undefined {
|
||||
if (kind) {
|
||||
switch (kind) {
|
||||
case LSFoldingRangeKind.Comment:
|
||||
return FoldingRangeKind.Comment;
|
||||
case LSFoldingRangeKind.Imports:
|
||||
return FoldingRangeKind.Imports;
|
||||
case LSFoldingRangeKind.Region:
|
||||
return FoldingRangeKind.Region;
|
||||
}
|
||||
}
|
||||
let kind = kinds[value];
|
||||
if (!kind) {
|
||||
kind = new FoldingRangeKind(value);
|
||||
kinds[value] = kind;
|
||||
}
|
||||
return kind;
|
||||
return void 0;
|
||||
}
|
||||
return languages.registerFoldingRangeProvider(documentSelector, {
|
||||
provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken) {
|
||||
|
|
25
src/vs/vscode.d.ts
vendored
25
src/vs/vscode.d.ts
vendored
|
@ -3411,7 +3411,7 @@ declare module 'vscode' {
|
|||
* 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.
|
||||
* [FoldingRangeKind](#FoldingRangeKind) for an enumeration of all kinds.
|
||||
*/
|
||||
kind?: FoldingRangeKind;
|
||||
|
||||
|
@ -3425,30 +3425,19 @@ declare module 'vscode' {
|
|||
constructor(start: number, end: number, kind?: FoldingRangeKind);
|
||||
}
|
||||
|
||||
export class FoldingRangeKind {
|
||||
export enum FoldingRangeKind {
|
||||
/**
|
||||
* Kind for folding range representing a comment. The value of the kind is 'comment'.
|
||||
* Kind for folding range representing a comment.
|
||||
*/
|
||||
static readonly Comment: FoldingRangeKind;
|
||||
Comment = 1,
|
||||
/**
|
||||
* Kind for folding range representing a import. The value of the kind is 'imports'.
|
||||
* Kind for folding range representing a import.
|
||||
*/
|
||||
static readonly Imports: FoldingRangeKind;
|
||||
Imports = 2,
|
||||
/**
|
||||
* Kind for folding range representing regions (for example a folding range marked by `#region` and `#endregion`).
|
||||
* The value of the kind is 'region'.
|
||||
*/
|
||||
static readonly Region: FoldingRangeKind;
|
||||
/**
|
||||
* String value of the kind, e.g. `comment`.
|
||||
*/
|
||||
readonly value: string;
|
||||
/**
|
||||
* Creates a new [FoldingRangeKind](#FoldingRangeKind).
|
||||
*
|
||||
* @param value of the kind.
|
||||
*/
|
||||
public constructor(value: string);
|
||||
Region = 3
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -625,7 +625,27 @@ export namespace ProgressLocation {
|
|||
|
||||
export namespace FoldingRange {
|
||||
export function from(r: vscode.FoldingRange): modes.FoldingRange {
|
||||
return { start: r.start + 1, end: r.end + 1, kind: r.kind };
|
||||
let range: modes.FoldingRange = { start: r.start + 1, end: r.end + 1 };
|
||||
if (r.kind) {
|
||||
range.kind = FoldingRangeKind.from(r.kind);
|
||||
}
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace FoldingRangeKind {
|
||||
export function from(kind: vscode.FoldingRangeKind | undefined): modes.FoldingRangeKind | undefined {
|
||||
if (kind) {
|
||||
switch (kind) {
|
||||
case types.FoldingRangeKind.Comment:
|
||||
return modes.FoldingRangeKind.Comment;
|
||||
case types.FoldingRangeKind.Imports:
|
||||
return modes.FoldingRangeKind.Imports;
|
||||
case types.FoldingRangeKind.Region:
|
||||
return modes.FoldingRangeKind.Region;
|
||||
}
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1912,28 +1912,10 @@ export class FoldingRange {
|
|||
}
|
||||
}
|
||||
|
||||
export class FoldingRangeKind {
|
||||
/**
|
||||
* Kind for folding range representing a comment. The value of the kind is 'comment'.
|
||||
*/
|
||||
static readonly Comment = new FoldingRangeKind('comment');
|
||||
/**
|
||||
* Kind for folding range representing a import. The value of the kind is 'imports'.
|
||||
*/
|
||||
static readonly Imports = new FoldingRangeKind('imports');
|
||||
/**
|
||||
* Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
|
||||
* The value of the kind is 'region'.
|
||||
*/
|
||||
static readonly Region = new FoldingRangeKind('region');
|
||||
|
||||
/**
|
||||
* Creates a new [FoldingRangeKind](#FoldingRangeKind).
|
||||
*
|
||||
* @param value of the kind.
|
||||
*/
|
||||
public constructor(public value: string) {
|
||||
}
|
||||
export enum FoldingRangeKind {
|
||||
Comment = 1,
|
||||
Imports = 2,
|
||||
Region = 3
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
|
Loading…
Reference in a new issue