/// <summary> /// Get the dictionary for the specified buffer /// </summary> /// <param name="buffer">The buffer for which to get a dictionary</param> /// <returns>The spelling dictionary for the buffer or null if one is not provided</returns> public SpellingDictionary GetDictionary(ITextBuffer buffer) { SpellingDictionary service = null; if (buffer != null && !buffer.Properties.TryGetProperty(typeof(SpellingDictionary), out service)) { // Get the configuration and create the dictionary based on the configuration var config = this.GetConfiguration(buffer); if (config != null) { // Create a dictionary for each configuration dictionary language ignoring any that are // invalid and duplicates caused by missing languages which return the en-US dictionary. var globalDictionaries = config.DictionaryLanguages.Select(l => GlobalDictionary.CreateGlobalDictionary(l, globalServiceProvider, config.AdditionalDictionaryFolders, config.RecognizedWords)).Where( d => d != null).Distinct().ToList(); if (globalDictionaries.Any()) { service = new SpellingDictionary(globalDictionaries, config.IgnoredWords); buffer.Properties[typeof(SpellingDictionary)] = service; } } } return(service); }
//===================================================================== /// <inheritdoc /> public ISpellingDictionary GetDictionary(ITextBuffer buffer) { ISpellingDictionary service = null; if (buffer.Properties.TryGetProperty(typeof(SpellingDictionaryService), out service)) { return(service); } List <ISpellingDictionary> bufferSpecificDictionaries = new List <ISpellingDictionary>(); foreach (var provider in bufferSpecificDictionaryProviders) { var dictionary = provider.Value.GetDictionary(buffer); if (dictionary != null) { bufferSpecificDictionaries.Add(dictionary); } } // Create or get the existing global dictionary for the default language var globalDictionary = GlobalDictionary.CreateGlobalDictionary(null); if (globalDictionary != null) { service = new SpellingDictionaryService(bufferSpecificDictionaries, globalDictionary); buffer.Properties[typeof(SpellingDictionaryService)] = service; } return(service); }
/// <summary> /// Get the dictionary for the specified buffer /// </summary> /// <param name="buffer">The buffer for which to get a dictionary</param> /// <returns>The spelling dictionary for the buffer or null if one is not provided</returns> public SpellingDictionary GetDictionary(ITextBuffer buffer) { SpellingDictionary service = null; if (buffer != null && !buffer.Properties.TryGetProperty(typeof(SpellingDictionary), out service)) { // Get the configuration and create the dictionary based on the configuration var config = this.GetConfiguration(buffer); if (config != null) { // Create or get the existing global dictionary for the default language var globalDictionary = GlobalDictionary.CreateGlobalDictionary(config.DefaultLanguage, globalServiceProvider, config.AdditionalDictionaryFolders, config.RecognizedWords); if (globalDictionary != null) { service = new SpellingDictionary(globalDictionary, config.IgnoredWords); buffer.Properties[typeof(SpellingDictionary)] = service; } } } return(service); }