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

Incorrect language detection for ASPX files #78

Open
errosan opened this issue Aug 13, 2018 · 7 comments
Open

Incorrect language detection for ASPX files #78

errosan opened this issue Aug 13, 2018 · 7 comments

Comments

@errosan
Copy link

errosan commented Aug 13, 2018

The plugin is reporting ASPX as VB.NET language. ASPX pages have a language declaration at the beginning of the file, it would be better to use the language specified since aspx pages can be either language, vb or c#.

<%@ Page Title="" Language="C#" %>

@gandarez gandarez self-assigned this Jul 4, 2019
@gandarez
Copy link
Member

gandarez commented Jul 4, 2019

@errosan are you using visual studio?

@alanhamlett
Copy link
Member

Looks like Pygments (the library we use for language detection) already supports detecting language attribute from Page tags:

https://bitbucket.org/birkenfeld/pygments-main/src/e63f7b68898445836091b51cfa81bf0613fb05eb/pygments/lexers/dotnet.py#lines-499

We might be not correctly using this information from pygments, or truncating the language name since we only support a single language while Pygments supports nested languages:
https://bitbucket.org/birkenfeld/pygments-main/src/e63f7b68898445836091b51cfa81bf0613fb05eb/pygments/lexers/dotnet.py#lines-504

Here's where we use Pygments to detect the language via lexer.name:
https://github.com/wakatime/wakatime/blob/ddc7cb3ed4626aa89a3bab2015cd2bb0b5c8754d/wakatime/stats.py#L70

@gandarez
Copy link
Member

Closing due to the lack of response, feel free to reopen @errosan.

@errosan
Copy link
Author

errosan commented Aug 15, 2019

@gandarez Yes, Visual Studio. Please reopen.

@alanhamlett alanhamlett reopened this Aug 16, 2019
@alanhamlett
Copy link
Member

alanhamlett commented Aug 16, 2019

Here's a screenshot of our server-side language rule overrides related to asp and vb:
Screen Shot 2019-08-15 at 9 53 55 PM

That means we're not overwriting the language server-side. Probably what's happening is the VB.NET Lexer is using priority 0.5:
wakatime/packages/pygments/lexers/dotnet.py#L470

While the C# Lexer has a max priority of 0.2:
wakatime/packages/pygments/lexers/dotnet.py#L513

So Pygments prefers VB.NET over C#.

@gandarez
Copy link
Member

gandarez commented Aug 16, 2019

@alanhamlett would be possible to call the api and add an extra parameter to force the language (using the parameter language)? I think the visualstudio extension can read the first line of the file and decide if it's C# or VB.NET.

https://github.com/wakatime/wakatime/blob/master/wakatime/heartbeat.py#L39

@alanhamlett
Copy link
Member

alanhamlett commented Jan 21, 2024

Is this still happening now that we've moved from Pygments to chroma?

We can have the Visual Studio extension pass --language "VB.NET" | "C#" | "ASP.NET" to wakatime-cli if it detects one of those languages with certainty. We should only add --language for those three languages, because it disables language detection in wakatime-cli.

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

3 participants