Refactoring only

This commit is contained in:
Olivier Guinart 2017-01-15 14:44:43 -08:00
parent 22df541220
commit 6933f485a3
9 changed files with 115 additions and 137 deletions

View File

@ -13,35 +13,35 @@ namespace VSMerlin32.Coloring.Classification
/// </summary> /// </summary>
[Export(typeof(ClassificationTypeDefinition))] [Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Opcode)] [Name(Merlin32TokenHelper.Merlin32Opcode)]
internal static ClassificationTypeDefinition opcode = null; internal static ClassificationTypeDefinition Opcode = null;
/// <summary> /// <summary>
/// Defines the "directive" classification type. /// Defines the "directive" classification type.
/// </summary> /// </summary>
[Export(typeof(ClassificationTypeDefinition))] [Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Directive)] [Name(Merlin32TokenHelper.Merlin32Directive)]
internal static ClassificationTypeDefinition directive = null; internal static ClassificationTypeDefinition Directive = null;
/// <summary> /// <summary>
/// Defines the "datadefine" classification type. /// Defines the "datadefine" classification type.
/// </summary> /// </summary>
[Export(typeof(ClassificationTypeDefinition))] [Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32DataDefine)] [Name(Merlin32TokenHelper.Merlin32DataDefine)]
internal static ClassificationTypeDefinition datadefine = null; internal static ClassificationTypeDefinition Datadefine = null;
/// <summary> /// <summary>
/// Defines the "text" classification type. /// Defines the "text" classification type.
/// </summary> /// </summary>
[Export(typeof(ClassificationTypeDefinition))] [Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Text)] [Name(Merlin32TokenHelper.Merlin32Text)]
internal static ClassificationTypeDefinition text = null; internal static ClassificationTypeDefinition Text = null;
/// <summary> /// <summary>
/// Defines the "comment" classification type. /// Defines the "comment" classification type.
/// </summary> /// </summary>
[Export(typeof(ClassificationTypeDefinition))] [Export(typeof(ClassificationTypeDefinition))]
[Name(Merlin32TokenHelper.Merlin32Comment)] [Name(Merlin32TokenHelper.Merlin32Comment)]
internal static ClassificationTypeDefinition comment = null; internal static ClassificationTypeDefinition Comment = null;
#endregion #endregion
} }

View File

@ -13,7 +13,6 @@ namespace VSMerlin32.Coloring.Classification
[TagType(typeof(ClassificationTag))] [TagType(typeof(ClassificationTag))]
internal sealed class Merlin32ClassifierProvider : ITaggerProvider internal sealed class Merlin32ClassifierProvider : ITaggerProvider
{ {
[Export] [Export]
[Name("Merlin32")] [Name("Merlin32")]
[BaseDefinition("code")] [BaseDefinition("code")]
@ -28,34 +27,33 @@ namespace VSMerlin32.Coloring.Classification
internal IClassificationTypeRegistryService ClassificationTypeRegistry = null; internal IClassificationTypeRegistryService ClassificationTypeRegistry = null;
[Import] [Import]
internal IBufferTagAggregatorFactoryService aggregatorFactory = null; internal IBufferTagAggregatorFactoryService AggregatorFactory = null;
public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
{ {
ITagAggregator<Merlin32TokenTag> merlin32TagAggregator =
AggregatorFactory.CreateTagAggregator<Merlin32TokenTag>(buffer);
ITagAggregator<Merlin32TokenTag> Merlin32TagAggregator = return new Merlin32Classifier(buffer, merlin32TagAggregator, ClassificationTypeRegistry) as ITagger<T>;
aggregatorFactory.CreateTagAggregator<Merlin32TokenTag>(buffer);
return new Merlin32Classifier(buffer, Merlin32TagAggregator, ClassificationTypeRegistry) as ITagger<T>;
} }
} }
internal sealed class Merlin32Classifier : ITagger<ClassificationTag> internal sealed class Merlin32Classifier : ITagger<ClassificationTag>
{ {
ITextBuffer _buffer; private ITextBuffer _buffer;
ITagAggregator<Merlin32TokenTag> _aggregator; private readonly ITagAggregator<Merlin32TokenTag> _aggregator;
IDictionary<Merlin32TokenTypes, IClassificationType> _Merlin32Types; private readonly IDictionary<Merlin32TokenTypes, IClassificationType> _merlin32Types;
internal Merlin32Classifier(ITextBuffer buffer, internal Merlin32Classifier(ITextBuffer buffer,
ITagAggregator<Merlin32TokenTag> Merlin32TagAggregator, ITagAggregator<Merlin32TokenTag> merlin32TagAggregator,
IClassificationTypeRegistryService typeService) IClassificationTypeRegistryService typeService)
{ {
_buffer = buffer; _buffer = buffer;
_aggregator = Merlin32TagAggregator; _aggregator = merlin32TagAggregator;
_Merlin32Types = new Dictionary<Merlin32TokenTypes, IClassificationType>(); _merlin32Types = new Dictionary<Merlin32TokenTypes, IClassificationType>();
foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes))) foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes)))
_Merlin32Types[token] = typeService.GetClassificationType(token.ToString()); _merlin32Types[token] = typeService.GetClassificationType(token.ToString());
} }
public event EventHandler<SnapshotSpanEventArgs> TagsChanged public event EventHandler<SnapshotSpanEventArgs> TagsChanged
@ -66,13 +64,11 @@ namespace VSMerlin32.Coloring.Classification
public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans) public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{ {
foreach (var tagSpan in _aggregator.GetTags(spans))
foreach (var tagSpan in this._aggregator.GetTags(spans))
{ {
var tagSpans = tagSpan.Span.GetSpans(spans[0].Snapshot); var tagSpans = tagSpan.Span.GetSpans(spans[0].Snapshot);
yield return yield return
new TagSpan<ClassificationTag>(tagSpans[0], new TagSpan<ClassificationTag>(tagSpans[0], new ClassificationTag(_merlin32Types[tagSpan.Tag.Tokentype]));
new ClassificationTag(_Merlin32Types[tagSpan.Tag.Tokentype]));
} }
} }
} }

