-
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.
- Loading branch information
Showing
28 changed files
with
1,240 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NMF.AnyText.Rules; | ||
using NMF.AnyText.Workspace; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
/// <summary> | ||
/// Represents the information about a code action. | ||
/// </summary> | ||
public class CodeActionInfo | ||
{ | ||
/// <summary> | ||
/// RuleApplication of the Action | ||
/// </summary> | ||
public RuleApplication RuleApplication { get; set; } | ||
/// <summary> | ||
/// The title is typically displayed in the UI to describe the action. | ||
/// </summary> | ||
public string Title { get; set; } | ||
|
||
/// <summary> | ||
/// Kind of the code action. | ||
/// Possible values: | ||
/// - "quickfix" | ||
/// - "refactor" | ||
/// - "refactor.extract" | ||
/// - "refactor.inline" | ||
/// - "refactor.rewrite" | ||
/// - "source" | ||
/// - "source.organizeImports" | ||
/// </summary> | ||
public string Kind { get; set; } | ||
|
||
/// <summary> | ||
/// This array holds diagnostics for which this action is relevant. If no diagnostics are set, the action may apply generally. | ||
/// </summary> | ||
public string[] Diagnostics { get; set; } | ||
|
||
/// <summary> | ||
/// A value of <c>true</c> indicates that the code action is preferred; otherwise, <c>false</c> or <c>null</c> if there's no preference. | ||
/// </summary> | ||
public bool IsPreferred { get; set; } | ||
|
||
/// <summary> | ||
/// This is the text that describes the command to execute, which can be shown to the user. | ||
/// </summary> | ||
public string CommandTitle { get; set; } | ||
|
||
/// <summary> | ||
/// The command is the identifier or name of the action to execute when the user selects it. | ||
/// </summary> | ||
public string CommandIdentifier { get; set; } | ||
|
||
/// <summary> | ||
/// These are the parameters passed to the command when it is executed. | ||
/// </summary> | ||
public Dictionary<string, object> Arguments { get; set; } | ||
|
||
/// <summary> | ||
/// Identifies the Diagnostic that this Action fixes | ||
/// </summary> | ||
public string DiagnosticIdentifier { get; set; } | ||
|
||
/// <summary> | ||
/// Defines the how the WorkspaceEdit Object of this CodeAction is created | ||
/// </summary> | ||
public Func<ExecuteCommandArguments, WorkspaceEdit> WorkspaceEdit { get; set; } | ||
|
||
/// <summary> | ||
/// The actual execution of this CodeAction | ||
/// </summary> | ||
public Action<ExecuteCommandArguments> Action { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NMF.AnyText.Rules; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
/// <summary> | ||
/// Represents a CodeLens item used for a Language Server Protocol (LSP) server. | ||
/// CodeLens provides information or actions associated with specific locations in a text document. | ||
/// </summary> | ||
public class CodeLensInfo | ||
{ | ||
/// <summary> | ||
/// RuleApplication of the Lens | ||
/// </summary> | ||
public RuleApplication RuleApplication {get;set;} | ||
/// <summary> | ||
/// Gets or sets the title of the CodeLens item, typically a label displayed in the editor. | ||
/// </summary> | ||
public string Title { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the identifier for the command to be executed when the CodeLens is activated. | ||
/// </summary> | ||
public string CommandIdentifier { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the dictionary of arguments to be passed along with the command when invoked. | ||
/// </summary> | ||
public Dictionary<string, object> Arguments { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets additional data associated with this CodeLens, which can be used for custom functionality. | ||
/// </summary> | ||
public object Data { get; set; } | ||
/// <summary> | ||
/// The actual execution of this CodeLens | ||
/// </summary> | ||
public Action<ExecuteCommandArguments> Action { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections.Generic; | ||
using NMF.AnyText.Rules; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
/// <summary> | ||
/// Represents the arguments for executing a command on a document. | ||
/// </summary> | ||
public class ExecuteCommandArguments | ||
{ | ||
/// <summary> | ||
/// RuleApplication of the Action | ||
/// </summary> | ||
public RuleApplication RuleApplication { get; set; } | ||
|
||
/// <summary> | ||
/// ParseContext of the Document | ||
/// </summary> | ||
public ParseContext Context { get; set; } | ||
|
||
/// <summary> | ||
/// URI of the document. | ||
/// </summary> | ||
public string DocumentUri { get; set; } | ||
|
||
/// <summary> | ||
/// Starting position of the Range. | ||
/// </summary> | ||
public ParsePosition Start { get; set; } | ||
|
||
/// <summary> | ||
/// Ending position of the Range. | ||
/// </summary> | ||
public ParsePosition End { get; set; } | ||
|
||
/// <summary> | ||
/// Additional options for the command execution. | ||
/// </summary> | ||
public Dictionary<string, object> OtherOptions { 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,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NMF.AnyText.Rules; | ||
|
||
namespace NMF.AnyText | ||
{ | ||
public partial class Parser | ||
{ | ||
/// <summary> | ||
/// Retrieves code action information within a specified range of parse positions. | ||
/// </summary> | ||
/// <param name="start">The starting position of the range.</param> | ||
/// <param name="end">The ending position of the range.</param> | ||
/// <param name="predicate">An optional predicate to filter rule applications.</param> | ||
/// <returns>A collection of <see cref="CodeActionInfo"/> objects representing available code actions.</returns> | ||
public IEnumerable<CodeActionInfo> GetCodeActionInfo(ParsePosition start, ParsePosition end, | ||
Predicate<RuleApplication> predicate = null) | ||
{ | ||
predicate ??= _ => true; | ||
var codeActionInfos = new List<CodeActionInfo>(); | ||
|
||
var ruleApp = Context.Matcher.GetRuleApplicationsAt(start) | ||
.FirstOrDefault(r => r.Rule.IsLiteral); | ||
|
||
if (ruleApp == null) return codeActionInfos.ToArray(); | ||
|
||
while (!(ruleApp.CurrentPosition <= start && | ||
ruleApp.CurrentPosition + ruleApp.Length >= end)) | ||
{ | ||
ruleApp = ruleApp.Parent; | ||
if (ruleApp == null) | ||
return codeActionInfos; | ||
} | ||
|
||
CollectCodeActionsWithRuleApplication(ruleApp, predicate, codeActionInfos); | ||
|
||
var parent = ruleApp.Parent; | ||
while (parent != null && parent.Length == ruleApp.Length) | ||
{ | ||
CollectCodeActionsWithRuleApplication(parent, predicate, codeActionInfos); | ||
parent = parent.Parent; | ||
|
||
} | ||
|
||
|
||
return codeActionInfos; | ||
} | ||
|
||
private static void CollectCodeActionsWithRuleApplication(RuleApplication ruleApp, Predicate<RuleApplication> predicate, | ||
List<CodeActionInfo> codeActionInfos) | ||
{ | ||
if (predicate.Invoke(ruleApp)) | ||
codeActionInfos.AddRange(ruleApp.Rule.SupportedCodeActions.Select(a => new CodeActionInfo | ||
{ | ||
RuleApplication = ruleApp, | ||
Action = a.Action, | ||
CommandIdentifier = a.CommandIdentifier, | ||
Arguments = a.Arguments, | ||
Diagnostics = a.Diagnostics, | ||
Kind = a.Kind, | ||
CommandTitle = a.CommandTitle, | ||
Title = a.Title, | ||
DiagnosticIdentifier = a.DiagnosticIdentifier, | ||
WorkspaceEdit = a.WorkspaceEdit, | ||
IsPreferred = a.IsPreferred | ||
})); | ||
} | ||
} | ||
} |
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,23 @@ | ||
namespace NMF.AnyText.Workspace | ||
{ | ||
/// <summary> | ||
/// Represents metadata or instructions for an annotation associated with a change. | ||
/// </summary> | ||
public class ChangeAnnotation | ||
{ | ||
/// <summary> | ||
/// A label for the annotation (e.g., "Refactor"). | ||
/// </summary> | ||
public string Label { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the change requires user confirmation. | ||
/// </summary> | ||
public bool? NeedsConfirmation { get; set; } | ||
|
||
/// <summary> | ||
/// A description or explanation of the annotation. | ||
/// </summary> | ||
public string Description { get; set; } | ||
} | ||
} |
Oops, something went wrong.