Skip to content

Commit

Permalink
! Improve comment tagger to handle more situations
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Jun 10, 2024
1 parent 299e249 commit 6b557e0
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Codist/Taggers/CommentTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ static Dictionary<string, CodeType> InitCodeTypeExtensions() {
{ "h", CodeType.C },
{ "cxx", CodeType.C },
{ "css", CodeType.Css },
{ "less", CodeType.Common },
{ "less", CodeType.AlternativeC },
{ "scss", CodeType.AlternativeC },
{ "json", CodeType.Common },
{ "cshtml", CodeType.CSharp },
{ "cshtml", CodeType.AlternativeC },
{ "razor", CodeType.AlternativeC },
{ "go", CodeType.Go },
{ "html", CodeType.Markup },
{ "xhtml", CodeType.Markup },
Expand Down Expand Up @@ -119,6 +121,8 @@ public static CommentTagger Create(IClassificationTypeRegistryService registry,
case CodeType.BashShell:
case CodeType.Common:
return new CommonCommentTagger(registry, textView, textBuffer);
case CodeType.AlternativeC:
return new AlternativeCCommentTagger(registry, textView, textBuffer);
}
return null;
}
Expand Down Expand Up @@ -316,9 +320,10 @@ static CodeType GetCodeType(ITextBuffer textBuffer) {
: t.IsOfType("TypeScript") || t.IsOfType("JavaScript") ? CodeType.Js
: t.IsOfType("code++.MagicPython") ? CodeType.Python
: t.IsOfType("html") || t.IsOfType("htmlx") || t.IsOfType("XAML") || t.IsOfType("XML") || t.IsOfType(Constants.CodeTypes.HtmlxProjection) ? CodeType.Markup
: t.IsOfType("Razor") ? CodeType.Common
: t.IsOfType("Razor") ? CodeType.AlternativeC
: t.IsOfType("code++.css") ? CodeType.Css
: t.IsOfType("code++.LESS") ? CodeType.Common
: t.IsOfType("css.extensions") ? CodeType.AlternativeC
: t.IsOfType("code++.JSON (Javascript Next)") ? CodeType.Common
: t.IsOfType("code++.Shell Script (Bash)") || t.IsOfType("InBoxPowerShell") ? CodeType.BashShell
: t.IsOfType("code++.Batch File") ? CodeType.Batch
Expand Down Expand Up @@ -375,7 +380,7 @@ public void Dispose() {

enum CodeType
{
None, Common, CSharp, Markup, C, Css, Go, Rust, Js, Sql, Python, Batch, BashShell
None, Common, CSharp, Markup, C, AlternativeC, Css, Go, Rust, Js, Sql, Python, Batch, BashShell
}

sealed class CommonCommentTagger : CommentTagger
Expand Down Expand Up @@ -443,6 +448,20 @@ protected override int GetCommentEndIndex(SnapshotSpan content) {
}
}

sealed class AlternativeCCommentTagger : CommentTagger
{
public AlternativeCCommentTagger(IClassificationTypeRegistryService registry, ITextView textView, ITextBuffer buffer) : base(registry, textView, buffer) {
}

protected override int GetCommentStartIndex(SnapshotSpan content) {
return content.Length > 2 && content.CharAt(1) == '/' ? 2
: SlashStarCommentTagger.GetStartIndexOfMultilineSlashStartComment(content, 0);
}
protected override int GetCommentEndIndex(SnapshotSpan content) {
return content.CharAt(1) == '*' ? content.Length - 2 : content.Length;
}
}

sealed class CSharpCommentTagger : CommentTagger
{
readonly ClassificationTag _PreprocessorKeywordTag;
Expand Down

0 comments on commit 6b557e0

Please sign in to comment.