-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'anytext' into LSP-code-action
- Loading branch information
Showing
20 changed files
with
472 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
/// <summary> | ||
/// Denotes a part in a parsed document that can be folded away (hidden). | ||
/// Analogous to the LspTypes FoldingRange interface. | ||
/// </summary> | ||
public class FoldingRange | ||
{ | ||
/// <summary> | ||
/// The zero-based start line of the range to fold. The folded area starts | ||
/// after the line's last character. To be valid, the end must be zero or | ||
/// larger and smaller than the number of lines in the document. | ||
/// </summary> | ||
public uint StartLine { get; set; } | ||
|
||
/// <summary> | ||
/// The zero-based character offset from where the folded range starts. | ||
/// If not defined, defaults to the length of the start line. | ||
/// </summary> | ||
public uint StartCharacter { get; set; } | ||
|
||
/// <summary> | ||
/// The zero-based end line of the range to fold. The folded area ends with | ||
/// the line's last character. To be valid, the end must be zero or larger | ||
/// and smaller than the number of lines in the document. | ||
/// </summary> | ||
public uint EndLine { get; set; } | ||
|
||
/// <summary> | ||
/// The zero-based character offset before the folded range ends. | ||
/// If not defined, defaults to the length of the end line. | ||
/// </summary> | ||
public uint EndCharacter { get; set; } | ||
|
||
/// <summary> | ||
/// Describes the kind of the folding range. | ||
/// Supports values "comment", "imports" and "region". | ||
/// </summary> | ||
public string Kind { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using NMF.AnyText.Model; | ||
using NMF.AnyText.Rules; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.XPath; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
public partial class Parser | ||
{ | ||
/// <summary> | ||
/// Parses folding ranges starting from the root rule application | ||
/// </summary> | ||
/// <returns>An IEnumerable of <see cref="FoldingRange"/> objects, each containing details on a folding range in the document.</returns> | ||
public IEnumerable<FoldingRange> GetFoldingRangesFromRoot() | ||
{ | ||
RuleApplication rootApplication = Context.RootRuleApplication; | ||
|
||
if (rootApplication.IsPositive) | ||
{ | ||
var result = new List<FoldingRange>(); | ||
rootApplication.AddFoldingRanges(result); | ||
return result; | ||
} | ||
|
||
return Enumerable.Empty<FoldingRange>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using LspTypes; | ||
using Newtonsoft.Json.Linq; | ||
using StreamJsonRpc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
public partial interface ILspServer | ||
{ | ||
/// <summary> | ||
/// Handles the <c>textDocument/foldingRange/full</c> request from the client. This is used to retrieve all folding ranges for a document. | ||
/// </summary> | ||
/// <param name="arg">The JSON token containing the parameters of the request. (FoldingRangeParams)</param> | ||
/// <returns>An array of <see cref="FoldingRange" /> objects, each containing details on a folding range in the document.</returns> | ||
[JsonRpcMethod(Methods.TextDocumentFoldingRangeName)] | ||
LspTypes.FoldingRange[] QueryFoldingRanges(JToken arg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using LspTypes; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
public partial class LspServer | ||
{ | ||
/// <inheritdoc cref="ILspServer.QueryFoldingRanges(JToken)"/> | ||
public LspTypes.FoldingRange[] QueryFoldingRanges(JToken arg) | ||
{ | ||
var foldingRangeParams = arg.ToObject<FoldingRangeParams>(); | ||
string uri = foldingRangeParams.TextDocument.Uri; | ||
|
||
if (!_documents.TryGetValue(uri, out var document)) | ||
{ | ||
return Array.Empty<LspTypes.FoldingRange>(); | ||
} | ||
|
||
var foldingRanges = document.GetFoldingRangesFromRoot(); | ||
|
||
return foldingRanges.Select(foldingRange => new LspTypes.FoldingRange() | ||
{ | ||
StartLine = foldingRange.StartLine, | ||
StartCharacter = foldingRange.StartCharacter, | ||
EndLine = foldingRange.EndLine, | ||
EndCharacter = foldingRange.EndCharacter, | ||
Kind = foldingRange.Kind | ||
}).ToArray(); | ||
} | ||
} | ||
} |
Oops, something went wrong.