chroma
chroma copied to clipboard
GDScript3 detected over F# (FSharp)
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
Current Chroma version is detecting this sample file which is a F# demo code as GDScript3.
// ================================================
// More on functions
// ================================================
// F# is a true functional language -- functions are first
// class entities and can be combined easily to make powerful
// constructs
// Modules are used to group functions together
// Indentation is needed for each nested module.
module FunctionExamples =
// define a simple adding function
let add x y = x + y
// basic usage of a function
let a = add 1 2
printfn "1 + 2 = %i" a
// partial application to "bake in" parameters
let add42 = add 42
let b = add42 1
printfn "42 + 1 = %i" b
// composition to combine functions
let add1 = add 1
let add2 = add 2
let add3 = add1 >> add2
let c = add3 7
printfn "3 + 7 = %i" c
// higher order functions
[1..10] |> List.map add3 |> printfn "new list is %A"
// lists of functions, and more
let add6 = [add1; add2; add3] |> List.reduce (>>)
let d = add6 7
printfn "1 + 2 + 3 + 7 = %i" d
To Reproduce
// data is max 512kb
lexers.Analyse(string(data))
@gandarez
I added some logs to registry.go's Analyse() function, and GDScript3 has 0.2 weight whereas all other languages have 0.
The thing is your F# code has a // constructs comment, and GSCript3 has a 0.2 score when detecting const, I tried removing this comment and every language then had a score of 0.
#848 introduced an analysis regex which matches to pretty common keywords across languages, such as var or const, which is in my opinion at least annoying and at most problematic.
The diff for registry.go :
diff --git a/registry.go b/registry.go
index a309af9..effc96a 100644
--- a/registry.go
+++ b/registry.go
@@ -183,6 +183,9 @@ func (l *LexerRegistry) Analyse(text string) Lexer {
for _, lexer := range l.Lexers {
if analyser, ok := lexer.(Analyser); ok {
weight := analyser.AnalyseText(text)
+ if weight != 0 {
+ println(lexer.Config().Name, weight)
+ }
if weight > highest {
picked = lexer
highest = weight