feat: Add JSP grammar support and improve TextMateHelper file type handling (#1100)

- 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.
This commit is contained in:
Gadfly 2025-03-17 10:12:44 +08:00 committed by GitHub
parent 7caa03a09b
commit 450dadf76c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1218 additions and 10 deletions

View file

@ -21,10 +21,11 @@ namespace SourceGit.Models
{ {
private static readonly ExtraGrammar[] s_extraGrammars = private static readonly ExtraGrammar[] s_extraGrammars =
[ [
new ExtraGrammar("source.toml", ".toml", "toml.json"), new ExtraGrammar("source.toml", [".toml"], "toml.json"),
new ExtraGrammar("source.kotlin", ".kotlin", "kotlin.json"), new ExtraGrammar("source.kotlin", [".kotlin", ".kt", ".kts"], "kotlin.json"),
new ExtraGrammar("source.hx", ".hx", "haxe.json"), new ExtraGrammar("source.hx", [".hx"], "haxe.json"),
new ExtraGrammar("source.hxml", ".hxml", "hxml.json"), new ExtraGrammar("source.hxml", [".hxml"], "hxml.json"),
new ExtraGrammar("text.html.jsp", [".jsp", ".jspf", ".tag"], "jsp.json"),
]; ];
public static string GetScope(string file, RegistryOptions reg) public static string GetScope(string file, RegistryOptions reg)
@ -36,13 +37,14 @@ namespace SourceGit.Models
extension = ".xml"; extension = ".xml";
else if (extension == ".command") else if (extension == ".command")
extension = ".sh"; extension = ".sh";
else if (extension == ".kt" || extension == ".kts")
extension = ".kotlin";
foreach (var grammar in s_extraGrammars) foreach (var grammar in s_extraGrammars)
{ {
if (grammar.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) foreach (var ext in grammar.Extensions)
return grammar.Scope; {
if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase))
return grammar.Scope;
}
} }
return reg.GetScopeByExtension(extension); return reg.GetScopeByExtension(extension);
@ -71,10 +73,10 @@ namespace SourceGit.Models
return reg.GetGrammar(scopeName); return reg.GetGrammar(scopeName);
} }
private record ExtraGrammar(string Scope, string Extension, string File) private record ExtraGrammar(string Scope, List<string> Extensions, string File)
{ {
public readonly string Scope = Scope; public readonly string Scope = Scope;
public readonly string Extension = Extension; public readonly List<string> Extensions = Extensions;
public readonly string File = File; public readonly string File = File;
} }
} }

File diff suppressed because it is too large Load diff