/// <summary> /// Creates a tag provider for the specified buffer /// </summary> /// <typeparam name="T">The tag type</typeparam> /// <param name="buffer">The text buffer</param> /// <returns>The tag provider for the specified buffer or null if the buffer is null or the spelling /// service is unavailable.</returns> public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag { if (buffer == null || buffer.ContentType.IsOfType("R Markdown")) { return(null); } #pragma warning disable VSTHRD010 var config = SpellingServiceProxy.GetConfiguration(buffer); #pragma warning restore VSTHRD010 if (config == null) { return(null); } // Markdown has its own tagger if (buffer.ContentType.IsOfType("Markdown")) { return(new MarkdownTextTagger(buffer, classifierAggregatorService.GetClassifier(buffer), config.IgnoredClassificationsFor(buffer.ContentType.TypeName)) as ITagger <T>); } // Due to an issue with the built-in C# classifier, we avoid using it. This also lets us provide // configuration options to exclude certain elements from being spell checked if not wanted. // Through the configuration options, we can also specify this tagger be used for all C-style // code. Not all configuration options will apply but the structure is similar enough to make // most of them relevant. string filename = buffer.GetFilename(); if (buffer.ContentType.IsOfType("csharp") || (config.CSharpOptions.ApplyToAllCStyleLanguages && ClassifierFactory.IsCStyleCode(filename))) { // The C# options are passed to the tagger for local use since it tracks the state of the // lines in the buffer. Changing the global options will require that any open editors be // closed and reopened for the changes to take effect. return(new CSharpCommentTextTagger(buffer) { SupportsOldStyleXmlDocComments = ClassifierFactory.SupportsOldStyleXmlDocComments(filename), IgnoreXmlDocComments = config.CSharpOptions.IgnoreXmlDocComments, IgnoreDelimitedComments = config.CSharpOptions.IgnoreDelimitedComments, IgnoreStandardSingleLineComments = config.CSharpOptions.IgnoreStandardSingleLineComments, IgnoreQuadrupleSlashComments = config.CSharpOptions.IgnoreQuadrupleSlashComments, IgnoreNormalStrings = config.CSharpOptions.IgnoreNormalStrings, IgnoreVerbatimStrings = config.CSharpOptions.IgnoreVerbatimStrings, IgnoreInterpolatedStrings = config.CSharpOptions.IgnoreInterpolatedStrings, IgnoredXmlElements = config.IgnoredXmlElements, SpellCheckedAttributes = config.SpellCheckedXmlAttributes } as ITagger <T>); } return(new CommentTextTagger(buffer, classifierAggregatorService.GetClassifier(buffer), config.IgnoredXmlElements, config.SpellCheckedXmlAttributes, config.IgnoredClassificationsFor(buffer.ContentType.TypeName)) as ITagger <T>); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="buffer">The text buffer</param> /// <param name="view">The text view</param> /// <param name="naturalTextAggregator">The tag aggregator</param> /// <param name="urlAggregator">The URL aggregator</param> /// <param name="configuration">The spell checker configuration to use</param> /// <param name="dictionary">The spelling dictionary to use</param> public SpellingTagger(ITextBuffer buffer, ITextView view, ITagAggregator <INaturalTextTag> naturalTextAggregator, ITagAggregator <IUrlTag> urlAggregator, SpellCheckerConfiguration configuration, SpellingDictionary dictionary) { _isClosed = false; _buffer = buffer; _naturalTextAggregator = naturalTextAggregator; _urlAggregator = urlAggregator; _dispatcher = Dispatcher.CurrentDispatcher; this.configuration = configuration; _dictionary = dictionary; _dirtySpans = new List <SnapshotSpan>(); _misspellings = new List <MisspellingTag>(); wordsIgnoredOnce = new List <IgnoredOnceWord>(); inlineIgnoredWords = new List <InlineIgnoredWord>(); string filename = buffer.GetFilename(); wordSplitter = new WordSplitter { Configuration = configuration, Mnemonic = ClassifierFactory.GetMnemonic(filename), IsCStyleCode = ClassifierFactory.IsCStyleCode(filename) }; _buffer.Changed += BufferChanged; _naturalTextAggregator.TagsChanged += AggregatorTagsChanged; _urlAggregator.TagsChanged += AggregatorTagsChanged; _dictionary.DictionaryUpdated += DictionaryUpdated; _dictionary.ReplaceAll += ReplaceAll; _dictionary.IgnoreOnce += IgnoreOnce; view.Closed += ViewClosed; // Strings in SQL script can contain escaped single quotes which are apostrophes. Unescape them // so that they are spell checked correctly. unescapeApostrophes = buffer.ContentType.IsOfType("SQL Server Tools"); // To start with, the entire buffer is dirty. Split this into chunks so we update pieces at a time. ITextSnapshot snapshot = _buffer.CurrentSnapshot; foreach (var line in snapshot.Lines) { AddDirtySpan(line.Extent); } }