Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/Models/ExternalTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public class ExternalToolCustomization
public List<string> Excludes { get; set; } = new List<string>();
}

public class CustomFileAssociations
{
[JsonPropertyName("associations")] public Dictionary<string, string> Associations { get; set; } = new Dictionary<string, string>();
}

public class ExternalToolsFinder
{
public List<ExternalTool> Tools
Expand Down
47 changes: 40 additions & 7 deletions src/Models/TextMateHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;

using System.Text.Json;
using Avalonia;
using Avalonia.Platform;
using Avalonia.Styling;
Expand Down Expand Up @@ -39,12 +39,45 @@ public static class GrammarUtility
public static string GetScope(string file, RegistryOptions reg)
{
var extension = Path.GetExtension(file);
if (extension == ".h")
extension = ".cpp";
else if (extension is ".resx" or ".plist" or ".manifest" or ".sln" or ".slnx")
extension = ".xml";
else if (extension == ".command")
extension = ".sh";

switch (extension)
{
case ".h":
extension = ".cpp";
break;
case ".resx" or ".plist" or ".manifest" or ".sln" or ".slnx":
extension = ".xml";
break;
case ".command":
extension = ".sh";
break;
default:

if (!string.IsNullOrEmpty(extension))
{
var customFileAssociations = Path.Combine(Native.OS.BasicDirectories.ConfigDir, "custom_file_associations.json");

try
{
if (File.Exists(customFileAssociations))
{
using var stream = File.OpenRead(customFileAssociations);
var fileAssociations = JsonSerializer.Deserialize<CustomFileAssociations>(stream) ?? new CustomFileAssociations();

if (fileAssociations.Associations.TryGetValue(file, out var ext))
{
extension = ext;
}
}
}
catch
{
// Ignore
}
}

break;
}

foreach (var grammar in s_extraGrammars)
{
Expand Down