View File

@ -8,17 +8,17 @@ namespace VSMerlin32.Coloring
{ {
internal class Merlin32CodeHelper internal class Merlin32CodeHelper
{ {
const string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ; private static readonly string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ;
const string TextRegex = @"(""|')[^']*(""|')"; private static readonly string TextRegex = @"(""|')[^']*(""|')";
// OPCODE_REG and below are initialized dynamically below. // OPCODE_REG and below are initialized dynamically below.
const string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)"; private static readonly string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)";
const string Opcode = "OPCODE"; private static readonly string Opcode = "OPCODE";
const string Data = "DATA"; private static readonly string Data = "DATA";
const string Directive = "DIRECTIVE"; private static readonly string Directive = "DIRECTIVE";
const string Elup = "ELUP"; private static readonly string Elup = "ELUP";
static string OpcodeRegex = ""; private static string _opcodeRegex = "";
static string DirectiveRegex = ""; private static string _directiveRegex = "";
static string DataRegex = ""; private static string _dataRegex = "";
public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span) public static IEnumerable<SnapshotHelper> GetTokens(SnapshotSpan span)
{ {
@ -47,13 +47,13 @@ namespace VSMerlin32.Coloring
TempRegex = ""; TempRegex = "";
foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes))) foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes)))
{ {
TempRegex += (token.ToString() + ("|")); TempRegex += token.ToString() + ("|");
} }
// we remove the last "|" added // we remove the last "|" added
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal));
OpcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex); _opcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex);
reg = new Regex(OpcodeRegex,RegexOptions.IgnoreCase); reg = new Regex(_opcodeRegex,RegexOptions.IgnoreCase);
Match opcodeMatch = reg.Match(formattedLine); Match opcodeMatch = reg.Match(formattedLine);
if (opcodeMatch.Success) if (opcodeMatch.Success)
{ {
@ -68,21 +68,21 @@ namespace VSMerlin32.Coloring
// OG NEW // OG NEW
// DIRECTIVES // DIRECTIVES
TempRegex = ""; TempRegex = "";
string ElupDirective = Resources.directives.ELUP; string elupDirective = Resources.directives.ELUP;
foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives))) foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives)))
{ {
if (token.ToString() != ElupDirective) if (token.ToString() != elupDirective)
TempRegex += (token.ToString() + ("|")); TempRegex += token.ToString() + ("|");
} }
// we remove the last "|" added // we remove the last "|" added
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal));
DirectiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex); _directiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex);
reg = new Regex(DirectiveRegex, RegexOptions.IgnoreCase); reg = new Regex(_directiveRegex, RegexOptions.IgnoreCase);
Match DirectiveMatch = reg.Match(formattedLine); Match directiveMatch = reg.Match(formattedLine);
if (DirectiveMatch.Success) if (directiveMatch.Success)
{ {
foreach (Capture directive in DirectiveMatch.Groups[Directive].Captures) foreach (Capture directive in directiveMatch.Groups[Directive].Captures)
{ {
if (directive.Index < commentMatch) if (directive.Index < commentMatch)
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, directive.Index + curLoc), directive.Length), Merlin32TokenTypes.Merlin32Directive); yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, directive.Index + curLoc), directive.Length), Merlin32TokenTypes.Merlin32Directive);
@ -91,10 +91,10 @@ namespace VSMerlin32.Coloring
// We also need to check for special ELUP directive... // We also need to check for special ELUP directive...
reg = new Regex(Resources.directives.ELUPRegex); reg = new Regex(Resources.directives.ELUPRegex);
Match ElupMatch = reg.Match(formattedLine); Match elupMatch = reg.Match(formattedLine);
if (ElupMatch.Success) if (elupMatch.Success)
{ {
foreach (Capture elup in ElupMatch.Groups[Elup].Captures) foreach (Capture elup in elupMatch.Groups[Elup].Captures)
{ {
if (elup.Index < commentMatch) if (elup.Index < commentMatch)
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, elup.Index + curLoc), elup.Length), Merlin32TokenTypes.Merlin32Directive); yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, elup.Index + curLoc), elup.Length), Merlin32TokenTypes.Merlin32Directive);
@ -106,13 +106,13 @@ namespace VSMerlin32.Coloring
TempRegex = ""; TempRegex = "";
foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines))) foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
{ {
TempRegex += (token.ToString() + ("|")); TempRegex += token.ToString() + ("|");
} }
// we remove the last "|" added // we remove the last "|" added
TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal));
DataRegex = string.Format(RegexBoilerplate, Data, TempRegex); _dataRegex = string.Format(RegexBoilerplate, Data, TempRegex);
reg = new Regex(DataRegex, RegexOptions.IgnoreCase); reg = new Regex(_dataRegex, RegexOptions.IgnoreCase);
Match dataMatch = reg.Match(formattedLine); Match dataMatch = reg.Match(formattedLine);
if (dataMatch.Success) if (dataMatch.Success)
{ {

View File

@ -10,13 +10,11 @@ using VSMerlin32.Coloring.Data;
namespace VSMerlin32.Coloring namespace VSMerlin32.Coloring
{ {
[Export(typeof(ITaggerProvider))] [Export(typeof(ITaggerProvider))]
[ContentType("Merlin32")] [ContentType("Merlin32")]
[TagType(typeof(Merlin32TokenTag))] [TagType(typeof(Merlin32TokenTag))]
internal sealed class Merlin32TokenTagProvider : ITaggerProvider internal sealed class Merlin32TokenTagProvider : ITaggerProvider
{ {
public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
{ {
return new Merlin32TokenTagger(buffer) as ITagger<T>; return new Merlin32TokenTagger(buffer) as ITagger<T>;
@ -35,17 +33,16 @@ namespace VSMerlin32.Coloring
internal sealed class Merlin32TokenTagger : ITagger<Merlin32TokenTag> internal sealed class Merlin32TokenTagger : ITagger<Merlin32TokenTag>
{ {
private ITextBuffer _buffer;
ITextBuffer _buffer; private readonly IDictionary<string, Merlin32TokenTypes> _merlin32Types;
IDictionary<string, Merlin32TokenTypes> _Merlin32Types;
internal Merlin32TokenTagger(ITextBuffer buffer) internal Merlin32TokenTagger(ITextBuffer buffer)
{ {
_buffer = buffer; _buffer = buffer;
_Merlin32Types = new Dictionary<string, Merlin32TokenTypes>(); _merlin32Types = new Dictionary<string, Merlin32TokenTypes>();
foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes))) foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes)))
_Merlin32Types.Add(token.ToString(), token); _merlin32Types.Add(token.ToString(), token);
} }
public event EventHandler<SnapshotSpanEventArgs> TagsChanged public event EventHandler<SnapshotSpanEventArgs> TagsChanged
@ -67,8 +64,9 @@ namespace VSMerlin32.Coloring
foreach (SnapshotHelper item in Merlin32CodeHelper.GetTokens(curSpan)) foreach (SnapshotHelper item in Merlin32CodeHelper.GetTokens(curSpan))
{ {
if (item.Snapshot.IntersectsWith(curSpan)) if (item.Snapshot.IntersectsWith(curSpan))
yield return new TagSpan<Merlin32TokenTag>(item.Snapshot, {
new Merlin32TokenTag(item.TokenType)); yield return new TagSpan<Merlin32TokenTag>(item.Snapshot, new Merlin32TokenTag(item.TokenType));
}
} }
//add an extra char location because of the space //add an extra char location because of the space

View File

@ -1,11 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Resources; using System.Resources;
using System.Reflection;
using System.Collections;
namespace VSMerlin32 namespace VSMerlin32
{ {

View File

@ -15,7 +15,6 @@ using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Text.Operations; using Microsoft.VisualStudio.Text.Operations;
namespace VSMerlin32 namespace VSMerlin32
{ {
#region Command Filter #region Command Filter
@ -39,37 +38,37 @@ namespace VSMerlin32
if (textView == null) if (textView == null)
return; return;
Func<CommandFilter> createCommandHandler = delegate() { return new CommandFilter(textViewAdapter, textView, this); }; Func<CommandFilter> createCommandHandler = delegate { return new CommandFilter(textViewAdapter, textView, this); };
textView.Properties.GetOrCreateSingletonProperty(createCommandHandler); textView.Properties.GetOrCreateSingletonProperty(createCommandHandler);
} }
} }
internal sealed class CommandFilter : IOleCommandTarget internal sealed class CommandFilter : IOleCommandTarget
{ {
private IOleCommandTarget m_nextCommandHandler; private IOleCommandTarget _nextCommandHandler;
private ITextView m_textView; private ITextView _textView;
private VsTextViewCreationListener m_provider; private VsTextViewCreationListener _provider;
private ICompletionSession m_session; private ICompletionSession _session;
internal CommandFilter(IVsTextView textViewAdapter, ITextView textView, VsTextViewCreationListener provider) internal CommandFilter(IVsTextView textViewAdapter, ITextView textView, VsTextViewCreationListener provider)
{ {
this.m_textView = textView; _textView = textView;
this.m_provider = provider; _provider = provider;
//add the command to the command chain //add the command to the command chain
textViewAdapter.AddCommandFilter(this, out m_nextCommandHandler); textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
} }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{ {
return m_nextCommandHandler.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); return _nextCommandHandler.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
} }
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{ {
if (VsShellUtilities.IsInAutomationFunction(m_provider.ServiceProvider)) if (VsShellUtilities.IsInAutomationFunction(_provider.ServiceProvider))
{ {
return m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); return _nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
} }
//make a copy of this so we can look at it after forwarding some commands //make a copy of this so we can look at it after forwarding some commands
uint commandID = nCmdID; uint commandID = nCmdID;
@ -87,56 +86,56 @@ namespace VSMerlin32
|| char.IsPunctuation(typedChar)) || char.IsPunctuation(typedChar))
{ {
//check for a a selection //check for a a selection
if (m_session != null && !m_session.IsDismissed) if (_session != null && !_session.IsDismissed)
{ {
//if the selection is fully selected, commit the current session //if the selection is fully selected, commit the current session
if (m_session.SelectedCompletionSet.SelectionStatus.IsSelected) if (_session.SelectedCompletionSet.SelectionStatus.IsSelected)
{ {
m_session.Commit(); _session.Commit();
//also, don't add the character to the buffer //also, don't add the character to the buffer
return VSConstants.S_OK; return VSConstants.S_OK;
} }
else else
{ {
//if there is no selection, dismiss the session //if there is no selection, dismiss the session
m_session.Dismiss(); _session.Dismiss();
} }
} }
} }
//pass along the command so the char is added to the buffer //pass along the command so the char is added to the buffer
int retVal = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); int retVal = _nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
bool handled = false; bool handled = false;
// Test for '-' is to catch ELUP (--^) // Test for '-' is to catch ELUP (--^)
if (!typedChar.Equals(char.MinValue) && ((char.IsLetterOrDigit(typedChar)) || ((typedChar == '\'') || (typedChar == '"') || (typedChar == '-')))) if (!typedChar.Equals(char.MinValue) && ((char.IsLetterOrDigit(typedChar)) || ((typedChar == '\'') || (typedChar == '"') || (typedChar == '-'))))
{ {
if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion if (_session == null || _session.IsDismissed) // If there is no active session, bring up completion
{ {
this.TriggerCompletion(); TriggerCompletion();
// No need to filter for single and double-quotes, the choice IS the characted, just doubled, and already populated in a single completionset if we're here... // No need to filter for single and double-quotes, the choice IS the characted, just doubled, and already populated in a single completionset if we're here...
if ((typedChar == '\'') || (typedChar == '"')) if ((typedChar == '\'') || (typedChar == '"'))
{ {
// We need to save the currect caret position because we'll position it in between the single/double quotes after the commit... // We need to save the currect caret position because we'll position it in between the single/double quotes after the commit...
ITextCaret CaretBeforeCommit = m_session.TextView.Caret; ITextCaret caretBeforeCommit = _session.TextView.Caret;
m_session.Commit(); _session.Commit();
this.m_textView.Caret.MoveTo(CaretBeforeCommit.Position.BufferPosition - 1); _textView.Caret.MoveTo(caretBeforeCommit.Position.BufferPosition - 1);
} }
else if (!m_session.IsDismissed) else if (!_session.IsDismissed)
{ {
m_session.Filter(); _session.Filter();
} }
} }
else //the completion session is already active, so just filter else //the completion session is already active, so just filter
{ {
m_session.Filter(); _session.Filter();
} }
handled = true; handled = true;
} }
else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE //redo the filter if there is a deletion else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE //redo the filter if there is a deletion
|| commandID == (uint)VSConstants.VSStd2KCmdID.DELETE) || commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
{ {
if (m_session != null && !m_session.IsDismissed) if (_session != null && !_session.IsDismissed)
m_session.Filter(); _session.Filter();
handled = true; handled = true;
} }
@ -148,20 +147,20 @@ namespace VSMerlin32
{ {
//the caret must be in a non-projection location //the caret must be in a non-projection location
SnapshotPoint? caretPoint = SnapshotPoint? caretPoint =
m_textView.Caret.Position.Point.GetPoint( _textView.Caret.Position.Point.GetPoint(
textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor);
if (!caretPoint.HasValue) if (!caretPoint.HasValue)
{ {
return false; return false;
} }
m_session = m_provider.CompletionBroker.CreateCompletionSession(m_textView, _session = _provider.CompletionBroker.CreateCompletionSession(_textView,
caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive),
true); true);
// We need to check now whether we are in a comment or not, because if we are, we don't want to provide a completion list to the user // We need to check now whether we are in a comment or not, because if we are, we don't want to provide a completion list to the user
ITextSnapshot snapshot = caretPoint.Value.Snapshot; ITextSnapshot snapshot = caretPoint.Value.Snapshot;
var triggerPoint = (SnapshotPoint)m_session.GetTriggerPoint(snapshot); var triggerPoint = (SnapshotPoint)_session.GetTriggerPoint(snapshot);
var snapshotSpan = new SnapshotSpan(triggerPoint, 0); var snapshotSpan = new SnapshotSpan(triggerPoint, 0);
foreach (VSMerlin32.Coloring.Data.SnapshotHelper item in VSMerlin32.Coloring.Merlin32CodeHelper.GetTokens(snapshotSpan)) foreach (VSMerlin32.Coloring.Data.SnapshotHelper item in VSMerlin32.Coloring.Merlin32CodeHelper.GetTokens(snapshotSpan))
{ {
@ -169,17 +168,17 @@ namespace VSMerlin32
{ {
if (item.TokenType == Merlin32TokenTypes.Merlin32Comment) if (item.TokenType == Merlin32TokenTypes.Merlin32Comment)
{ {
m_session.Dismiss(); _session.Dismiss();
break; break;
} }
} }
} }
if (!m_session.IsDismissed) if (!_session.IsDismissed)
{ {
//subscribe to the Dismissed event on the session //subscribe to the Dismissed event on the session
m_session.Dismissed += this.OnSessionDismissed; _session.Dismissed += OnSessionDismissed;
m_session.Start(); _session.Start();
} }
return true; return true;
@ -187,8 +186,8 @@ namespace VSMerlin32
private void OnSessionDismissed(object sender, EventArgs e) private void OnSessionDismissed(object sender, EventArgs e)
{ {
m_session.Dismissed -= this.OnSessionDismissed; _session.Dismissed -= OnSessionDismissed;
m_session = null; _session = null;
} }
} }

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text;
@ -26,20 +24,20 @@ namespace VSMerlin32
internal class Merlin32CompletionSource : ICompletionSource internal class Merlin32CompletionSource : ICompletionSource
{ {
private Merlin32CompletionSourceProvider m_sourceprovider; private Merlin32CompletionSourceProvider _sourceprovider;
private ITextBuffer m_buffer; private ITextBuffer _buffer;
private List<Completion> m_compList; private List<Completion> _compList;
private bool m_isDisposed = false; private bool _isDisposed;
public Merlin32CompletionSource(Merlin32CompletionSourceProvider sourceprovider, ITextBuffer buffer) public Merlin32CompletionSource(Merlin32CompletionSourceProvider sourceprovider, ITextBuffer buffer)
{ {
m_sourceprovider = sourceprovider; _sourceprovider = sourceprovider;
m_buffer = buffer; _buffer = buffer;
} }
public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
{ {
if (m_isDisposed) if (_isDisposed)
throw new ObjectDisposedException("Merlin32CompletionSource"); throw new ObjectDisposedException("Merlin32CompletionSource");
List<string> strList = new List<string>(); List<string> strList = new List<string>();
@ -78,27 +76,27 @@ namespace VSMerlin32
// strList[strList.IndexOf(Merlin32Directives.ELUP.ToString())] = "--^"; // strList[strList.IndexOf(Merlin32Directives.ELUP.ToString())] = "--^";
// OG // OG
} }
m_compList = new List<Completion>(); _compList = new List<Completion>();
foreach (string str in strList) foreach (string str in strList)
m_compList.Add(new Completion(str, str, str, null, null)); _compList.Add(new Completion(str, str, str, null, null));
completionSets.Add(new CompletionSet("All", "All", FindTokenSpanAtPosition(session.GetTriggerPoint(m_buffer), session), m_compList, null)); completionSets.Add(new CompletionSet("All", "All", FindTokenSpanAtPosition(session), _compList, null));
} }
private ITrackingSpan FindTokenSpanAtPosition(ITrackingPoint point, ICompletionSession session) private ITrackingSpan FindTokenSpanAtPosition(ICompletionSession session)
{ {
SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1; SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;
ITextStructureNavigator navigator = m_sourceprovider.NavigatorService.GetTextStructureNavigator(m_buffer); ITextStructureNavigator navigator = _sourceprovider.NavigatorService.GetTextStructureNavigator(_buffer);
TextExtent extent = navigator.GetExtentOfWord(currentPoint); TextExtent extent = navigator.GetExtentOfWord(currentPoint);
return currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); return currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);
} }
public void Dispose() public void Dispose()
{ {
if (!m_isDisposed) if (!_isDisposed)
{ {
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
m_isDisposed = true; _isDisposed = true;
} }
} }
} }

