wakatime / visualstudio-wakatime

Visual Studio plugin for automatic time tracking and metrics generated from your programming activity.
https://wakatime.com/visual-studio
BSD 3-Clause "New" or "Revised" License
334 stars 63 forks source link

Incorrect language detection for ASPX files #78

Open errosan opened 6 years ago

errosan commented 6 years ago

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 commented 5 years ago

@errosan are you using visual studio?

alanhamlett commented 5 years ago

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 commented 5 years ago

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

errosan commented 5 years ago

@gandarez Yes, Visual Studio. Please reopen.

alanhamlett commented 5 years ago

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 commented 5 years ago

@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 commented 9 months ago

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.