-
Notifications
You must be signed in to change notification settings - Fork 18
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
6 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/dotnet/ReSharperPlugin.SpecflowRiderPlugin/Navigation/SpecflowOccurenceKindProvider.cs
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,24 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.Feature.Services.Occurrences; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Navigation; | ||
|
||
[SolutionComponent] | ||
public class SpecflowOccurenceKindProvider : IOccurrenceKindProvider | ||
{ | ||
public static readonly OccurrenceKind SpecflowStep = OccurrenceKind.CreateSemantic("SpecflowStep"); | ||
|
||
public ICollection<OccurrenceKind> GetOccurrenceKinds(IOccurrence occurrence) | ||
{ | ||
if (occurrence is SpecflowStepOccurrence) | ||
return [SpecflowStep]; | ||
return []; | ||
} | ||
|
||
public IEnumerable<OccurrenceKind> GetAllPossibleOccurrenceKinds() | ||
{ | ||
return [SpecflowStep]; | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
src/dotnet/ReSharperPlugin.SpecflowRiderPlugin/Navigation/SpecflowOccurenceProvider.cs
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,20 @@ | ||
using JetBrains.ReSharper.Feature.Services.Occurrences; | ||
using JetBrains.ReSharper.Psi.Search; | ||
using ReSharperPlugin.SpecflowRiderPlugin.References; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Navigation; | ||
|
||
[OccurrenceProvider(Priority = 10)] | ||
public class SpecflowOccurenceProvider : IOccurrenceProvider | ||
{ | ||
public IOccurrence MakeOccurrence(FindResult findResult) | ||
{ | ||
if (findResult is FindResultReference findResultReference) | ||
{ | ||
if (findResultReference.Reference is SpecflowStepDeclarationReference specflowStepDeclarationReference) | ||
return new SpecflowStepOccurrence(specflowStepDeclarationReference); | ||
} | ||
|
||
return null; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...tnet/ReSharperPlugin.SpecflowRiderPlugin/Navigation/SpecflowOccurrenceKindIconProvider.cs
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,25 @@ | ||
using JetBrains.Application; | ||
using JetBrains.Application.Parts; | ||
using JetBrains.ReSharper.Feature.Services.Occurrences; | ||
using JetBrains.UI.Icons; | ||
using ReSharperPlugin.SpecflowRiderPlugin.Icons; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Navigation; | ||
|
||
[ShellComponent(Instantiation.DemandAnyThread)] | ||
public class SpecflowOccurrenceKindIconProvider : IOccurrenceKindIconProvider | ||
{ | ||
public IconId GetImageId(OccurrenceKind declaredElement) | ||
{ | ||
if (declaredElement == SpecflowOccurenceKindProvider.SpecflowStep) | ||
return SpecFlowIcons.SpecFlowIcon; | ||
return null; | ||
} | ||
|
||
public int GetPriority(OccurrenceKind occurrenceKind) | ||
{ | ||
if (occurrenceKind == SpecflowOccurenceKindProvider.SpecflowStep) | ||
return -8; | ||
return 0; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...otnet/ReSharperPlugin.SpecflowRiderPlugin/Navigation/SpecflowStepOccurenceInfoProvider.cs
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,66 @@ | ||
using JetBrains.DocumentManagers; | ||
using JetBrains.IDE; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.Feature.Services.Occurrences; | ||
using JetBrains.ReSharper.Feature.Services.Occurrences.OccurrenceInformation; | ||
using JetBrains.ReSharper.Psi; | ||
using JetBrains.ReSharper.Psi.Pointers; | ||
using JetBrains.Util; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Navigation; | ||
|
||
[SolutionFeaturePart] | ||
public class SpecflowStepOccurenceInfoProvider : IOccurrenceInformationProvider2 | ||
{ | ||
public IDeclaredElementEnvoy GetTypeMember(IOccurrence occurrence) | ||
{ | ||
return null; | ||
} | ||
|
||
public IDeclaredElementEnvoy GetTypeElement(IOccurrence occurrence) | ||
{ | ||
return null; | ||
} | ||
|
||
public IDeclaredElementEnvoy GetNamespace(IOccurrence occurrence) | ||
{ | ||
return null; | ||
} | ||
|
||
public OccurrenceMergeContext GetMergeContext(IOccurrence occurrence) | ||
{ | ||
return new OccurrenceMergeContext(occurrence); | ||
} | ||
|
||
public TextRange GetTextRange(IOccurrence occurrence) | ||
{ | ||
return TextRange.InvalidRange; | ||
} | ||
|
||
public ProjectModelElementEnvoy GetProjectModelElementEnvoy(IOccurrence occurrence) | ||
{ | ||
var sourceFile = (occurrence as SpecflowStepOccurrence)?.SourceFile; | ||
if (sourceFile != null) | ||
{ | ||
var map = sourceFile.GetSolution().GetComponent<DocumentToProjectFileMappingStorage>(); | ||
var miscFilesProjectFile = map.TryGetProjectFile(sourceFile.Document); | ||
return miscFilesProjectFile != null ? ProjectModelElementEnvoy.Create(miscFilesProjectFile) : null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public SourceFilePtr GetSourceFilePtr(IOccurrence occurrence) | ||
{ | ||
return (occurrence as SpecflowStepOccurrence)?.SourceFile.Ptr() ?? SourceFilePtr.Fake; | ||
} | ||
|
||
public bool IsApplicable(IOccurrence occurrence) | ||
{ | ||
return occurrence is SpecflowStepOccurrence; | ||
} | ||
|
||
public void SetTabOptions(TabOptions tabOptions, IOccurrence occurrence) | ||
{ | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/dotnet/ReSharperPlugin.SpecflowRiderPlugin/Navigation/SpecflowStepOccurrence.cs
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,66 @@ | ||
using System.Linq; | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
using JetBrains.Application.UI.PopupLayout; | ||
using JetBrains.IDE; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.Feature.Services.Navigation.NavigationExtensions; | ||
using JetBrains.ReSharper.Feature.Services.Occurrences; | ||
using JetBrains.ReSharper.Psi; | ||
using ReSharperPlugin.SpecflowRiderPlugin.References; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Navigation; | ||
|
||
public sealed class SpecflowStepOccurrence(SpecflowStepDeclarationReference specflowStepDeclarationReference) : IOccurrence | ||
{ | ||
public bool Navigate( | ||
ISolution solution, | ||
PopupWindowContextSource windowContext, | ||
bool transferFocus, | ||
TabOptions tabOptions = TabOptions.Default | ||
) | ||
{ | ||
specflowStepDeclarationReference.GetTreeNode().NavigateToNode(true); | ||
PresentationOptions = OccurrencePresentationOptions.DefaultOptions; | ||
return true; | ||
} | ||
|
||
public ISolution GetSolution() | ||
{ | ||
return specflowStepDeclarationReference.GetProject().GetSolution(); | ||
} | ||
|
||
public string DumpToString() | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append($"SourceFilePtr: = {SourceFile.PsiStorage.PersistentIndex}"); | ||
sb.Append($" SpecflowStep: = {specflowStepDeclarationReference.GetStepText()}"); | ||
return sb.ToString(); | ||
} | ||
|
||
public OccurrenceType OccurrenceType => OccurrenceType.Occurrence; | ||
public bool IsValid => SourceFile.IsValid(); | ||
public OccurrencePresentationOptions PresentationOptions { get; set; } | ||
public IPsiSourceFile SourceFile => specflowStepDeclarationReference.GetTreeNode().GetSourceFile(); | ||
|
||
public string GetStepText() | ||
{ | ||
return specflowStepDeclarationReference.GetStepText(); | ||
} | ||
|
||
public string GetScenarioText() | ||
{ | ||
return specflowStepDeclarationReference.ScenarioText; | ||
} | ||
|
||
[CanBeNull] | ||
public string GetRelatedFilePresentation() | ||
{ | ||
return SourceFile.DisplayName.Split('\\').Last(); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return GetStepText(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/dotnet/ReSharperPlugin.SpecflowRiderPlugin/Navigation/SpecflowStepOccurrencePresenter.cs
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,37 @@ | ||
using System.Text; | ||
using JetBrains.Application.UI.Controls.JetPopupMenu; | ||
using JetBrains.ReSharper.Feature.Services.Occurrences; | ||
using JetBrains.UI.RichText; | ||
using JetBrains.Util.Media; | ||
using ReSharperPlugin.SpecflowRiderPlugin.Icons; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Navigation; | ||
|
||
[OccurrencePresenter(Priority = 10.0)] | ||
public class SpecflowStepOccurrencePresenter : IOccurrencePresenter | ||
{ | ||
public bool Present( | ||
IMenuItemDescriptor descriptor, | ||
IOccurrence occurrence, | ||
OccurrencePresentationOptions occurrencePresentationOptions | ||
) | ||
{ | ||
if (occurrence is SpecflowStepOccurrence specflowStepOccurrence) | ||
{ | ||
var text = new RichText(specflowStepOccurrence.GetStepText(), TextStyle.Default); | ||
descriptor.Text = text; | ||
descriptor.Style = MenuItemStyle.CanExpand | MenuItemStyle.Enabled; | ||
descriptor.Tooltip = specflowStepOccurrence.GetScenarioText(); | ||
descriptor.ShortcutText = new RichText(specflowStepOccurrence.GetRelatedFilePresentation(), TextStyle.FromForeColor(JetRgbaColors.DarkGray)); | ||
descriptor.Icon = SpecFlowIcons.SpecFlowIcon; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
public bool IsApplicable(IOccurrence occurrence) | ||
{ | ||
return occurrence is SpecflowStepOccurrence; | ||
} | ||
} |