Skip to content

Commit

Permalink
Replace FoldingRangeKind type with normal enum. Fixes #48956
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Apr 30, 2018
1 parent bdb3d6e commit 2762cc7
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 74 deletions.
23 changes: 12 additions & 11 deletions extensions/css-language-features/client/src/cssMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
let kind = kinds[value];
if (!kind) {
kind = new FoldingRangeKind(value);
kinds[value] = kind;
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;
}
}
return kind;
return void 0;
}
return languages.registerFoldingRangeProvider(documentSelector, {
provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken) {
Expand Down
23 changes: 12 additions & 11 deletions extensions/html-language-features/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 12 additions & 11 deletions extensions/json-language-features/client/src/jsonMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
let kind = kinds[value];
if (!kind) {
kind = new FoldingRangeKind(value);
kinds[value] = kind;
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;
}
}
return kind;
return void 0;
}
return languages.registerFoldingRangeProvider(documentSelector, {
provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken) {
Expand Down
25 changes: 7 additions & 18 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}

/**
Expand Down
22 changes: 21 additions & 1 deletion src/vs/workbench/api/node/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
26 changes: 4 additions & 22 deletions src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2762cc7

Please sign in to comment.