This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from codiga/rosie-text-highlights-and-fixes
Rosie text highlights and fixes
- Loading branch information
Showing
28 changed files
with
1,458 additions
and
130 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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mxfile host="app.diagrams.net" modified="2022-11-30T10:01:00.434Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" etag="lvogCwi11RcuYZyPfP5i" version="20.0.3"><diagram id="EbkYADztwSF3Mh8ZUwno" name="Page-1">7Vrdd6I4FP9rfKwHiIg+qu1s55zOObNjd2f6GCFCdiOhIVSdv34TiHxItHQKutp5gtx8Xe7H797c0AOz1eYPBqPgC/UQ6VmGt+mB255lmbZpiIekbDOKMzAzgs+wpwYVhDn+iRRRzfMT7KG4MpBTSjiOqkSXhiFyeYUGGaPr6rAlJdVdI+ijGmHuQlKnfsceDzKqBcC46LhH2A/U1gAYivMV3I1WhDiAHl2XSOCuB2aMUp69rTYzRKT0doLJ5n060JtzxlDIm0z4ktxMoj+jkeXhjbPZjKPZ5OHGtLJlXiBJ1Ccrbvl2JwNGk9BDchWjB6brAHM0j6Are9dC64IW8BURLVO8LmnIP8EVJlLh94i8II5dKDrUPohxtDn4BWYuF2FRiK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y44TGaZrQjN+Z0LzPax3N8aG9+wzoT3yfIR9yGZuHcCVDKdGG9rw7ndqfQi5OMV4l6zAORIU2Lz3uhaOlcDXJcGqeKfpq7j6cgdWvho5BPZEAI7uOO53dwFvOb9xpD3fGDXHHss6KO/XfLtrDnSOO3J8n4hARc+Qp8mtHmitwcFNTKjmxh9dvzfPckItTXVos//D54OgXK1zdJYRnrXFfGTBneNsEmA/cj5zoftr6nRDqy0/z5wT7PkHX9jdMPWBYmkv7EweMem2p5fTggFr7TcqcV6BioKkXtaVi0Sz+ic6q28Wv5eDuPw==</diagram></mxfile> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mxfile host="app.diagrams.net" modified="2022-11-30T09:28:08.487Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" etag="_5ULwbQeA7Yn275ZxKg2" version="20.0.3"><diagram id="_s4aj7_37aYGRvY7WVtE" name="Page-1">7Vpbd9o4EP41nNM+hINtMPAYSNL2bNuTs8lmk0dhC6NWSK4sbv31HdnyDdvESQBDdp9sje4z+r6RRmpZ4/n6k0D+7Bt3MW2ZHXfdsq5apmn0Bn34KMkmkvS7RiTwBHF1oVRwR35jLexo6YK4OMgVlJxTSfy80OGMYUfmZEgIvsoXm3Ka79VHHi4I7hxEi9J/iStnkdS0rGGa8RkTb6a7tqyOHvkcxaW1IJghl68yIuu6ZY0F5zL6m6/HmCrtxYqJ6t1U5CYjE5jJOhX+efxrc/F0697P1vTHZoSv7r9/vzC1fQK5iaeMXdCATnIhZ9zjDNHrVDoSfMFcrJrtQCot85VzH4QGCH9g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jeK+XwP3aRiYueFxl1LsyBJPfYDLtwoSUKNZEhSOaS+U9AX6uvQ8gT0k1dZEh31pcVAyHFSU/UwkPBc6niirwuGEEuYdgEX/4+xpGDXps38w+mz0mvK90eegLn02eh8ZD7MefR5w47SDJicowIq2+X6I8gUM/T6Zxix5EFHKNAcLv5hWo0yT4Zn6F115pjFOiGnOI4pqFMOoBaa5IoFP0UaBXs5UXCXQBKEkH6LNW/JMUhPCTMVoPr5brNqNY3XQJFZfdynd7sCx4LweL9k1Qdzs6yW7BoYXIjofEBZIxCQJ3Wz4zGf7tOXoeEz8+mdv3n1MCVhAHSUuGeMyHMH7P1EkVyi7Hj6WXbO8IiADyfSFd5iXeShvXf8B</diagram></mxfile> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
144 changes: 144 additions & 0 deletions
144
src/Extension/Rosie/Annotation/ApplyRosieFixSuggestedAction.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,144 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.Imaging.Interop; | ||
using Microsoft.VisualStudio.Language.Intellisense; | ||
using Extension.Rosie.Model; | ||
using Microsoft.VisualStudio.Text; | ||
using Span = Microsoft.VisualStudio.Text.Span; | ||
|
||
namespace Extension.Rosie.Annotation | ||
{ | ||
/// <summary> | ||
/// Applies a fix with a series of edits on the code. | ||
/// </summary> | ||
public class ApplyRosieFixSuggestedAction : ISuggestedAction | ||
{ | ||
private readonly ITextBuffer _textBuffer; | ||
private readonly IList<RosieViolationFixEdit> _edits; | ||
private readonly string _displayText; | ||
|
||
public ApplyRosieFixSuggestedAction(ITextBuffer textBuffer, RosieViolationFix fix) | ||
{ | ||
_textBuffer = textBuffer; | ||
_edits = fix.Edits; | ||
_displayText = $"Fix: {fix.Description}"; | ||
} | ||
|
||
public void Invoke(CancellationToken cancellationToken) | ||
{ | ||
if (HasInvalidEditOffset()) | ||
return; | ||
|
||
foreach (var edit in _edits) | ||
{ | ||
//Apply code insertion/addition | ||
if (StringUtils.AreEqualIgnoreCase(edit.EditType, RosieEditTypes.Add)) | ||
{ | ||
_textBuffer.Insert(edit.Start.GetOffset(_textBuffer), edit.Content); | ||
} | ||
|
||
//Apply code replacement/update | ||
if (StringUtils.AreEqualIgnoreCase(edit.EditType, RosieEditTypes.Update)) | ||
{ | ||
var replacementSpan = | ||
Span.FromBounds(edit.Start.GetOffset(_textBuffer), edit.End.GetOffset(_textBuffer)); | ||
_textBuffer.Replace(replacementSpan, edit.Content); | ||
} | ||
|
||
//Apply code removal | ||
if (StringUtils.AreEqualIgnoreCase(edit.EditType, RosieEditTypes.Remove)) | ||
{ | ||
var removalSpan = | ||
Span.FromBounds(edit.Start.GetOffset(_textBuffer), edit.End.GetOffset(_textBuffer)); | ||
_textBuffer.Delete(removalSpan); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// If the start offset for additions, or the start/end offset for removals and updates, received from the rule configuration, | ||
/// is either null or is outside the current file's range, we don't apply the fix. | ||
/// </summary> | ||
internal bool HasInvalidEditOffset() | ||
{ | ||
var hasInvalidOffset = true; | ||
try | ||
{ | ||
var documentLastPosition = _textBuffer.CurrentSnapshot.Length - 1; | ||
hasInvalidOffset = _edits | ||
.Any(edit => | ||
{ | ||
int? startPosition; | ||
if (StringUtils.AreEqualIgnoreCase(edit.EditType, RosieEditTypes.Add)) | ||
{ | ||
startPosition = edit.Start?.GetOffset(_textBuffer); | ||
return startPosition == null || startPosition < 0 || startPosition > documentLastPosition; | ||
} | ||
|
||
startPosition = edit.Start?.GetOffset(_textBuffer); | ||
int? endPosition = edit.End?.GetOffset(_textBuffer); | ||
|
||
return startPosition == null || | ||
endPosition == null || | ||
startPosition < 0 || | ||
endPosition < 0 || | ||
startPosition > documentLastPosition || | ||
endPosition > documentLastPosition; | ||
}); | ||
} | ||
catch (IndexOutOfRangeException) | ||
{ | ||
//Let it through, no edit will happen. | ||
} | ||
|
||
return hasInvalidOffset; | ||
} | ||
|
||
#region Action sets and preview | ||
|
||
public Task<IEnumerable<SuggestedActionSet>> GetActionSetsAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<IEnumerable<SuggestedActionSet>>(null); | ||
} | ||
|
||
public Task<object> GetPreviewAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<object>(null); | ||
} | ||
|
||
#endregion | ||
|
||
#region Disposal | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
public bool TryGetTelemetryId(out Guid telemetryId) | ||
{ | ||
telemetryId = Guid.Empty; | ||
return false; | ||
} | ||
|
||
public bool HasActionSets => false; | ||
|
||
public string DisplayText => _displayText; | ||
|
||
public ImageMoniker IconMoniker => default; | ||
|
||
public string IconAutomationText => null; | ||
|
||
public string InputGestureText => null; | ||
|
||
public bool HasPreview => false; | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.