Skip to content

Commit 6f6695c

Browse files
committed
feat: Add JSP grammar support and improve TextMateHelper file type handling
- Extend grammar support by allowing multiple file extensions per grammar and adding JSP file type handling. - Add a new JSON grammar file for JavaServer Pages (JSP) syntax highlighting.
1 parent 7caa03a commit 6f6695c

File tree

2 files changed

+1218
-10
lines changed

2 files changed

+1218
-10
lines changed

src/Models/TextMateHelper.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ public static class GrammarUtility
2121
{
2222
private static readonly ExtraGrammar[] s_extraGrammars =
2323
[
24-
new ExtraGrammar("source.toml", ".toml", "toml.json"),
25-
new ExtraGrammar("source.kotlin", ".kotlin", "kotlin.json"),
26-
new ExtraGrammar("source.hx", ".hx", "haxe.json"),
27-
new ExtraGrammar("source.hxml", ".hxml", "hxml.json"),
24+
new ExtraGrammar("source.toml", [".toml"], "toml.json"),
25+
new ExtraGrammar("source.kotlin", [".kotlin", ".kt", ".kts"], "kotlin.json"),
26+
new ExtraGrammar("source.hx", [".hx"], "haxe.json"),
27+
new ExtraGrammar("source.hxml", [".hxml"], "hxml.json"),
28+
new ExtraGrammar("text.html.jsp", [".jsp", ".jspf", ".tag"], "jsp.json"),
2829
];
2930

3031
public static string GetScope(string file, RegistryOptions reg)
@@ -36,13 +37,14 @@ public static string GetScope(string file, RegistryOptions reg)
3637
extension = ".xml";
3738
else if (extension == ".command")
3839
extension = ".sh";
39-
else if (extension == ".kt" || extension == ".kts")
40-
extension = ".kotlin";
4140

4241
foreach (var grammar in s_extraGrammars)
4342
{
44-
if (grammar.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase))
45-
return grammar.Scope;
43+
foreach (var ext in grammar.Extensions)
44+
{
45+
if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase))
46+
return grammar.Scope;
47+
}
4648
}
4749

4850
return reg.GetScopeByExtension(extension);
@@ -71,10 +73,10 @@ public static IRawGrammar GetGrammar(string scopeName, RegistryOptions reg)
7173
return reg.GetGrammar(scopeName);
7274
}
7375

74-
private record ExtraGrammar(string Scope, string Extension, string File)
76+
private record ExtraGrammar(string Scope, List<string> Extensions, string File)
7577
{
7678
public readonly string Scope = Scope;
77-
public readonly string Extension = Extension;
79+
public readonly List<string> Extensions = Extensions;
7880
public readonly string File = File;
7981
}
8082
}

0 commit comments

Comments
 (0)