Skip to content

Commit

Permalink
Classifier adjustment
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EWSoftware committed Aug 24, 2020
1 parent 12fd6f2 commit 9bbd3ea
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 19 deletions.
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="04d6f71e-e4c3-41c2-b46e-fd0da1239843" />
</para>
</listItem>

<listItem>
<para>
<link xlink:href="9e9ebccd-3b61-4890-8467-823dacc7af3f" />
Expand Down
27 changes: 27 additions & 0 deletions Docs/Content/VersionHistory/v2020.8.24.0.aml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="04d6f71e-e4c3-41c2-b46e-fd0da1239843" 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>Adjusted the classifier definitions so that "<codeinline>/** */</codeinline>" comments are not
treated like XML documentation comments in script languages such as TypeScript which uses them for markdown
comments.</para>
</listItem>

</list>

</content>
</section>

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

</developerConceptualDocument>
</topic>
7 changes: 6 additions & 1 deletion Docs/ContentLayout.content
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@
<HelpKeyword index="K" term="submitting changes" />
</HelpKeywords>
</Topic>
<Topic id="548dc6d7-6d08-4006-82b3-d5830be96f04" visible="True" isSelected="true" title="Version History">
<Topic id="548dc6d7-6d08-4006-82b3-d5830be96f04" visible="True" isExpanded="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">
<HelpKeywords>
<HelpKeyword index="K" term="versions, 2020.8.24.0" />
</HelpKeywords>
</Topic>
<Topic id="9e9ebccd-3b61-4890-8467-823dacc7af3f" visible="True" title="Version 2020.6.11.0">
<HelpKeywords>
<HelpKeyword index="K" term="versions, 2020.6.11.0" />
Expand Down
3 changes: 2 additions & 1 deletion Docs/VSSpellCheckerDocs.shfbproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</NamespaceSummaries>
<ComponentConfigurations>
</ComponentConfigurations>
<HelpFileVersion>2020.6.11.0</HelpFileVersion>
<HelpFileVersion>2020.8.24.0</HelpFileVersion>
<SaveComponentCacheCapacity>0</SaveComponentCacheCapacity>
<SourceCodeBasePath>..\Source\</SourceCodeBasePath>
<WarnOnMissingSourceContext>True</WarnOnMissingSourceContext>
Expand Down Expand Up @@ -181,6 +181,7 @@
<None Include="Content\VersionHistory\v2020.3.28.0.aml" />
<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\VersionHistory.aml" />
<None Include="Content\VersionHistory\v2015.8.15.0.aml" />
<None Include="Content\VersionHistory\v2015.9.19.0.aml" />
Expand Down
6 changes: 3 additions & 3 deletions Source/VSSpellChecker/Classifications.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<Match Expression="(?&lt;=^\s*#endregion).*?[\r\n]{1,2}" Options="Multiline" Classification="RegionDirective" />
</Classifier>

<!-- Like CStyle but for JavaScript/TypeScript which allow single quotes for strings -->
<Classifier Id="CStyleScript" Type="CodeClassifier" XmlDocCommentDelimiter="///" QuadSlashDelimiter="////"
OldStyleDocCommentDelimiter="/**">
<!-- Like CStyle but for JavaScript/TypeScript which allow single quotes for strings. The old style doc
comments delimiter is omitted as TypeScript uses it for markdown comments. -->
<Classifier Id="CStyleScript" Type="CodeClassifier" XmlDocCommentDelimiter="///" QuadSlashDelimiter="////">
<Match Expression="\s*/\*.*?\*/" Options="Singleline" Classification="DelimitedComments" />
<Match Expression="\s*//.*?([\r\n]{1,2}|$)" Classification="SingleLineComment" />
<Match Expression="(&quot;&quot;)|((\$|@)?(@|R|\$)&quot;(.|[\r\n])*?&quot;|\$&quot;(.|[\r\n])*?&quot;|&quot;(.|\\&quot;|\\\r\n)*?((\\\\)+&quot;|[^\\]{1}&quot;))"
Expand Down
27 changes: 24 additions & 3 deletions Source/VSSpellChecker/ProjectSpellCheck/ClassifierFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// System : Visual Studio Spell Checker Package
// File : ClassifierFactory.cs
// Author : Eric Woodruff ([email protected])
// Updated : 09/17/2018
// Note : Copyright 2015-2018, Eric Woodruff, All rights reserved
// Compiler: Microsoft Visual C#
// Updated : 07/24/2020
// Note : Copyright 2015-2020, Eric Woodruff, All rights reserved
//
// This file contains a class used to generate classifiers for files that need to be spell checked
//
Expand Down Expand Up @@ -126,6 +125,7 @@ public static string ClassifierIdFor(string filename)
/// This is used to determine if the file contains C-style code based on its extension
/// </summary>
/// <param name="filename">The filename to check</param>
/// <returns>True if it does, false if not</returns>
public static bool IsCStyleCode(string filename)
{
if(filename == null)
Expand All @@ -142,10 +142,31 @@ public static bool IsCStyleCode(string filename)
return (extensionMap.TryGetValue(extension, out string id) && id.StartsWith("CStyle", StringComparison.Ordinal));
}

