-
Notifications
You must be signed in to change notification settings - Fork 85
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
112 additions
and
139 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
37 changes: 37 additions & 0 deletions
37
AvaloniaVS.Shared/SuggestedActions/Actions/Base/BaseSuggestedAction.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; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.Imaging.Interop; | ||
using Microsoft.VisualStudio.Language.Intellisense; | ||
|
||
namespace AvaloniaVS.Shared.SuggestedActions.Actions.Base | ||
{ | ||
internal class BaseSuggestedAction | ||
{ | ||
public bool HasActionSets { get; } | ||
|
||
public ImageMoniker IconMoniker { get; } | ||
|
||
public string IconAutomationText { get; } | ||
|
||
public string InputGestureText { get; } | ||
|
||
public bool HasPreview => true; | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public bool TryGetTelemetryId(out Guid telemetryId) | ||
{ | ||
telemetryId = Guid.Empty; | ||
return false; | ||
} | ||
|
||
public Task<IEnumerable<SuggestedActionSet>> GetActionSetsAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<IEnumerable<SuggestedActionSet>>(null); | ||
} | ||
} | ||
} |
49 changes: 10 additions & 39 deletions
49
AvaloniaVS.Shared/SuggestedActions/Actions/MissingAliasSuggestedAction.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 |
---|---|---|
@@ -1,85 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AvaloniaVS.Shared.SuggestedActions.Actions.Base; | ||
using AvaloniaVS.Shared.SuggestedActions.Helpers; | ||
using Microsoft.VisualStudio.Imaging.Interop; | ||
using Microsoft.VisualStudio.Language.Intellisense; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Differencing; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
|
||
namespace AvaloniaVS.Shared.SuggestedActions.Actions | ||
{ | ||
internal class MissingAliasSuggestedAction : ISuggestedAction | ||
internal class MissingAliasSuggestedAction : BaseSuggestedAction, ISuggestedAction | ||
{ | ||
private readonly ITrackingSpan _span; | ||
private readonly ITextSnapshot _snapshot; | ||
private readonly string _targetClassName; | ||
private readonly KeyValuePair<string, string> _targetClassMetadata; | ||
private readonly string _namespaceAlias; | ||
private readonly IWpfDifferenceViewerFactoryService _diffFactory; | ||
private readonly IDifferenceBufferFactoryService _diffBufferFactory; | ||
private readonly ITextBufferFactoryService _bufferFactory; | ||
private readonly IReadOnlyDictionary<string, string> _inverseNamespaces; | ||
private readonly ITextViewRoleSet _previewRoleSet; | ||
|
||
public MissingAliasSuggestedAction(ITrackingSpan span, IWpfDifferenceViewerFactoryService diffFactory, IDifferenceBufferFactoryService diffBufferFactory, ITextBufferFactoryService bufferFactory, ITextEditorFactoryService textEditorFactoryService, IReadOnlyDictionary<string, string> inverseNamespaces) | ||
{ | ||
_inverseNamespaces = inverseNamespaces; | ||
_span = span; | ||
_snapshot = span.TextBuffer.CurrentSnapshot; | ||
_snapshot = _span.TextBuffer.CurrentSnapshot; | ||
_targetClassName = _span.GetText(_snapshot); | ||
_targetClassMetadata = _inverseNamespaces.FirstOrDefault(x => x.Key.Split('.').Last() == _targetClassName); | ||
_namespaceAlias = _targetClassMetadata.Value.Split(':').Last().Split('.').Last(); | ||
var targetClassMetadata = inverseNamespaces.FirstOrDefault(x => x.Key.Split('.').Last() == _targetClassName); | ||
_namespaceAlias = targetClassMetadata.Value.Split(':').Last().Split('.').Last(); | ||
_diffFactory = diffFactory; | ||
_diffBufferFactory = diffBufferFactory; | ||
_bufferFactory = bufferFactory; | ||
_previewRoleSet = textEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Analyzable); | ||
DisplayText = $"Use {_namespaceAlias.ToLower()} ({_targetClassMetadata.Value})"; | ||
DisplayText = $"Use {_namespaceAlias.ToLower()} ({targetClassMetadata.Value})"; | ||
} | ||
|
||
public bool HasActionSets { get; } | ||
|
||
public string DisplayText { get; } | ||
|
||
public ImageMoniker IconMoniker { get; } | ||
|
||
public string IconAutomationText { get; } | ||
|
||
public string InputGestureText { get; } | ||
|
||
public bool HasPreview => true; | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public Task<IEnumerable<SuggestedActionSet>> GetActionSetsAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<IEnumerable<SuggestedActionSet>>(null); | ||
} | ||
|
||
public Task<object> GetPreviewAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<object>(PreviewProvider.GetPreview(_bufferFactory, _span, _diffBufferFactory, _diffFactory, _previewRoleSet, ApplyNamespaceSuggestion)); | ||
return Task.FromResult<object>(PreviewProvider.GetPreview(_bufferFactory, _span, _diffBufferFactory, _diffFactory, _previewRoleSet, ApplySuggestion)); | ||
} | ||
|
||
private void ApplyNamespaceSuggestion(ITextBuffer buffer) | ||
private void ApplySuggestion(ITextBuffer buffer) | ||
{ | ||
buffer.Replace(_span.GetSpan(_snapshot), $"{_namespaceAlias.ToLower()}:{_targetClassName}"); | ||
} | ||
|
||
public void Invoke(CancellationToken cancellationToken) | ||
{ | ||
ApplyNamespaceSuggestion(_span.TextBuffer); | ||
} | ||
|
||
public bool TryGetTelemetryId(out Guid telemetryId) | ||
{ | ||
telemetryId = Guid.Empty; | ||
return false; | ||
ApplySuggestion(_span.TextBuffer); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.