Skip to content

Commit

Permalink
Fixes and new menu option
Browse files Browse the repository at this point in the history
- Fixed loading of the default ignored words file in the absence of a default global configuration file.  Fixes #223.
- Fixed loading of ignored words files so that words starting with an invalid escape sequence have the leading backslash removed.  Fixes #222.
- Fixed saving words to the user dictionary file so that words added by other instances of Visual Studio are not lost.  Fixes #219.
- Updated the word splitter to split text on emoji characters.  This prevents them from being included as part of the preceding/following word and fixes a crash in NHunSpell that can occur if they are included as part of the word when using non-US dictionaries.  Fixes #216.  Fixes #218.
- Added the menu option Tools, Spell Checker, Disable/Enable in Current Session to disable/enable interactive spell checking in the current Visual Studio session.  Closes #149.
  • Loading branch information
EWSoftware committed Jan 23, 2021
1 parent 9bbd3ea commit 1856b88
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 111 deletions.
20 changes: 16 additions & 4 deletions Docs/Content/Installation.aml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ them.</para>
<linkText>Visual Studio 2017 or later</linkText>
<linkUri>https://marketplace.visualstudio.com/items?itemName=EWoodruff.VisualStudioSpellCheckerVS2017andLater</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>) using the <ui>Tools | Extension and Updates</ui> option. Select the online marketplace and
</externalLink>) using the <ui>Tools | Extension and Updates</ui> option (Visual Studio 2017) or
<ui>Extensions | Manage Extensions</ui> option (Visual Studio 2019 or later). Select the online marketplace and
search for "Visual Studio Spell Checker". Include the quote marks for an exact match and find the one created by
<legacyItalic>EWSoftware</legacyItalic>. Once found, you can click the <ui>Download</ui> button to download and
install it.</para>

<para>Once installed, you will find a new <ui>Spell Checker</ui> option on the <ui>Tools</ui> menu.
Unless other packages have been installed that alter its position, it will be the fourth option from the bottom
between the <ui>External Tools</ui> and the <ui>Import and Export Settings</ui> options. Its submenu contains
following options:</para>
Unless other packages have been installed that alter its position, it will be the fourth or fifth option from the
bottom between the <ui>External Tools</ui> and the <ui>Import and Export Settings</ui> options. Its submenu
contains following options:</para>

<list class="bullet">
<listItem>
Expand All @@ -65,6 +66,17 @@ way to find and resolve spelling issues without using the interactive spell chec
<link xlink:href="63d5096c-6695-441d-886a-01a120f2894a" /> topic for more information.</para>
</listItem>

<listItem>
<para><ui>Disable in Current Session</ui>/<ui>Enable in Current Session</ui> - This option acts as a
toggle to temporarily disable and subsequently re-enable interactive spell checking in editors during the current
Visual Studio session. This is separate from the <ui>Spell check as you type</ui> option in the configuration
files. If that option is disabled, this menu option will have no effect.</para>

<para>Use this option to temporarily suspend spell checking in the current session. To turn it off
on a more permanent basis either globally or for a solution, project, folder, or file, use the configuration file
option instead.</para>
</listItem>

<listItem>
<para><ui>Spell Check Entire Solution</ui> - This opens the
<link xlink:href="fa790577-88c0-4141-b8f4-d8b70f625cfd">solution/project spell check tool window</link> and
Expand Down
6 changes: 6 additions & 0 deletions Docs/Content/VersionHistory/VersionHistory.aml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ project. Select a version below to see a description of its changes.</para>
<section>
<content>
<list class="bullet">
<listItem>
<para>
<link xlink:href="bb88f7d5-2491-457e-9ba3-8d7d0bbc8615" />
</para>
</listItem>

<listItem>
<para>
<link xlink:href="04d6f71e-e4c3-41c2-b46e-fd0da1239843" />
Expand Down
48 changes: 48 additions & 0 deletions Docs/Content/VersionHistory/v2021.1.23.0.aml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="bb88f7d5-2491-457e-9ba3-8d7d0bbc8615" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Changes in this release:</para>
</introduction>

<section>
<content>
<list class="bullet">
<listItem>
<para>Fixed loading of the default ignored words file in the absence of a default global configuration
file.</para>
</listItem>

<listItem>
<para>Fixed loading of ignored words files so that words starting with an invalid escape sequence
have the leading backslash removed.</para>
</listItem>

<listItem>
<para>Fixed saving words to the user dictionary file so that words added by other instances of Visual
Studio are not lost.</para>
</listItem>

