Skip to content

Commit 3034963

Browse files
committed
Start implementing code folding provider
1 parent a5cdb62 commit 3034963

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
2+
3+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities
4+
{
5+
public class FoldingRangeCapability : DynamicCapability
6+
{
7+
/// <summary>
8+
/// The maximum number of folding ranges that the client prefers to receive per document. The value serves as a
9+
/// hint, servers are free to follow the limit.
10+
/// </summary>
11+
[Optional]
12+
public long? RangeLimit { get; set; }
13+
14+
/// <summary>
15+
/// set, the client signals that it only supports folding complete lines. If set, client will
16+
/// ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange.
17+
/// </summary>
18+
[Optional]
19+
public bool LineFoldingOnly { get; set; }
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using OmniSharp.Extensions.JsonRpc;
2+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
3+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
4+
5+
// ReSharper disable once CheckNamespace
6+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Server
7+
{
8+
using static DocumentNames;
9+
[Serial, Method(FoldingRange)]
10+
public interface IFoldingRangeHandler : IJsonRpcRequestHandler<FoldingRangeRequestParam, Container<FoldingRange>>, IRegistration<TextDocumentRegistrationOptions>, ICapability<FoldingRangeCapability> { }
11+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
2+
3+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
4+
{
5+
/// <summary>
6+
/// Represents a folding range.
7+
/// </summary>
8+
public class FoldingRange
9+
{
10+
/// <summary>
11+
/// The zero-based line number from where the folded range starts.
12+
/// </summary>
13+
public long StartLine { get; set; }
14+
15+
/// <summary>
16+
/// The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
17+
/// </summary>
18+
[Optional]
19+
public long? StartCharacter { get; set; }
20+
21+
/// <summary>
22+
/// The zero-based line number where the folded range ends.
23+
/// </summary>
24+
public long EndLine { get; set; }
25+
26+
/// <summary>
27+
/// The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
28+
/// </summary>
29+
[Optional]
30+
public long? EndCharacter { get; set; }
31+
32+
/// <summary>
33+
/// Describes the kind of the folding range such as `comment' or 'region'. The kind
34+
/// is used to categorize folding ranges and used by commands like 'Fold all comments'. See
35+
/// [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
36+
/// </summary>
37+
[Optional]
38+
public FoldingRangeKind? Kind { get; set; }
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
2+
{
3+
/// <summary>
4+
/// Enum of known range kinds
5+
/// </summary>
6+
public enum FoldingRangeKind
7+
{
8+
/// <summary>
9+
/// Folding range for a comment
10+
/// </summary>
11+
Comment,
12+
/// <summary>
13+
/// Folding range for a imports or includes
14+
/// </summary>
15+
Imports,
16+
/// <summary>
17+
/// Folding range for a region (e.g. `#region`)
18+
/// </summary>
19+
Region
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using MediatR;
2+
3+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
4+
{
5+
public class FoldingRangeRequestParam : ITextDocumentIdentifierParams, IRequest<Container<FoldingRange>>
6+
{
7+
/// <summary>
8+
/// The text document.
9+
/// </summary>
10+
public TextDocumentIdentifier TextDocument { get; set; }
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
2+
3+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities
4+
{
5+
public class FoldingRangeProviderOptions : StaticTextDocumentRegistrationOptions
6+
{
7+
8+
}
9+
}

0 commit comments

Comments
 (0)