Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monaco languages file includes multiple IDs with the same extension #35916

Open
daverayment opened this issue Nov 13, 2024 · 0 comments
Open
Labels
Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams

Comments

@daverayment
Copy link
Contributor

daverayment commented Nov 13, 2024

Microsoft PowerToys version

0.86

Installation method

Dev build in Visual Studio

Running as admin

No

Area(s) with issue?

File Explorer: Preview Pane, Peek

Steps to reproduce

Please note: this is a minor issue, and I'm just reporting it to raise awareness and to include repro code so it may be tracked in the future.

The monaco_languages.json file includes a mapping of file extensions to language IDs. This allows for syntax highlighting on a per-language basis.

There exist 3 cases where the same file extension is present for multiple languages. This may result in incorrect syntax highlighting in one of those cases.

The code to repro the issue is as follows:

using System.Text.Json;

string json = File.ReadAllText("monaco_languages.json");

using var jsonDoc = JsonDocument.Parse(json);
var list = jsonDoc.RootElement.GetProperty("list");

foreach (var entry in list.EnumerateArray()
    .Where(item => item.TryGetProperty("id", out var _) && item.TryGetProperty("extensions", out var _))
    .SelectMany(item => item.GetProperty("extensions").EnumerateArray()
        .Select(ext => new
        {
            Extension = ext.GetString(),
            Id = item.GetProperty("id").GetString()
        })
    ).GroupBy(pair => pair.Extension)
    .Where(group => group.Count() > 1)
    .Select(group => new
    {
        Extension = group.Key,
        Ids = group.Select(x => x.Id)
    }))
{
    Console.WriteLine($"Extension '{entry.Extension}' used by IDs {string.Join(", ", entry.Ids)}");
}

(Setup a new Console application with this code as Program.cs and also copy in the current monaco_languages.json file, setting that file to be copied to the output directory.)

The results are:

Extension '.gitconfig' used by IDs ini, iniExt
Extension '.pp' used by IDs pascal, ruby
Extension '.csproj' used by IDs xml, xmlExt

The lookup for Monaco language matching in PowerToys will always pick the first match, so a file with a .pp extension will always be recognised as Pascal, even if it is a Puppet manifest file. (I assume the other 2 cases are OK, as the language IDs appear synonymous.)

I'm unsure what the resolution for this is without doing file introspection. That's probably unreasonable, especially for a single case such as this.

If it was decided to favour Puppet files over Pascal, the entry for Ruby should be moved before Pascal's in the file.

✔️ Expected Behavior

Files for Pascal and Puppet manifest files should be recognised as distinct, and highlighted differently by Monaco.

❌ Actual Behavior

As the files share the same extension, they cannot be distinguished from one another, and will always be rendered as Pascal.

Other Software

No response

@daverayment daverayment added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams
Projects
None yet
Development

No branches or pull requests

1 participant