<listItem>
<para>Updated the word splitter to split text on emoji characters. This prevents them from being
included as part of the preceding/following word and fixes a crash in NHunSpell that can occur if they are
included as part of the word when using non-US dictionaries.</para>
</listItem>

<listItem>
<para>Added the menu option <legacyBold>Tools</legacyBold>, <legacyBold>Spell Checker</legacyBold>,
<legacyBold>Disable/Enable in Current Session</legacyBold> to temporarily disable and subsequently re-enable
interactive spell checking in editors during the current Visual Studio session.</para>
</listItem>

</list>

</content>
</section>

<relatedTopics>
<link xlink:href="548dc6d7-6d08-4006-82b3-d5830be96f04" />
</relatedTopics>

</developerConceptualDocument>
</topic>
9 changes: 7 additions & 2 deletions Docs/ContentLayout.content
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,16 @@
<HelpKeyword index="K" term="submitting changes" />
</HelpKeywords>
</Topic>
<Topic id="548dc6d7-6d08-4006-82b3-d5830be96f04" visible="True" isExpanded="true" title="Version History">
<Topic id="548dc6d7-6d08-4006-82b3-d5830be96f04" visible="True" isSelected="true" title="Version History">
<HelpKeywords>
<HelpKeyword index="K" term="version, history" />
</HelpKeywords>
<Topic id="04d6f71e-e4c3-41c2-b46e-fd0da1239843" visible="True" isSelected="true" title="Version 2020.8.24.0">
<Topic id="bb88f7d5-2491-457e-9ba3-8d7d0bbc8615" visible="True" title="Version 2021.1.23.0">
<HelpKeywords>
<HelpKeyword index="K" term="versions, 2021.1.23.0" />
</HelpKeywords>
</Topic>
<Topic id="04d6f71e-e4c3-41c2-b46e-fd0da1239843" visible="True" title="Version 2020.8.24.0">
<HelpKeywords>
<HelpKeyword index="K" term="versions, 2020.8.24.0" />
</HelpKeywords>
Expand Down
5 changes: 3 additions & 2 deletions Docs/VSSpellCheckerDocs.shfbproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
<NamingMethod>Guid</NamingMethod>
<HelpTitle>Visual Studio Spell Checker Documentation</HelpTitle>
<FeedbackEMailAddress>Eric%40EWoodruff.us</FeedbackEMailAddress>
<CopyrightText>Copyright \xA9 2013-2020, Eric Woodruff, All rights reserved</CopyrightText>
<CopyrightText>Copyright \xA9 2013-2021, Eric Woodruff, All rights reserved</CopyrightText>
<CopyrightHref>https://GitHub.com/EWSoftware/VSSpellChecker</CopyrightHref>
<ContentPlacement>AboveNamespaces</ContentPlacement>
<NamespaceSummaries>
<NamespaceSummaryItem name="VisualStudio.SpellChecker.Definitions" isDocumented="True" xmlns="">This namespace contains classes used to create new tagger providers for third-party content types so that they can make use of the spell checker.</NamespaceSummaryItem>
</NamespaceSummaries>
<ComponentConfigurations>
</ComponentConfigurations>
<HelpFileVersion>2020.8.24.0</HelpFileVersion>
<HelpFileVersion>2021.1.23.0</HelpFileVersion>
<SaveComponentCacheCapacity>0</SaveComponentCacheCapacity>
<SourceCodeBasePath>..\Source\</SourceCodeBasePath>
<WarnOnMissingSourceContext>True</WarnOnMissingSourceContext>
Expand Down Expand Up @@ -182,6 +182,7 @@
<None Include="Content\VersionHistory\v2020.4.18.0.aml" />
<None Include="Content\VersionHistory\v2020.6.11.0.aml" />
<None Include="Content\VersionHistory\v2020.8.24.0.aml" />
<None Include="Content\VersionHistory\v2021.1.23.0.aml" />
<None Include="Content\VersionHistory\VersionHistory.aml" />
<None Include="Content\VersionHistory\v2015.8.15.0.aml" />
<None Include="Content\VersionHistory\v2015.9.19.0.aml" />
Expand Down
8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ Copyright Notices
-----------------
The core Visual Studio package code related to the spell checker implementation
was originally written by Noah Richards, Roman Golovin, and Michael Lehenbauer
and is Copyright (c) 2010-2020 Microsoft Corporation, All Rights Reserved.
and is Copyright (c) 2010-2021 Microsoft Corporation, All Rights Reserved.

