Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Models/TextMateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public static class GrammarUtility
{
private static readonly ExtraGrammar[] s_extraGrammars =
[
new ExtraGrammar("source.toml", ".toml", "toml.json"),
new ExtraGrammar("source.kotlin", ".kotlin", "kotlin.json"),
new ExtraGrammar("source.hx", ".hx", "haxe.json"),
new ExtraGrammar("source.hxml", ".hxml", "hxml.json"),
new ExtraGrammar("source.toml", [".toml"], "toml.json"),
new ExtraGrammar("source.kotlin", [".kotlin", ".kt", ".kts"], "kotlin.json"),
new ExtraGrammar("source.hx", [".hx"], "haxe.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)
Expand All @@ -36,13 +37,14 @@ public static string GetScope(string file, RegistryOptions reg)
extension = ".xml";
else if (extension == ".command")
extension = ".sh";
else if (extension == ".kt" || extension == ".kts")
extension = ".kotlin";

foreach (var grammar in s_extraGrammars)
{
if (grammar.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase))
return grammar.Scope;
foreach (var ext in grammar.Extensions)
{
if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase))
return grammar.Scope;
}
}

return reg.GetScopeByExtension(extension);
Expand Down Expand Up @@ -71,10 +73,10 @@ public static IRawGrammar GetGrammar(string scopeName, RegistryOptions reg)
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 Extension = Extension;
public readonly List<string> Extensions = Extensions;
public readonly string File = File;
}
}
Expand Down
Loading