View File

@ -1,9 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Language.Intellisense;
using System.Collections.ObjectModel;
using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Tagging; using Microsoft.VisualStudio.Text.Tagging;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
@ -12,19 +10,17 @@ using VSMerlin32.Coloring;
namespace VSMerlin32 namespace VSMerlin32
{ {
[Export(typeof(IQuickInfoSourceProvider))] [Export(typeof(IQuickInfoSourceProvider))]
[ContentType("Merlin32")] [ContentType("Merlin32")]
[Name("Merlin32QuickInfo")] [Name("Merlin32QuickInfo")]
class Merlin32QuickInfoSourceProvider : IQuickInfoSourceProvider class Merlin32QuickInfoSourceProvider : IQuickInfoSourceProvider
{ {
[Import] [Import]
IBufferTagAggregatorFactoryService aggService = null; private IBufferTagAggregatorFactoryService _aggService = null;
public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer)
{ {
return new Merlin32QuickInfoSource(textBuffer, aggService.CreateTagAggregator<Merlin32TokenTag>(textBuffer)); return new Merlin32QuickInfoSource(textBuffer, _aggService.CreateTagAggregator<Merlin32TokenTag>(textBuffer));
} }
} }
@ -33,8 +29,7 @@ namespace VSMerlin32
private ITagAggregator<Merlin32TokenTag> _aggregator; private ITagAggregator<Merlin32TokenTag> _aggregator;
private ITextBuffer _buffer; private ITextBuffer _buffer;
private Merlin32KeywordsHelper _Merlin32OpcodesHelper = new Merlin32KeywordsHelper(); private Merlin32KeywordsHelper _Merlin32OpcodesHelper = new Merlin32KeywordsHelper();
private bool _disposed = false; private bool _disposed;
public Merlin32QuickInfoSource(ITextBuffer buffer, ITagAggregator<Merlin32TokenTag> aggregator) public Merlin32QuickInfoSource(ITextBuffer buffer, ITagAggregator<Merlin32TokenTag> aggregator)
{ {

View File

@ -2,13 +2,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Input;
using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
namespace VSLTK.Intellisense namespace VSLTK.Intellisense
{ {