Skip to content

Commit

Permalink
bugfix: words were highlighted in all text files instead of only in a…
Browse files Browse the repository at this point in the history
…sm files.
  • Loading branch information
HJLebbink committed Mar 7, 2016
1 parent 3128e95 commit ceda4a5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion CSHARP/AsmDudePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AsmDude {
/// </summary>
[PackageRegistration(UseManagedResourcesOnly = true)]

[InstalledProductRegistration("Asm-Dude", "Asm-Dude description here", "1.4.0")] // for the help about information
[InstalledProductRegistration("Asm-Dude", "Asm-Dude description here", "1.4.3")] // for the help about information

[ProvideOptionPageAttribute(typeof(OptionsPageCodeCompletion), "AsmDude", "Code Completion", 100, 101, true, new string[] { "Change Code Completion Options" })]
[ProvideProfileAttribute( typeof(OptionsPageCodeCompletion), "AsmDude", "Code Completion Options", 100, 101, true)]
Expand Down
86 changes: 47 additions & 39 deletions CSHARP/HighlightWord/HighlightWordTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using System.Globalization;
using System.Diagnostics;

namespace AsmDude.HighlightWord {
namespace AsmDude {

/// <summary>
/// Derive from TextMarkerTag, in case anyone wants to consume
Expand Down Expand Up @@ -124,50 +126,56 @@ private void UpdateWordAdornments(object threadContext) {
List<SnapshotSpan> wordSpans = new List<SnapshotSpan>();

// Find all words in the buffer like the one the caret is on
TextExtent word = TextStructureNavigator.GetExtentOfWord(currentRequest);

bool foundWord = true;

// If we've selected something not worth highlighting, we might have
// missed a "word" by a little bit
if (!WordExtentIsValid(currentRequest, word)) {
// Before we retry, make sure it is worthwhile
if (word.Span.Start != currentRequest ||
currentRequest == currentRequest.GetContainingLine().Start ||
char.IsWhiteSpace((currentRequest - 1).GetChar())) {
foundWord = false;
} else {
// Try again, one character previous. If the caret is at the end of a word, then
// this will pick up the word we are at the end of.
word = TextStructureNavigator.GetExtentOfWord(currentRequest - 1);

// If we still aren't valid the second time around, we're done
if (!WordExtentIsValid(currentRequest, word))
try {
TextExtent word = TextStructureNavigator.GetExtentOfWord(currentRequest);
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: {0}:UpdateWordAdornments. word={1}", this.ToString(), word.ToString()));


bool foundWord = true;
// If we've selected something not worth highlighting, we might have
// missed a "word" by a little bit
if (!WordExtentIsValid(currentRequest, word)) {
// Before we retry, make sure it is worthwhile
if (word.Span.Start != currentRequest ||
currentRequest == currentRequest.GetContainingLine().Start ||
char.IsWhiteSpace((currentRequest - 1).GetChar())) {
foundWord = false;
} else {
// Try again, one character previous. If the caret is at the end of a word, then
// this will pick up the word we are at the end of.
word = TextStructureNavigator.GetExtentOfWord(currentRequest - 1);

// If we still aren't valid the second time around, we're done
if (!WordExtentIsValid(currentRequest, word)) {
foundWord = false;
}
}
}
if (!foundWord) {
// If we couldn't find a word, just clear out the existing markers
SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(), null);
return;
}
}

if (!foundWord) {
// If we couldn't find a word, just clear out the existing markers
SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(), null);
return;
}

SnapshotSpan currentWord = word.Span;

// If this is the same word we currently have, we're done (e.g. caret moved within a word).
if (CurrentWord.HasValue && currentWord == CurrentWord)
return;
SnapshotSpan currentWord = word.Span;

// Find the new spans
FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);
findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
// If this is the same word we currently have, we're done (e.g. caret moved within a word).
if (CurrentWord.HasValue && currentWord == CurrentWord) {
return;
}
// Find the new spans
FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);
findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;

wordSpans.AddRange(TextSearchService.FindAll(findData));
wordSpans.AddRange(TextSearchService.FindAll(findData));

// If we are still up-to-date (another change hasn't happened yet), do a real update
if (currentRequest == RequestedPoint)
SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
// If we are still up-to-date (another change hasn't happened yet), do a real update
if (currentRequest == RequestedPoint) {
SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
}
} catch (Exception e) {
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "ERROR: {0}:UpdateWordAdornments. Something went wrong. e={1}", this.ToString(), e.ToString()));
}
}

/// <summary>
Expand Down
10 changes: 3 additions & 7 deletions CSHARP/HighlightWord/HighlightWordTaggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,17 @@
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsmDude.HighlightWord {
namespace AsmDude {
/// <summary>
/// Export a <see cref="IViewTaggerProvider"/>
/// </summary>
[Export(typeof(IViewTaggerProvider))]
[ContentType("text")]
[ContentType("asm!")]
[TagType(typeof(HighlightWordTag))]
public class HighlightWordTaggerProvider : IViewTaggerProvider {

[Import]
internal ITextSearchService TextSearchService { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion CSHARP/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011">
<Metadata>
<Identity Id="c729d6b2-f412-49ed-893d-a8f61f25db98" Version="1.4.2" Language="en-US" Publisher="H.J. Lebbink" />
<Identity Id="c729d6b2-f412-49ed-893d-a8f61f25db98" Version="1.4.3" Language="en-US" Publisher="H.J. Lebbink" />
<DisplayName>AsmDude</DisplayName>
<Description xml:space="preserve">Syntax highlighting, code completion and folding for assembly source code</Description>
<MoreInfo>https://github.com/HJLebbink/asm-dude</MoreInfo>
Expand Down

0 comments on commit ceda4a5

Please sign in to comment.