From 9bbd3ead0c7e47da9f4a8b8c4b14fabbaa104968 Mon Sep 17 00:00:00 2001 From: EWSoftware Date: Mon, 24 Aug 2020 16:35:24 -0700 Subject: [PATCH] Classifier adjustment Adjusted the classifier definitions so that "/** */" comments are not treated like XML documentation comments in script languages such as TypeScript which uses them for markdown comments. Fixes #215. --- .../Content/VersionHistory/VersionHistory.aml | 6 +++++ Docs/Content/VersionHistory/v2020.8.24.0.aml | 27 +++++++++++++++++++ Docs/ContentLayout.content | 7 ++++- Docs/VSSpellCheckerDocs.shfbproj | 3 ++- Source/VSSpellChecker/Classifications.config | 6 ++--- .../ProjectSpellCheck/ClassifierFactory.cs | 27 ++++++++++++++++--- .../Tagging/CSharp/CSharpCommentTextTagger.cs | 19 ++++++++----- .../Tagging/CommentTextTagger.cs | 5 +++- .../source.extension.vsixmanifest | 2 +- .../Properties/AssemblyInfoShared.cs | 6 ++--- 10 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 Docs/Content/VersionHistory/v2020.8.24.0.aml diff --git a/Docs/Content/VersionHistory/VersionHistory.aml b/Docs/Content/VersionHistory/VersionHistory.aml index 587b402..1e06d89 100644 --- a/Docs/Content/VersionHistory/VersionHistory.aml +++ b/Docs/Content/VersionHistory/VersionHistory.aml @@ -9,6 +9,12 @@ project. Select a version below to see a description of its changes.
+ + + + + + diff --git a/Docs/Content/VersionHistory/v2020.8.24.0.aml b/Docs/Content/VersionHistory/v2020.8.24.0.aml new file mode 100644 index 0000000..1668b88 --- /dev/null +++ b/Docs/Content/VersionHistory/v2020.8.24.0.aml @@ -0,0 +1,27 @@ + + + + + Changes in this release: + + +
+ + + + Adjusted the classifier definitions so that "/** */" comments are not +treated like XML documentation comments in script languages such as TypeScript which uses them for markdown +comments. + + + + + +
+ + + + + +
+
diff --git a/Docs/ContentLayout.content b/Docs/ContentLayout.content index c0e1312..acc408a 100644 --- a/Docs/ContentLayout.content +++ b/Docs/ContentLayout.content @@ -149,10 +149,15 @@ - + + + + + + diff --git a/Docs/VSSpellCheckerDocs.shfbproj b/Docs/VSSpellCheckerDocs.shfbproj index f481781..2597f3c 100644 --- a/Docs/VSSpellCheckerDocs.shfbproj +++ b/Docs/VSSpellCheckerDocs.shfbproj @@ -49,7 +49,7 @@ - 2020.6.11.0 + 2020.8.24.0 0 ..\Source\ True @@ -181,6 +181,7 @@ + diff --git a/Source/VSSpellChecker/Classifications.config b/Source/VSSpellChecker/Classifications.config index 2696813..60556ed 100644 --- a/Source/VSSpellChecker/Classifications.config +++ b/Source/VSSpellChecker/Classifications.config @@ -28,9 +28,9 @@ - - + + /// The filename to check + /// True if it does, false if not public static bool IsCStyleCode(string filename) { if(filename == null) @@ -142,10 +142,31 @@ public static bool IsCStyleCode(string filename) return (extensionMap.TryGetValue(extension, out string id) && id.StartsWith("CStyle", StringComparison.Ordinal)); } + /// + /// This is used to see if a C-style language support old style XML documentation comments (/** ... */) + /// + /// The filename to check + /// True if it does, false if not + public static bool SupportsOldStyleXmlDocComments(string filename) + { + string extension = Path.GetExtension(filename); + + if(extensionMap == null) + LoadClassifierConfiguration(); + + if(!String.IsNullOrWhiteSpace(extension)) + extension = extension.Substring(1); + + return extensionMap.TryGetValue(extension, out string id) && id != "None" && + definitions.TryGetValue(id, out ClassifierDefinition definition) && + !String.IsNullOrWhiteSpace((string)definition.Configuration.Attribute("OldStyleDocCommentDelimiter")); + } + /// /// This is used to determine if apostrophes are escaped such as in SQL literal strings /// /// The filename to check + /// True if they are, false if not public static bool EscapesApostrophes(string filename) { if(filename == null) diff --git a/Source/VSSpellChecker/Tagging/CSharp/CSharpCommentTextTagger.cs b/Source/VSSpellChecker/Tagging/CSharp/CSharpCommentTextTagger.cs index f5816ff..311bad8 100644 --- a/Source/VSSpellChecker/Tagging/CSharp/CSharpCommentTextTagger.cs +++ b/Source/VSSpellChecker/Tagging/CSharp/CSharpCommentTextTagger.cs @@ -2,10 +2,9 @@ // System : Visual Studio Spell Checker Package // File : CSharpCommentTextTagger.cs // Authors : Noah Richards, Roman Golovin, Michael Lehenbauer, Eric Woodruff -// Updated : 07/08/2019 -// Note : Copyright 2010-2019, Microsoft Corporation, All rights reserved -// Portions Copyright 2013-2019, Eric Woodruff, All rights reserved -// Compiler: Microsoft Visual C# +// Updated : 07/24/2020 +// Note : Copyright 2010-2020, Microsoft Corporation, All rights reserved +// Portions Copyright 2013-2020, Eric Woodruff, All rights reserved // // This file contains a class used to provide tags for C# code // @@ -64,6 +63,13 @@ internal class CSharpCommentTextTagger : ITagger, IDisposable /// The default is false to include XML documentation comments public bool IgnoreXmlDocComments { get; set; } + /// + /// This is used to get or set whether or not the file might contain old style XML documentation comments + /// (/** ... */). + /// + /// The default is true to assume they may be present + public bool SupportsOldStyleXmlDocComments { get; set; } + /// /// This is used to get or set whether or not to ignore delimited comments (/* ... */) /// @@ -126,7 +132,8 @@ internal class CSharpCommentTextTagger : ITagger, IDisposable public CSharpCommentTextTagger(ITextBuffer buffer) { this.buffer = buffer; - this.IgnoredXmlElements = this.SpellCheckedAttributes = new string[0]; + this.IgnoredXmlElements = this.SpellCheckedAttributes = Array.Empty(); + this.SupportsOldStyleXmlDocComments = true; // Populate our cache initially ITextSnapshot snapshot = this.buffer.CurrentSnapshot; @@ -364,7 +371,7 @@ private void ScanDefault(LineProgress p) p.Advance(2); // "/***" is just a regular multi-line comment, not a doc comment - if(p.EndOfLine || p.Char() != '*' || p.NextChar() == '*') + if(!this.SupportsOldStyleXmlDocComments || p.EndOfLine || p.Char() != '*' || p.NextChar() == '*') { p.State = State.MultiLineComment; ScanMultiLineComment(p); diff --git a/Source/VSSpellChecker/Tagging/CommentTextTagger.cs b/Source/VSSpellChecker/Tagging/CommentTextTagger.cs index 401a731..7ceccbf 100644 --- a/Source/VSSpellChecker/Tagging/CommentTextTagger.cs +++ b/Source/VSSpellChecker/Tagging/CommentTextTagger.cs @@ -100,14 +100,17 @@ public ITagger CreateTagger(ITextBuffer buffer) where T : ITag // 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(buffer.GetFilename()))) + 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, diff --git a/Source/VSSpellChecker/source.extension.vsixmanifest b/Source/VSSpellChecker/source.extension.vsixmanifest index e19b9a3..c3ef953 100644 --- a/Source/VSSpellChecker/source.extension.vsixmanifest +++ b/Source/VSSpellChecker/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + Visual Studio Spell Checker (VS2017 and Later) An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with a tool window. It can also spell check an entire solution, project, or selected items. Options are available to define multiple languages to spell check against, define ignored words, control how elements and attributes in XML and MAML files are spell checked, and much more. https://ewsoftware.github.io/VSSpellChecker diff --git a/Source/VSSpellCheckerDefinitions/Properties/AssemblyInfoShared.cs b/Source/VSSpellCheckerDefinitions/Properties/AssemblyInfoShared.cs index 2995406..f87f72b 100644 --- a/Source/VSSpellCheckerDefinitions/Properties/AssemblyInfoShared.cs +++ b/Source/VSSpellCheckerDefinitions/Properties/AssemblyInfoShared.cs @@ -2,7 +2,7 @@ // System : Visual Studio Spell Checker // File : AssemblyInfoShared.cs // Author : Eric Woodruff (Eric@EWoodruff.us) -// Updated : 06/11/2020 +// Updated : 08/24/2020 // Note : Copyright 2013-2020, Eric Woodruff, All rights reserved // // Visual Studio spell checker common assembly attributes @@ -82,13 +82,13 @@ internal static partial class AssemblyInfo // // This is used to set the assembly file version. This will change with each new release. MSIs only // support a Major value between 0 and 255 so we drop the century from the year on this one. - public const string FileVersion = "20.6.11.0"; + public const string FileVersion = "20.8.24.0"; // Common product version // // This may contain additional text to indicate Alpha or Beta states. The version number will always match // the file version above but includes the century on the year. - public const string ProductVersion = "2020.6.11.0"; + public const string ProductVersion = "2020.8.24.0"; // Assembly copyright information public const string Copyright = "Copyright \xA9 2013-2020, Eric Woodruff, All Rights Reserved.\r\n" +