/// <summary>
/// This is used to see if a C-style language support old style XML documentation comments (/** ... */)
/// </summary>
/// <param name="filename">The filename to check</param>
/// <returns>True if it does, false if not</returns>
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"));
}

/// <summary>
/// This is used to determine if apostrophes are escaped such as in SQL literal strings
/// </summary>
/// <param name="filename">The filename to check</param>
/// <returns>True if they are, false if not</returns>
public static bool EscapesApostrophes(string filename)
{
if(filename == null)
Expand Down
19 changes: 13 additions & 6 deletions Source/VSSpellChecker/Tagging/CSharp/CSharpCommentTextTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -64,6 +63,13 @@ internal class CSharpCommentTextTagger : ITagger<NaturalTextTag>, IDisposable
/// <value>The default is false to include XML documentation comments</value>
public bool IgnoreXmlDocComments { get; set; }

/// <summary>
/// This is used to get or set whether or not the file might contain old style XML documentation comments
/// (/** ... */).
/// </summary>
/// <value>The default is true to assume they may be present</value>
public bool SupportsOldStyleXmlDocComments { get; set; }

/// <summary>
/// This is used to get or set whether or not to ignore delimited comments (<c>/* ... */</c>)
/// </summary>
Expand Down Expand Up @@ -126,7 +132,8 @@ internal class CSharpCommentTextTagger : ITagger<NaturalTextTag>, IDisposable
public CSharpCommentTextTagger(ITextBuffer buffer)
{
this.buffer = buffer;
this.IgnoredXmlElements = this.SpellCheckedAttributes = new string[0];
this.IgnoredXmlElements = this.SpellCheckedAttributes = Array.Empty<string>();
this.SupportsOldStyleXmlDocComments = true;

// Populate our cache initially
ITextSnapshot snapshot = this.buffer.CurrentSnapshot;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion Source/VSSpellChecker/Tagging/CommentTextTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ public ITagger<T> CreateTagger<T>(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,
Expand Down
2 changes: 1 addition & 1 deletion Source/VSSpellChecker/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="43EA967E-0DE2-4136-8E52-C6DCFB5C2748" Version="2020.6.11.0" Language="en-US" Publisher="EWSoftware" />
<Identity Id="43EA967E-0DE2-4136-8E52-C6DCFB5C2748" Version="2020.8.24.0" Language="en-US" Publisher="EWSoftware" />
<DisplayName>Visual Studio Spell Checker (VS2017 and Later)</DisplayName>
<Description xml:space="preserve">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.</Description>
<MoreInfo>https://ewsoftware.github.io/VSSpellChecker</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// System : Visual Studio Spell Checker
// File : AssemblyInfoShared.cs
// Author : Eric Woodruff ([email protected])
// Updated : 06/11/2020
// Updated : 08/24/2020
// Note : Copyright 2013-2020, Eric Woodruff, All rights reserved
//
// Visual Studio spell checker common assembly attributes
Expand Down Expand Up @@ -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" +
Expand Down

0 comments on commit 9bbd3ea

Please sign in to comment.