From 22df54122058ceb63e8a855db5727d22e5520ea8 Mon Sep 17 00:00:00 2001 From: Olivier Guinart Date: Sat, 14 Jan 2017 18:56:21 -0800 Subject: [PATCH 1/2] Fixed with regex improvements. Also enabled ELUP detection for autocompletion --- Coloring/Merlin32CodeHelper.cs | 101 ++++++++++++++++++--------- Intellisense/CompletionController.cs | 3 +- Resources/directives.Designer.cs | 2 +- Resources/directives.resx | 2 +- 4 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Coloring/Merlin32CodeHelper.cs b/Coloring/Merlin32CodeHelper.cs index 09f3279..dfc83d9 100644 --- a/Coloring/Merlin32CodeHelper.cs +++ b/Coloring/Merlin32CodeHelper.cs @@ -8,29 +8,34 @@ namespace VSMerlin32.Coloring { internal class Merlin32CodeHelper { - const string COMMENT_REG = @"((\u003B)|(\u002A))(.*)"; // ; - const string TEXT_REG = @"(""|')[^']*(""|')"; - // OPCODE_REG is initialized dynamically below. - static string OPCODE_REG = ""; - static string DIRECTIVE_REG = ""; - static string DATADEFINE_REG = ""; + const string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ; + const string TextRegex = @"(""|')[^']*(""|')"; + // OPCODE_REG and below are initialized dynamically below. + const string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)"; + const string Opcode = "OPCODE"; + const string Data = "DATA"; + const string Directive = "DIRECTIVE"; + const string Elup = "ELUP"; + static string OpcodeRegex = ""; + static string DirectiveRegex = ""; + static string DataRegex = ""; public static IEnumerable GetTokens(SnapshotSpan span) { - string strTempRegex; // temp var string + string TempRegex; // temp var string ITextSnapshotLine containingLine = span.Start.GetContainingLine(); int curLoc = containingLine.Start.Position; string formattedLine = containingLine.GetText(); int commentMatch = int.MaxValue; - Regex reg = new Regex(COMMENT_REG); + Regex reg = new Regex(CommentRegex); foreach (Match match in reg.Matches(formattedLine)) { commentMatch = match.Index < commentMatch ? match.Index : commentMatch; yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32Comment); } - reg = new Regex(TEXT_REG); + reg = new Regex(TextRegex); foreach (Match match in reg.Matches(formattedLine)) { if (match.Index < commentMatch) @@ -39,55 +44,83 @@ namespace VSMerlin32.Coloring // OG NEW // OPCODES - strTempRegex = ""; + TempRegex = ""; foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes))) { - strTempRegex += (token.ToString() + ("|")); + TempRegex += (token.ToString() + ("|")); } // we remove the last "|" added - strTempRegex = strTempRegex.Remove(strTempRegex.LastIndexOf("|")); - OPCODE_REG = string.Format(@"\b({0})\b", strTempRegex); + TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); + OpcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex); - reg = new Regex(OPCODE_REG,RegexOptions.IgnoreCase); - foreach (Match match in reg.Matches(formattedLine)) + reg = new Regex(OpcodeRegex,RegexOptions.IgnoreCase); + Match opcodeMatch = reg.Match(formattedLine); + if (opcodeMatch.Success) { - if (match.Index < commentMatch) - yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32Opcode); + foreach (Capture opcode in opcodeMatch.Groups[Opcode].Captures) + { + // An opcode after within a comment doesn't get a SnapShotSpan... + if (opcode.Index < commentMatch) + yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, opcode.Index + curLoc), opcode.Length), Merlin32TokenTypes.Merlin32Opcode); + } } // OG NEW // DIRECTIVES - strTempRegex = ""; + TempRegex = ""; + string ElupDirective = Resources.directives.ELUP; foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives))) { - if (token.ToString() != Resources.directives.ELUP) - strTempRegex += (token.ToString() + ("|")); + if (token.ToString() != ElupDirective) + TempRegex += (token.ToString() + ("|")); } - DIRECTIVE_REG = string.Format(@"\b({0})\b|{1}", strTempRegex, Resources.directives.ELUPRegex); - - reg = new Regex(DIRECTIVE_REG, RegexOptions.IgnoreCase); - foreach (Match match in reg.Matches(formattedLine)) + // we remove the last "|" added + TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); + DirectiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex); + + reg = new Regex(DirectiveRegex, RegexOptions.IgnoreCase); + Match DirectiveMatch = reg.Match(formattedLine); + if (DirectiveMatch.Success) { - if (match.Index < commentMatch) - yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32Directive); + foreach (Capture directive in DirectiveMatch.Groups[Directive].Captures) + { + if (directive.Index < commentMatch) + yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, directive.Index + curLoc), directive.Length), Merlin32TokenTypes.Merlin32Directive); + } + } + + // We also need to check for special ELUP directive... + reg = new Regex(Resources.directives.ELUPRegex); + Match ElupMatch = reg.Match(formattedLine); + if (ElupMatch.Success) + { + foreach (Capture elup in ElupMatch.Groups[Elup].Captures) + { + if (elup.Index < commentMatch) + yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, elup.Index + curLoc), elup.Length), Merlin32TokenTypes.Merlin32Directive); + } } // OG NEW // DATADEFINES - strTempRegex = ""; + TempRegex = ""; foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines))) { - strTempRegex += (token.ToString() + ("|")); + TempRegex += (token.ToString() + ("|")); } // we remove the last "|" added - strTempRegex = strTempRegex.Remove(strTempRegex.LastIndexOf("|")); - DATADEFINE_REG = string.Format(@"\b({0})\b", strTempRegex); + TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); + DataRegex = string.Format(RegexBoilerplate, Data, TempRegex); - reg = new Regex(DATADEFINE_REG, RegexOptions.IgnoreCase); - foreach (Match match in reg.Matches(formattedLine)) + reg = new Regex(DataRegex, RegexOptions.IgnoreCase); + Match dataMatch = reg.Match(formattedLine); + if (dataMatch.Success) { - if (match.Index < commentMatch) - yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32DataDefine); + foreach (Capture data in dataMatch.Groups[Data].Captures) + { + if (data.Index < commentMatch) + yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, data.Index + curLoc), data.Length), Merlin32TokenTypes.Merlin32DataDefine); + } } } } diff --git a/Intellisense/CompletionController.cs b/Intellisense/CompletionController.cs index 0a04460..b188f1c 100644 --- a/Intellisense/CompletionController.cs +++ b/Intellisense/CompletionController.cs @@ -107,7 +107,8 @@ namespace VSMerlin32 //pass along the command so the char is added to the buffer int retVal = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); bool handled = false; - if (!typedChar.Equals(char.MinValue) && ((char.IsLetterOrDigit(typedChar)) || ((typedChar == '\'') || (typedChar == '"')))) + // Test for '-' is to catch ELUP (--^) + 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 { diff --git a/Resources/directives.Designer.cs b/Resources/directives.Designer.cs index eff2724..6134741 100644 --- a/Resources/directives.Designer.cs +++ b/Resources/directives.Designer.cs @@ -151,7 +151,7 @@ namespace VSMerlin32.Resources { } /// - /// Looks up a localized string similar to (--\^). + /// Looks up a localized string similar to (^|\s)(?<ELUP>--\^)(\s|$). /// internal static string ELUPRegex { get { diff --git a/Resources/directives.resx b/Resources/directives.resx index 07d9f1f..aa598b8 100644 --- a/Resources/directives.resx +++ b/Resources/directives.resx @@ -148,7 +148,7 @@ End of LUP - (--\^) + (^|\s)(?<ELUP>--\^)(\s|$) --^ From 6933f485a383c479fd37476d5ed37a01b5ca9366 Mon Sep 17 00:00:00 2001 From: Olivier Guinart Date: Sun, 15 Jan 2017 14:44:43 -0800 Subject: [PATCH 2/2] Refactoring only --- Coloring/Classification/ClassificationType.cs | 12 ++-- .../Classification/Merlin32sClassifier.cs | 32 ++++----- Coloring/Merlin32CodeHelper.cs | 64 ++++++++--------- Coloring/Merlin32TokenTag.cs | 20 +++--- Coloring/Merlin32TokenTypes.cs | 9 +-- Intellisense/CompletionController.cs | 71 +++++++++---------- Intellisense/CompletionSource.cs | 30 ++++---- Intellisense/Merlin32QuickInfoSource.cs | 11 +-- Intellisense/QuickInfoController.cs | 3 - 9 files changed, 115 insertions(+), 137 deletions(-) diff --git a/Coloring/Classification/ClassificationType.cs b/Coloring/Classification/ClassificationType.cs index aa99655..7a4cb7d 100644 --- a/Coloring/Classification/ClassificationType.cs +++ b/Coloring/Classification/ClassificationType.cs @@ -13,36 +13,36 @@ namespace VSMerlin32.Coloring.Classification /// [Export(typeof(ClassificationTypeDefinition))] [Name(Merlin32TokenHelper.Merlin32Opcode)] - internal static ClassificationTypeDefinition opcode = null; + internal static ClassificationTypeDefinition Opcode = null; /// /// Defines the "directive" classification type. /// [Export(typeof(ClassificationTypeDefinition))] [Name(Merlin32TokenHelper.Merlin32Directive)] - internal static ClassificationTypeDefinition directive = null; + internal static ClassificationTypeDefinition Directive = null; /// /// Defines the "datadefine" classification type. /// [Export(typeof(ClassificationTypeDefinition))] [Name(Merlin32TokenHelper.Merlin32DataDefine)] - internal static ClassificationTypeDefinition datadefine = null; + internal static ClassificationTypeDefinition Datadefine = null; /// /// Defines the "text" classification type. /// [Export(typeof(ClassificationTypeDefinition))] [Name(Merlin32TokenHelper.Merlin32Text)] - internal static ClassificationTypeDefinition text = null; + internal static ClassificationTypeDefinition Text = null; /// /// Defines the "comment" classification type. /// [Export(typeof(ClassificationTypeDefinition))] [Name(Merlin32TokenHelper.Merlin32Comment)] - internal static ClassificationTypeDefinition comment = null; - + internal static ClassificationTypeDefinition Comment = null; + #endregion } } diff --git a/Coloring/Classification/Merlin32sClassifier.cs b/Coloring/Classification/Merlin32sClassifier.cs index 332dbeb..5cce64c 100644 --- a/Coloring/Classification/Merlin32sClassifier.cs +++ b/Coloring/Classification/Merlin32sClassifier.cs @@ -13,7 +13,6 @@ namespace VSMerlin32.Coloring.Classification [TagType(typeof(ClassificationTag))] internal sealed class Merlin32ClassifierProvider : ITaggerProvider { - [Export] [Name("Merlin32")] [BaseDefinition("code")] @@ -28,34 +27,33 @@ namespace VSMerlin32.Coloring.Classification internal IClassificationTypeRegistryService ClassificationTypeRegistry = null; [Import] - internal IBufferTagAggregatorFactoryService aggregatorFactory = null; + internal IBufferTagAggregatorFactoryService AggregatorFactory = null; public ITagger CreateTagger(ITextBuffer buffer) where T : ITag { + ITagAggregator merlin32TagAggregator = + AggregatorFactory.CreateTagAggregator(buffer); - ITagAggregator Merlin32TagAggregator = - aggregatorFactory.CreateTagAggregator(buffer); - - return new Merlin32Classifier(buffer, Merlin32TagAggregator, ClassificationTypeRegistry) as ITagger; + return new Merlin32Classifier(buffer, merlin32TagAggregator, ClassificationTypeRegistry) as ITagger; } } internal sealed class Merlin32Classifier : ITagger { - ITextBuffer _buffer; - ITagAggregator _aggregator; - IDictionary _Merlin32Types; + private ITextBuffer _buffer; + private readonly ITagAggregator _aggregator; + private readonly IDictionary _merlin32Types; internal Merlin32Classifier(ITextBuffer buffer, - ITagAggregator Merlin32TagAggregator, + ITagAggregator merlin32TagAggregator, IClassificationTypeRegistryService typeService) { _buffer = buffer; - _aggregator = Merlin32TagAggregator; - _Merlin32Types = new Dictionary(); + _aggregator = merlin32TagAggregator; + _merlin32Types = new Dictionary(); foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes))) - _Merlin32Types[token] = typeService.GetClassificationType(token.ToString()); + _merlin32Types[token] = typeService.GetClassificationType(token.ToString()); } public event EventHandler TagsChanged @@ -66,13 +64,11 @@ namespace VSMerlin32.Coloring.Classification public IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans) { - - foreach (var tagSpan in this._aggregator.GetTags(spans)) + foreach (var tagSpan in _aggregator.GetTags(spans)) { var tagSpans = tagSpan.Span.GetSpans(spans[0].Snapshot); - yield return - new TagSpan(tagSpans[0], - new ClassificationTag(_Merlin32Types[tagSpan.Tag.Tokentype])); + yield return + new TagSpan(tagSpans[0], new ClassificationTag(_merlin32Types[tagSpan.Tag.Tokentype])); } } } diff --git a/Coloring/Merlin32CodeHelper.cs b/Coloring/Merlin32CodeHelper.cs index dfc83d9..efa0fe9 100644 --- a/Coloring/Merlin32CodeHelper.cs +++ b/Coloring/Merlin32CodeHelper.cs @@ -8,18 +8,18 @@ namespace VSMerlin32.Coloring { internal class Merlin32CodeHelper { - const string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ; - const string TextRegex = @"(""|')[^']*(""|')"; + private static readonly string CommentRegex = @"((\u003B)|(\u002A))(.*)"; // ; + private static readonly string TextRegex = @"(""|')[^']*(""|')"; // OPCODE_REG and below are initialized dynamically below. - const string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)"; - const string Opcode = "OPCODE"; - const string Data = "DATA"; - const string Directive = "DIRECTIVE"; - const string Elup = "ELUP"; - static string OpcodeRegex = ""; - static string DirectiveRegex = ""; - static string DataRegex = ""; - + private static readonly string RegexBoilerplate = @"(\b|\s)(?<{0}>{1})(\b|\s)"; + private static readonly string Opcode = "OPCODE"; + private static readonly string Data = "DATA"; + private static readonly string Directive = "DIRECTIVE"; + private static readonly string Elup = "ELUP"; + private static string _opcodeRegex = ""; + private static string _directiveRegex = ""; + private static string _dataRegex = ""; + public static IEnumerable GetTokens(SnapshotSpan span) { string TempRegex; // temp var string @@ -47,13 +47,13 @@ namespace VSMerlin32.Coloring TempRegex = ""; foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes))) { - TempRegex += (token.ToString() + ("|")); + TempRegex += token.ToString() + ("|"); } // we remove the last "|" added - TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); - OpcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex); + TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal)); + _opcodeRegex = string.Format(RegexBoilerplate, Opcode, TempRegex); - reg = new Regex(OpcodeRegex,RegexOptions.IgnoreCase); + reg = new Regex(_opcodeRegex,RegexOptions.IgnoreCase); Match opcodeMatch = reg.Match(formattedLine); if (opcodeMatch.Success) { @@ -68,21 +68,21 @@ namespace VSMerlin32.Coloring // OG NEW // DIRECTIVES TempRegex = ""; - string ElupDirective = Resources.directives.ELUP; + string elupDirective = Resources.directives.ELUP; foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives))) { - if (token.ToString() != ElupDirective) - TempRegex += (token.ToString() + ("|")); + if (token.ToString() != elupDirective) + TempRegex += token.ToString() + ("|"); } // we remove the last "|" added - TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); - DirectiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex); - - reg = new Regex(DirectiveRegex, RegexOptions.IgnoreCase); - Match DirectiveMatch = reg.Match(formattedLine); - if (DirectiveMatch.Success) + TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal)); + _directiveRegex = string.Format(RegexBoilerplate, Directive, TempRegex); + + reg = new Regex(_directiveRegex, RegexOptions.IgnoreCase); + Match directiveMatch = reg.Match(formattedLine); + if (directiveMatch.Success) { - foreach (Capture directive in DirectiveMatch.Groups[Directive].Captures) + foreach (Capture directive in directiveMatch.Groups[Directive].Captures) { if (directive.Index < commentMatch) 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... reg = new Regex(Resources.directives.ELUPRegex); - Match ElupMatch = reg.Match(formattedLine); - if (ElupMatch.Success) + Match elupMatch = reg.Match(formattedLine); + if (elupMatch.Success) { - foreach (Capture elup in ElupMatch.Groups[Elup].Captures) + foreach (Capture elup in elupMatch.Groups[Elup].Captures) { if (elup.Index < commentMatch) 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 = ""; foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines))) { - TempRegex += (token.ToString() + ("|")); + TempRegex += token.ToString() + ("|"); } // we remove the last "|" added - TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|")); - DataRegex = string.Format(RegexBoilerplate, Data, TempRegex); + TempRegex = TempRegex.Remove(TempRegex.LastIndexOf("|", StringComparison.Ordinal)); + _dataRegex = string.Format(RegexBoilerplate, Data, TempRegex); - reg = new Regex(DataRegex, RegexOptions.IgnoreCase); + reg = new Regex(_dataRegex, RegexOptions.IgnoreCase); Match dataMatch = reg.Match(formattedLine); if (dataMatch.Success) { diff --git a/Coloring/Merlin32TokenTag.cs b/Coloring/Merlin32TokenTag.cs index d225c1c..08ec029 100644 --- a/Coloring/Merlin32TokenTag.cs +++ b/Coloring/Merlin32TokenTag.cs @@ -10,20 +10,18 @@ using VSMerlin32.Coloring.Data; namespace VSMerlin32.Coloring { - [Export(typeof(ITaggerProvider))] [ContentType("Merlin32")] [TagType(typeof(Merlin32TokenTag))] internal sealed class Merlin32TokenTagProvider : ITaggerProvider { - public ITagger CreateTagger(ITextBuffer buffer) where T : ITag { return new Merlin32TokenTagger(buffer) as ITagger; } } - public class Merlin32TokenTag : ITag + public class Merlin32TokenTag : ITag { public Merlin32TokenTypes Tokentype { get; private set; } @@ -35,17 +33,16 @@ namespace VSMerlin32.Coloring internal sealed class Merlin32TokenTagger : ITagger { - - ITextBuffer _buffer; - IDictionary _Merlin32Types; + private ITextBuffer _buffer; + private readonly IDictionary _merlin32Types; internal Merlin32TokenTagger(ITextBuffer buffer) { _buffer = buffer; - _Merlin32Types = new Dictionary(); + _merlin32Types = new Dictionary(); foreach (Merlin32TokenTypes token in Enum.GetValues(typeof(Merlin32TokenTypes))) - _Merlin32Types.Add(token.ToString(), token); + _merlin32Types.Add(token.ToString(), token); } public event EventHandler TagsChanged @@ -61,14 +58,15 @@ namespace VSMerlin32.Coloring { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); int curLoc = containingLine.Start.Position; - + string formattedLine = containingLine.GetText(); foreach (SnapshotHelper item in Merlin32CodeHelper.GetTokens(curSpan)) { if (item.Snapshot.IntersectsWith(curSpan)) - yield return new TagSpan(item.Snapshot, - new Merlin32TokenTag(item.TokenType)); + { + yield return new TagSpan(item.Snapshot, new Merlin32TokenTag(item.TokenType)); + } } //add an extra char location because of the space diff --git a/Coloring/Merlin32TokenTypes.cs b/Coloring/Merlin32TokenTypes.cs index f41693b..b1e483d 100644 --- a/Coloring/Merlin32TokenTypes.cs +++ b/Coloring/Merlin32TokenTypes.cs @@ -1,11 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Resources; -using System.Reflection; -using System.Collections; namespace VSMerlin32 { @@ -51,7 +46,7 @@ namespace VSMerlin32 DA, DW, DDB, DFB, DB, ADR, ADRL, HEX, DS, DC, DE, /* ? */ ASC, DCI, INV, FLS, REV, STR, STRL, - CHK + CHK } class Merlin32KeywordsHelper @@ -85,7 +80,7 @@ namespace VSMerlin32 foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines))) { _Merlin32KeywordsQuickInfo[token.ToString()] = rsData.GetString(token.ToString()); - } + } /* _Merlin32OpcodesQuickInfo[Merlin32Opcodes.ORG.ToString()] = VSMerlin32.strings.ORG; */ diff --git a/Intellisense/CompletionController.cs b/Intellisense/CompletionController.cs index b188f1c..24c0acf 100644 --- a/Intellisense/CompletionController.cs +++ b/Intellisense/CompletionController.cs @@ -15,7 +15,6 @@ using Microsoft.VisualStudio.Utilities; using Microsoft.VisualStudio.Text.Operations; - namespace VSMerlin32 { #region Command Filter @@ -39,37 +38,37 @@ namespace VSMerlin32 if (textView == null) return; - Func createCommandHandler = delegate() { return new CommandFilter(textViewAdapter, textView, this); }; + Func createCommandHandler = delegate { return new CommandFilter(textViewAdapter, textView, this); }; textView.Properties.GetOrCreateSingletonProperty(createCommandHandler); } } internal sealed class CommandFilter : IOleCommandTarget { - private IOleCommandTarget m_nextCommandHandler; - private ITextView m_textView; - private VsTextViewCreationListener m_provider; - private ICompletionSession m_session; + private IOleCommandTarget _nextCommandHandler; + private ITextView _textView; + private VsTextViewCreationListener _provider; + private ICompletionSession _session; internal CommandFilter(IVsTextView textViewAdapter, ITextView textView, VsTextViewCreationListener provider) { - this.m_textView = textView; - this.m_provider = provider; + _textView = textView; + _provider = provider; //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) { - 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) { - 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 uint commandID = nCmdID; @@ -87,56 +86,56 @@ namespace VSMerlin32 || char.IsPunctuation(typedChar)) { //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 (m_session.SelectedCompletionSet.SelectionStatus.IsSelected) + if (_session.SelectedCompletionSet.SelectionStatus.IsSelected) { - m_session.Commit(); + _session.Commit(); //also, don't add the character to the buffer return VSConstants.S_OK; } else { //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 - int retVal = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); + int retVal = _nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); bool handled = false; // Test for '-' is to catch ELUP (--^) 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... 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... - ITextCaret CaretBeforeCommit = m_session.TextView.Caret; - m_session.Commit(); - this.m_textView.Caret.MoveTo(CaretBeforeCommit.Position.BufferPosition - 1); + ITextCaret caretBeforeCommit = _session.TextView.Caret; + _session.Commit(); + _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 { - m_session.Filter(); + _session.Filter(); } handled = true; } else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE //redo the filter if there is a deletion || commandID == (uint)VSConstants.VSStd2KCmdID.DELETE) { - if (m_session != null && !m_session.IsDismissed) - m_session.Filter(); + if (_session != null && !_session.IsDismissed) + _session.Filter(); handled = true; } @@ -148,20 +147,20 @@ namespace VSMerlin32 { //the caret must be in a non-projection location SnapshotPoint? caretPoint = - m_textView.Caret.Position.Point.GetPoint( + _textView.Caret.Position.Point.GetPoint( textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return false; } - m_session = m_provider.CompletionBroker.CreateCompletionSession(m_textView, + _session = _provider.CompletionBroker.CreateCompletionSession(_textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), 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 ITextSnapshot snapshot = caretPoint.Value.Snapshot; - var triggerPoint = (SnapshotPoint)m_session.GetTriggerPoint(snapshot); + var triggerPoint = (SnapshotPoint)_session.GetTriggerPoint(snapshot); var snapshotSpan = new SnapshotSpan(triggerPoint, 0); foreach (VSMerlin32.Coloring.Data.SnapshotHelper item in VSMerlin32.Coloring.Merlin32CodeHelper.GetTokens(snapshotSpan)) { @@ -169,17 +168,17 @@ namespace VSMerlin32 { if (item.TokenType == Merlin32TokenTypes.Merlin32Comment) { - m_session.Dismiss(); + _session.Dismiss(); break; } } } - if (!m_session.IsDismissed) + if (!_session.IsDismissed) { //subscribe to the Dismissed event on the session - m_session.Dismissed += this.OnSessionDismissed; - m_session.Start(); + _session.Dismissed += OnSessionDismissed; + _session.Start(); } return true; @@ -187,8 +186,8 @@ namespace VSMerlin32 private void OnSessionDismissed(object sender, EventArgs e) { - m_session.Dismissed -= this.OnSessionDismissed; - m_session = null; + _session.Dismissed -= OnSessionDismissed; + _session = null; } } diff --git a/Intellisense/CompletionSource.cs b/Intellisense/CompletionSource.cs index 77b59c5..800eb85 100644 --- a/Intellisense/CompletionSource.cs +++ b/Intellisense/CompletionSource.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.ComponentModel.Composition; using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Text; @@ -26,20 +24,20 @@ namespace VSMerlin32 internal class Merlin32CompletionSource : ICompletionSource { - private Merlin32CompletionSourceProvider m_sourceprovider; - private ITextBuffer m_buffer; - private List m_compList; - private bool m_isDisposed = false; + private Merlin32CompletionSourceProvider _sourceprovider; + private ITextBuffer _buffer; + private List _compList; + private bool _isDisposed; public Merlin32CompletionSource(Merlin32CompletionSourceProvider sourceprovider, ITextBuffer buffer) { - m_sourceprovider = sourceprovider; - m_buffer = buffer; + _sourceprovider = sourceprovider; + _buffer = buffer; } public void AugmentCompletionSession(ICompletionSession session, IList completionSets) { - if (m_isDisposed) + if (_isDisposed) throw new ObjectDisposedException("Merlin32CompletionSource"); List strList = new List(); @@ -78,27 +76,27 @@ namespace VSMerlin32 // strList[strList.IndexOf(Merlin32Directives.ELUP.ToString())] = "--^"; // OG } - m_compList = new List(); + _compList = new List(); 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; - ITextStructureNavigator navigator = m_sourceprovider.NavigatorService.GetTextStructureNavigator(m_buffer); + ITextStructureNavigator navigator = _sourceprovider.NavigatorService.GetTextStructureNavigator(_buffer); TextExtent extent = navigator.GetExtentOfWord(currentPoint); return currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); } public void Dispose() { - if (!m_isDisposed) + if (!_isDisposed) { GC.SuppressFinalize(this); - m_isDisposed = true; + _isDisposed = true; } } } diff --git a/Intellisense/Merlin32QuickInfoSource.cs b/Intellisense/Merlin32QuickInfoSource.cs index cfc18ed..c6b8924 100644 --- a/Intellisense/Merlin32QuickInfoSource.cs +++ b/Intellisense/Merlin32QuickInfoSource.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.VisualStudio.Language.Intellisense; -using System.Collections.ObjectModel; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Tagging; using System.ComponentModel.Composition; @@ -12,19 +10,17 @@ using VSMerlin32.Coloring; namespace VSMerlin32 { - [Export(typeof(IQuickInfoSourceProvider))] [ContentType("Merlin32")] [Name("Merlin32QuickInfo")] class Merlin32QuickInfoSourceProvider : IQuickInfoSourceProvider { - [Import] - IBufferTagAggregatorFactoryService aggService = null; + private IBufferTagAggregatorFactoryService _aggService = null; public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) { - return new Merlin32QuickInfoSource(textBuffer, aggService.CreateTagAggregator(textBuffer)); + return new Merlin32QuickInfoSource(textBuffer, _aggService.CreateTagAggregator(textBuffer)); } } @@ -33,8 +29,7 @@ namespace VSMerlin32 private ITagAggregator _aggregator; private ITextBuffer _buffer; private Merlin32KeywordsHelper _Merlin32OpcodesHelper = new Merlin32KeywordsHelper(); - private bool _disposed = false; - + private bool _disposed; public Merlin32QuickInfoSource(ITextBuffer buffer, ITagAggregator aggregator) { diff --git a/Intellisense/QuickInfoController.cs b/Intellisense/QuickInfoController.cs index 35aa42b..92b055d 100644 --- a/Intellisense/QuickInfoController.cs +++ b/Intellisense/QuickInfoController.cs @@ -2,13 +2,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -using System; using System.Collections.Generic; -using System.Windows.Input; using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; -using Microsoft.VisualStudio.Utilities; namespace VSLTK.Intellisense {