The NHunspell library is Copyright (c) 2009-2020 Maierhofer Software,
The NHunspell library is Copyright (c) 2009-2021 Maierhofer Software,
All Rights Reserved.

The HTML Agility Pack is Copyright (c) 2006-2020 Simon Mourier, All Rights
The HTML Agility Pack is Copyright (c) 2006-2021 Simon Mourier, All Rights
Reserved.

All other code is Copyright (c) 2013-2020 Eric Woodruff, All Rights Reserved.
All other code is Copyright (c) 2013-2021 Eric Woodruff, All Rights Reserved.

All dictionaries supplied with the package are property of their respective
copyright holders. See the README files in the dictionary folder at the project
Expand Down
11 changes: 5 additions & 6 deletions Source/VSSpellChecker/Configuration/SpellCheckerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// System : Visual Studio Spell Checker Package
// File : SpellCheckerConfiguration.cs
// Author : Eric Woodruff ([email protected])
// Updated : 04/18/2020
// Note : Copyright 2015-2020, Eric Woodruff, All rights reserved
// Updated : 01/13/2021
// Note : Copyright 2015-2021, Eric Woodruff, All rights reserved
//
// This file contains the class used to contain the spell checker's configuration settings
//
Expand Down Expand Up @@ -508,10 +508,9 @@ public void Load(string filename)

try
{
// Nothing to do if the file doesn't exist
if(!File.Exists(filename))
return;

// We go through the motions of loading the configuration file even if it doesn't exist. This
// allows external files such as the default ignored words file to be loaded even if the default
// global configuration file does not exist.
var configuration = new SpellingConfigurationFile(filename, this);

loadedConfigFiles.Add(filename);
Expand Down
16 changes: 8 additions & 8 deletions Source/VSSpellChecker/Configuration/SpellingConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// System : Visual Studio Spell Checker Package
// File : SpellingConfigurationFile.cs
// Author : Eric Woodruff ([email protected])
// Updated : 10/05/2018
// Note : Copyright 2015-2018, Eric Woodruff, All rights reserved
// Updated : 01/13/2021
// Note : Copyright 2015-2021, Eric Woodruff, All rights reserved
// Compiler: Microsoft Visual C#
//
// This file contains the class used to load and save spell checker configuration files
Expand Down Expand Up @@ -41,12 +41,12 @@ public class SpellingConfigurationFile
#region Private data members
//=====================================================================

private Dictionary<string, PropertyInfo> propertyCache;
private readonly Dictionary<string, PropertyInfo> propertyCache;
private readonly PropertyDescriptorCollection configCache, csoCache, cadCache;
private readonly SpellCheckerConfiguration defaultConfig;

private XDocument document;
private XElement root;
private readonly XDocument document;
private readonly XElement root;

#endregion

Expand Down Expand Up @@ -139,7 +139,7 @@ public ConfigurationType ConfigurationType
public SpellingConfigurationFile(string filename, SpellCheckerConfiguration defaultConfig)
{
if(String.IsNullOrWhiteSpace(filename))
throw new ArgumentNullException("filename", "Filename cannot be null or empty");
throw new ArgumentNullException(nameof(filename), "Filename cannot be null or empty");

this.Filename = filename;
this.defaultConfig = defaultConfig;
Expand Down Expand Up @@ -635,7 +635,7 @@ public bool ToBoolean(string propertyName)
!Boolean.TryParse(property.Value, out bool value))
{
object defaultValue = this.DefaultValueFor(propertyName);
return (defaultValue != null) ? (bool)defaultValue : false;
return (defaultValue != null) && (bool)defaultValue;
}

return value;
Expand Down Expand Up @@ -675,7 +675,7 @@ public TEnum ToEnum<TEnum>(string propertyName) where TEnum : struct
!Enum.TryParse<TEnum>(property.Value, true, out TEnum value))
{
object defaultValue = this.DefaultValueFor(propertyName);
value = (defaultValue != null) ? (TEnum)defaultValue : default(TEnum);
value = (defaultValue != null) ? (TEnum)defaultValue : default;
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// System : Visual Studio Spell Checker Package
// File : DictionarySettingsUserControl.xaml.cs
// Author : Eric Woodruff ([email protected])
// Updated : 02/21/2020
// Note : Copyright 2014-2020, Eric Woodruff, All rights reserved
// Updated : 01/13/2021
// Note : Copyright 2014-2021, Eric Woodruff, All rights reserved
//
// This file contains a user control used to edit the spell checker dictionary settings
//
Expand Down Expand Up @@ -889,7 +889,7 @@ private void btnExport_Click(object sender, RoutedEventArgs e)
}
}

