Skip to content

Commit

Permalink
Merge pull request #938 from wakatime/feature/init-lexers
Browse files Browse the repository at this point in the history
Make lexers auto-register themselves
  • Loading branch information
gandarez authored Sep 25, 2023
2 parents c698baa + 7058206 commit bb856ef
Show file tree
Hide file tree
Showing 384 changed files with 4,703 additions and 5,154 deletions.
6 changes: 0 additions & 6 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/wakatime/wakatime-cli/pkg/exitcode"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/ini"
"github.com/wakatime/wakatime-cli/pkg/lexer"
"github.com/wakatime/wakatime-cli/pkg/log"
"github.com/wakatime/wakatime-cli/pkg/offline"
"github.com/wakatime/wakatime-cli/pkg/vipertools"
Expand Down Expand Up @@ -69,11 +68,6 @@ func Run(cmd *cobra.Command, v *viper.Viper) {
log.Fatalf("failed to setup logging: %s", err)
}

// register all custom lexers
if err := lexer.RegisterAll(); err != nil {
log.Fatalf("failed to register custom lexers: %s", err)
}

if v.GetBool("user-agent") {
log.Debugln("command: user-agent")

Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358
github.com/alecthomas/chroma/v2 v2.8.0
github.com/alecthomas/chroma/v2 v2.9.1
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
github.com/dlclark/regexp2 v1.10.0
github.com/gandarez/go-olson-timezone v0.1.0
Expand All @@ -21,9 +21,9 @@ require (
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
go.etcd.io/bbolt v1.3.7
golang.org/x/crypto v0.12.0
golang.org/x/net v0.14.0
golang.org/x/text v0.12.0
golang.org/x/crypto v0.13.0
golang.org/x/net v0.15.0
golang.org/x/text v0.13.0
gopkg.in/ini.v1 v1.67.0
)

Expand All @@ -47,17 +47,17 @@ require (
github.com/kr/fs v0.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/yookoala/realpath v1.0.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/alecthomas/chroma/v2 => github.com/gandarez/chroma/v2 v2.8.0-wakatime.1
replace github.com/alecthomas/chroma/v2 => github.com/gandarez/chroma/v2 v2.9.1-wakatime.1

replace github.com/matishsiao/goInfo => github.com/wakatime/goInfo v0.1.0-wakatime.8
36 changes: 18 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0X
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/gandarez/chroma/v2 v2.8.0-wakatime.1 h1:CHVpXUWoYho4HuH0Iu9sL7b5jG93oUrmWPw5Qb5fb2s=
github.com/gandarez/chroma/v2 v2.8.0-wakatime.1/go.mod h1:yrkMI9807G1ROx13fhe1v6PN2DDeaR73L3d+1nmYQtw=
github.com/gandarez/chroma/v2 v2.9.1-wakatime.1 h1:czvEuO+JRT4y2HTTh0REP0p0ebfleH6eY70UI0WF4OQ=
github.com/gandarez/chroma/v2 v2.9.1-wakatime.1/go.mod h1:4TQu7gdfuPjSh76j78ietmqh9LiurGF0EpseFXdKMBw=
github.com/gandarez/go-olson-timezone v0.1.0 h1:cDRlHKQE0uC3mJNZyKoQIpAuvQtV8KXwIVj8bDEEyuo=
github.com/gandarez/go-olson-timezone v0.1.0/go.mod h1:+yV/cYNjgs2JqdGShznAD4R13r8lKMGR2XlWAJqa5Yo=
github.com/gandarez/go-realpath v1.0.0 h1:fhQBRDshH/MZNmDLWM9vbBameK2fxyLr+ctqkRwbHEU=
Expand Down Expand Up @@ -224,8 +224,8 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pkg/sftp v1.13.6 h1:JFZT4XbOU7l77xGSpOdW+pwIMqP044IyjXX6FGyEKFo=
Expand All @@ -243,8 +243,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/slongfield/pyfmt v0.0.0-20220222012616-ea85ff4c361f h1:Z2cODYsUxQPofhpYRMQVwWz4yUVpHF+vPi+eUdruUYI=
github.com/slongfield/pyfmt v0.0.0-20220222012616-ea85ff4c361f/go.mod h1:JqzWyvTuI2X4+9wOHmKSQCYxybB/8j6Ko43qVmXDuZg=
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY=
github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
Expand All @@ -266,8 +266,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/wakatime/goInfo v0.1.0-wakatime.8 h1:MgyeRnCkynEmUxLKXnYUAP5Dd+vhKxhqg6Nx1PdAZy4=
github.com/wakatime/goInfo v0.1.0-wakatime.8/go.mod h1:aEt7p9Rvh67BYApmZwNDPpgircTO2kgdmDUoF/1QmwA=
github.com/yookoala/realpath v1.0.0 h1:7OA9pj4FZd+oZDsyvXWQvjn5oBdcHRTV44PpdMSuImQ=
Expand Down Expand Up @@ -296,8 +296,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -368,8 +368,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -431,13 +431,13 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -447,8 +447,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
5 changes: 3 additions & 2 deletions ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"net/http"
"testing"

"github.com/alecthomas/assert"
"github.com/stretchr/testify/require"
"github.com/wakatime/wakatime-cli/pkg/api"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type (
Expand Down
46 changes: 28 additions & 18 deletions pkg/heartbeat/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ const (
LanguageFoxPro
// LanguageFreefem represents the Freefem programming language.
LanguageFreefem
// LangauageFreeMarker represents the FreeMarker programming language.
LangauageFreeMarker
// LangauageFrege represents the Frege programming language.
LangauageFrege
// LanguageFreeMarker represents the FreeMarker programming language.
LanguageFreeMarker
// LanguageFrege represents the Frege programming language.
LanguageFrege
// LanguageFStar represents the F* programming language.
LanguageFStar
// LanguageFuthark represents the Futhark programming language.
Expand All @@ -531,6 +531,8 @@ const (
LanguageGDNative
// LanguageGDScript represents the GDScript programming language.
LanguageGDScript
// LanguageGDScript3 represents the GDScript3 programming language.
LanguageGDScript3
// LanguageGEDCOM represents the GEDCOM programming language.
LanguageGEDCOM
// LanguageGenie represents the Genie programming language.
Expand Down Expand Up @@ -573,6 +575,8 @@ const (
LanguageGoHTMLTemplate
// LanguageGoTextTemplate represents the Go Text Template programming language.
LanguageGoTextTemplate
// LanguageGoTemplate represents the Go Template programming language.
LanguageGoTemplate
// LanguageGolo represents the Golo programming language.
LanguageGolo
// LanguageGoodDataCL represents the GoodData-CL programming language.
Expand Down Expand Up @@ -1816,8 +1820,8 @@ const (
languageFSharpStr = "F#"
languageFoxProStr = "FoxPro"
languageFreefemStr = "Freefem"
langauageFreeMarkerStr = "FreeMarker"
langauageFregeStr = "Frege"
languageFreeMarkerStr = "FreeMarker"
languageFregeStr = "Frege"
languageFutharkStr = "Futhark"
languageFStarStr = "F*"
languageFStarLiteralStr = "FStar"
Expand All @@ -1831,6 +1835,7 @@ const (
languageGDBStr = "GDB"
languageGDNativeStr = "GDNative"
languageGDScriptStr = "GDScript"
languageGDScript3Str = "GDScript3"
languageGEDCOMStr = "GEDCOM"
languageGenieStr = "Genie"
languageGenshiStr = "Genshi"
Expand Down Expand Up @@ -2365,6 +2370,7 @@ const (
languageFSharpChromaStr = "FSharp"
languageEmacsLispChromaStr = "EmacsLisp"
languageGoHTMLTemplateChromaStr = "Go HTML Template"
languageGoTemplateChromaStr = "Go Template"
languageGoTextTemplateChromaStr = "Go Text Template"
languageHxmlChromaStr = "Hxml"
languageISCdhcpdChromaStr = "ISCdhcpd"
Expand Down Expand Up @@ -2901,10 +2907,10 @@ func ParseLanguage(s string) (Language, bool) {
return LanguageFoxPro, true
case normalizeString(languageFreefemStr):
return LanguageFreefem, true
case normalizeString(langauageFreeMarkerStr):
return LangauageFreeMarker, true
case normalizeString(langauageFregeStr):
return LangauageFrege, true
case normalizeString(languageFreeMarkerStr):
return LanguageFreeMarker, true
case normalizeString(languageFregeStr):
return LanguageFrege, true
case normalizeString(languageFutharkStr):
return LanguageFuthark, true
case normalizeString(languageFStarStr):
Expand All @@ -2931,6 +2937,8 @@ func ParseLanguage(s string) (Language, bool) {
return LanguageGDNative, true
case normalizeString(languageGDScriptStr):
return LanguageGDScript, true
case normalizeString(languageGDScript3Str):
return LanguageGDScript3, true
case normalizeString(languageGEDCOMStr):
return LanguageGEDCOM, true
case normalizeString(languageGenieStr):
Expand Down Expand Up @@ -3999,9 +4007,9 @@ func ParseLanguageFromChroma(lexerName string) (Language, bool) {
return LanguageDNSZone, true
case normalizeString(languageEmacsLispChromaStr):
return LanguageEmacsLisp, true
case normalizeString(languageGoHTMLTemplateChromaStr):
return LanguageGo, true
case normalizeString(languageGoTextTemplateChromaStr):
case normalizeString(languageGoHTMLTemplateChromaStr),
normalizeString(languageGoTextTemplateChromaStr),
normalizeString(languageGoTemplateChromaStr):
return LanguageGo, true
case normalizeString(languageFSharpChromaStr):
return LanguageFSharp, true
Expand Down Expand Up @@ -4587,10 +4595,10 @@ func (l Language) String() string {
return languageFoxProStr
case LanguageFreefem:
return languageFreefemStr
case LangauageFreeMarker:
return langauageFreeMarkerStr
case LangauageFrege:
return langauageFregeStr
case LanguageFreeMarker:
return languageFreeMarkerStr
case LanguageFrege:
return languageFregeStr
case LanguageFuthark:
return languageFutharkStr
case LanguageFStar:
Expand All @@ -4613,6 +4621,8 @@ func (l Language) String() string {
return languageGDBStr
case LanguageGDScript:
return languageGDScriptStr
case LanguageGDScript3:
return languageGDScript3Str
case LanguageGEDCOM:
return languageGEDCOMStr
case LanguageGenie:
Expand Down Expand Up @@ -4651,7 +4661,7 @@ func (l Language) String() string {
return languageGNStr
case LanguageGnuplot:
return languageGnuplotStr
case LanguageGo, LanguageGoHTMLTemplate, LanguageGoTextTemplate:
case LanguageGo, LanguageGoTemplate, LanguageGoHTMLTemplate, LanguageGoTextTemplate:
return languageGoStr
case LanguageGolo:
return languageGoloStr
Expand Down
6 changes: 3 additions & 3 deletions pkg/heartbeat/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ func languageTests() map[string]heartbeat.Language {
"Fortran Free Form": heartbeat.LanguageFortranFreeForm,
"FoxPro": heartbeat.LanguageFoxPro,
"Freefem": heartbeat.LanguageFreefem,
"FreeMarker": heartbeat.LangauageFreeMarker,
"Frege": heartbeat.LangauageFrege,
"FreeMarker": heartbeat.LanguageFreeMarker,
"Frege": heartbeat.LanguageFrege,
"Futhark": heartbeat.LanguageFuthark,
"Game Maker Language": heartbeat.LanguageGameMakerLanguage,
"GAML": heartbeat.LanguageGAML,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ func TestLanguage_StringChroma_AllLexersSupported(t *testing.T) {

// Aliases, which match in addition to standard spelling of languages are ignored here.
switch config.Name {
case "Go HTML Template", "Go Text Template":
case "Go HTML Template", "Go Text Template", "Go Template":
continue
case "TypoScriptCssData", "TypoScriptHtmlData":
continue
Expand Down
5 changes: 1 addition & 4 deletions pkg/language/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/language"
"github.com/wakatime/wakatime-cli/pkg/lexer"
_ "github.com/wakatime/wakatime-cli/pkg/lexer" // force to load all lexers

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -257,9 +257,6 @@ func TestDetect_FSharp_Over_Forth(t *testing.T) {
}

func TestDetect_ChromaTopLanguagesRetrofit(t *testing.T) {
err := lexer.RegisterAll()
require.NoError(t, err)

tests := map[string]struct {
Filepaths []string
Expected heartbeat.Language
Expand Down
37 changes: 13 additions & 24 deletions pkg/lexer/actionscript3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,29 @@ import (
"regexp"

"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/lexers"
)

// nolint:gochecknoglobals
var actionscript3AnalyserRe = regexp.MustCompile(`\w+\s*:\s*\w`)

// ActionScript3 lexer.
type ActionScript3 struct{}
// nolint:gochecknoinits
func init() {
language := heartbeat.LanguageActionScript3.StringChroma()
lexer := lexers.Get(language)

// Lexer returns the lexer.
func (l ActionScript3) Lexer() chroma.Lexer {
lexer := lexers.Get(l.Name())
if lexer == nil {
return nil
log.Debugf("lexer %q not found", language)
return
}

if lexer, ok := lexer.(*chroma.RegexLexer); ok {
lexer.SetAnalyser(func(text string) float32 {
if actionscript3AnalyserRe.MatchString(text) {
return 0.3
}
lexer.SetAnalyser(func(text string) float32 {
if actionscript3AnalyserRe.MatchString(text) {
return 0.3
}

return 0
})

return lexer
}

return nil
}

// Name returns the name of the lexer.
func (ActionScript3) Name() string {
return heartbeat.LanguageActionScript.StringChroma()
return 0
})
}
Loading

0 comments on commit bb856ef

Please sign in to comment.