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

Request: Add XML Heuristic for *proj$ File Pattern #7090

Closed
kasperk81 opened this issue Oct 14, 2024 · 9 comments
Closed

Request: Add XML Heuristic for *proj$ File Pattern #7090

kasperk81 opened this issue Oct 14, 2024 · 9 comments

Comments

@kasperk81
Copy link

query: https://github.com/search?q=path:*.*proj+language:xml&type=code

Microsoft has used XML as the format for project files for decades, with many project files having the proj suffix (e.g., .csproj, .vbproj, .fsproj, .pyproj, .jsproj, .sfproj and couple of dozen others). These files follow a consistent XML structure, but listing every project file extension individually can be cumbersome.

Suggestion:
To streamline the classification and ensure proper syntax highlighting for these files, it would make sense to add a heuristic rule to detect and classify files ending with proj as XML. Specifically, applying an XML heuristic to files that match the regex pattern ^*.*proj$ would allow these files to be recognized and highlighted as XML automatically, without the need to list each extension separately.

This improvement would cover a wide variety of project file extensions and enhance the developer experience on GitHub.

@lildude
Copy link
Member

lildude commented Oct 14, 2024

This is not necessary. All standard XML files are already correctly detected as such, unless there is a specific language entry for them thanks to the XML strategy:

/<?xml version=/.match(header) ? [Language["XML"]] : []

The strategies are applied in this order:

linguist/lib/linguist.rb

Lines 62 to 71 in f164d13

STRATEGIES = [
Linguist::Strategy::Modeline,
Linguist::Strategy::Filename,
Linguist::Shebang,
Linguist::Strategy::Extension,
Linguist::Strategy::XML,
Linguist::Strategy::Manpage,
Linguist::Heuristics,
Linguist::Classifier
]

You can tell this is already working as expected as all of the files in the seach results are already identified as XML (hence you can use the language:xml qualifier) and all have syntax highlighting.

This raises the question: why do you think we need this when it's already the case? Where are you seeing this not taking effect?

@kasperk81
Copy link
Author

Good point. The issue is that these proj files don’t always include the <?xml> preamble, which is why they aren't automatically recognized as XML. This makes it necessary to explicitly capture the extensions in Linguist's YAML configuration.

@lildude
Copy link
Member

lildude commented Oct 14, 2024

Oh wait, I think I understand what you're getting at.

No. We'd prefer to add support for extensions on a one-by-one basis as we require usage levels to be met before support can be added.

@kasperk81
Copy link
Author

Do you know how is fsproj or csproj getting recognized? e.g. https://github.com/blowdart/AspNetAuthenticationWorkshop/blob/fbe24ffd430bf38855e10e7e9344083e038cc269/src/Step6/Step_6_Adding_Mvc.csproj doesn't have the preamble and with ```csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

@kasperk81
Copy link
Author

Reason why I'm asking is file starting with <Solution is not recognized (tests are failing in #7084)

@lildude
Copy link
Member

lildude commented Oct 14, 2024

Yup, they're explicitly listed under XML...

- ".csproj"

- ".fsproj"

@kasperk81
Copy link
Author

Yes, it didn't recognized slnx that way though.

@lildude
Copy link
Member

lildude commented Oct 14, 2024

Explaination: #7084 (comment)

@kasperk81
Copy link
Author

Thanks. Lets close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants