Skip to content

feat(fsharp): add F# support #35

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions queries/fsharp/rainbow-delimiters.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
; ─── Disabled due to being unable to match more than one argument at a time ───
;
;(argument_patterns
; ("(" @opening ")" @closing)+
; ) @container
;
;(record_type_defn
; "{" @opening
; "}" @closing
; ) @container
;
;(type_arguments
; "<" @opening
; ">" @closing
; ) @container
;

; highlight unit expressions in function applications
; and return types for consistency
(application_expression
(const
(unit
"(" @opening
")" @closing
)) @container
)

(return_expression
(const
(unit
"(" @opening
")" @closing
)) @container
)

(if_expression
(const
(unit
"(" @opening
")" @closing
)) @container
)

(method_or_prop_defn
(const
(unit
"(" @opening
")" @closing
)) @container
)

(function_or_value_defn
body: (const
(unit
"(" @opening
")" @closing
)) @container
)

(paren_expression
"(" @opening
")" @closing
) @container

(paren_pattern
"(" @opening
")" @closing
) @container

(type
"(" @opening
")" @closing
) @container

(type
"<" @opening
">" @closing
) @container


(list_pattern
"[" @opening
"]" @closing
) @container

(array_pattern
"[|" @opening
"|]" @closing
) @container

(ce_expression
[ (return_expression (long_identifier_or_op (long_identifier)))
(long_identifier_or_op (long_identifier))
] @intermediate

"{" @opening
"}" @closing
) @container
112 changes: 112 additions & 0 deletions test/highlight/fsharp/regular.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
module Regular

let no_args () =
()

let one_arg (x: int) =
x

let two_args (x: int) (y: int) =
x + y

let three_args (x: int) (y: int) (z: int) =
x + y + z

let tuple ( (x: (int * float)) ) =
x

let destructured_tuple ((a, b): int * int) =
a + b

let array (x: int array) = function
| [|x|] -> x
| [| x; y; z |] -> x + y + x
| _ -> 0

let nested_array (x: int array array) = function
| [| [| [| x |] |] |] -> x
| [| [| [| x; y; z |] |] |] -> x + y + z
| _ -> 0

let list (x: int list) = function
| [x] -> x
| [ x; y; z ] -> x + y + x
| _ -> 0

let nested_list (x: int list list) = function
| [ [ [ x ] ] ] -> x
| [ [ [ x; y; z ] ] ] -> x + y + x
| _ -> 0

let return_value =
(Some (Ok (Some (2))))

let type_argument (x: seq<'a>) =
x

let nested_type_argument (x: seq<seq<seq<int>>>) =
x

type Record =
{ a: int
b: string
}

type Union =
| Tuple of (int * float)
| NestedTuple of (int * (int * (int * int)))
| TypeArgs of Result<seq<int>, float>

type Wrapper = Wrapper of int * int

let unwrap (Wrapper (a, b)) =
a + b

let lambda =
(fun x -> (fun (a, b) -> x))

let match_test x =
match x with
| (Some (((((Some (a))))))) -> a
| _ -> 0

let unit_args () () () =
()

let computation_expressions asyncFn (x: int) =
async {
let t =
task {
let a = 2
let b = 3
return async {
let! res = asyncFn (x)
return res + a + b
}
}
return t
}

let if_tests (x: int) =
if x <> 0 then
()
elif x < 1 then
()
else
()


type Class(a: int) =
member _.A () =
(a)

member this.Member () =
()

static member StaticMember () =
()

let main _ =
unit_args () ((((((((((())))))))))) ();
one_arg ((((((((((((1)))))))))))) |> ignore;
two_args (1) (((((((((2))))))))) |> ignore;