Utility.SaveCustomDictionary(dlg.FileName, replaceWords, true, uniqueWords.OrderBy(w => w));
Utility.SaveCustomDictionary(dlg.FileName, replaceWords, true, uniqueWords);
}
catch(Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// System : Visual Studio Spell Checker Package
// File : IgnoredWordsUserControl.xaml.cs
// Author : Eric Woodruff ([email protected])
// Updated : 03/19/2020
// Note : Copyright 2014-2020, Eric Woodruff, All rights reserved
// Updated : 01/13/2021
// Note : Copyright 2014-2021, Eric Woodruff, All rights reserved
//
// This file contains a user control used to edit the ignored words spell checker configuration settings
//
Expand Down Expand Up @@ -342,7 +342,7 @@ private void btnExport_Click(object sender, RoutedEventArgs e)
}
}

Utility.SaveCustomDictionary(dlg.FileName, replaceWords, false, uniqueWords.OrderBy(w => w));
Utility.SaveCustomDictionary(dlg.FileName, replaceWords, false, uniqueWords);
}
catch(Exception ex)
{
Expand Down
51 changes: 42 additions & 9 deletions Source/VSSpellChecker/GlobalDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// System : Visual Studio Spell Checker Package
// File : GlobalDictionary.cs
// Author : Eric Woodruff ([email protected])
// Updated : 02/21/2020
// Note : Copyright 2013-2020, Eric Woodruff, All rights reserved
// Updated : 01/20/2021
// Note : Copyright 2013-2021, Eric Woodruff, All rights reserved
//
// This file contains a class that implements the global dictionary
//
Expand Down Expand Up @@ -179,20 +179,42 @@ public bool AddWordToDictionary(string word)
if(!dictionaryWordsFile.CanWriteToUserWordsFile(dictionaryFile))
return false;

bool multipleWordsAdded = false;

lock(dictionaryWords)
{
var currentDictionary = new HashSet<string>(Utility.LoadUserDictionary(dictionaryWordsFile, false,
false), StringComparer.OrdinalIgnoreCase);

dictionaryWords.Add(word);

// Sort and write all the words to the file. If under source control, this should minimize the
// number of merge conflicts that could result if multiple people added words and they were all
// written to the end of the file.
File.WriteAllLines(dictionaryWordsFile, dictionaryWords.OrderBy(w => w));
// The word may have been added by another instance of Visual Studio. If so, don't save the change.
if(!currentDictionary.Contains(word))
{
int wordCount = dictionaryWords.Count;

// Add words added by other instances of Visual Studio not already in this copy of the
// dictionary so that we don't lose them when the file is saved. All new ones will be
// added as suggestions below.
dictionaryWords.UnionWith(currentDictionary);

multipleWordsAdded = (wordCount != dictionaryWords.Count);

// Sort and write all the words to the file. If under source control, this should minimize the
// number of merge conflicts that could result if multiple people added words and they were all
// written to the end of the file.
File.WriteAllLines(dictionaryWordsFile, dictionaryWords.OrderBy(w => w));
}
}

this.AddSuggestion(word);
if(multipleWordsAdded)
this.AddSuggestions();
else
this.AddSuggestion(word);

// Must pass the original word with mnemonics as it must match the span text
this.NotifySpellingServicesOfChange(originalWord);
// Must pass the original word with mnemonics as it must match the span text. If multiple words
// were added from other instances, pass null to respell all text.
this.NotifySpellingServicesOfChange(multipleWordsAdded ? null : originalWord);

return true;
}
Expand Down Expand Up @@ -446,6 +468,17 @@ public static bool IsReadyForUse(CultureInfo language)
return true;
}

/// <summary>
/// This is used to notify all registered spelling dictionary services of a change in status
/// </summary>
/// <remarks>This is used when turning the interactive spell checking on and off for the session</remarks>
public static void NotifyChangeOfStatus()
{
if(globalDictionaries != null)
foreach(var g in globalDictionaries.Values)
g.NotifySpellingServicesOfChange(null);
}

/// <summary>
/// This is used to load the user dictionary words file
/// </summary>
Expand Down
Binary file modified Source/VSSpellChecker/GlobalSuppressions.cs
Binary file not shown.
Loading

0 comments on commit 1856b88

Please sign in to comment.