Skip to content

Commit

Permalink
More julia improvements (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmandlik authored Apr 30, 2024
1 parent 156d578 commit 8b34305
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 47 deletions.
6 changes: 3 additions & 3 deletions queries/julia/endwise.scm
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
((ERROR "try" @indent @cursor)
(#endwise! "end"))

((for_statement (for_binding) @cursor) @indent @endable
((for_statement . (for_binding)* . (for_binding) @cursor) @indent @endable
(#endwise! "end"))

((ERROR "for" (for_binding) @cursor @indent .)
((ERROR "for" @indent . (for_binding)* . (for_binding) @cursor)
(#endwise! "end"))

((while_statement condition: (_) @cursor) @indent @endable
Expand All @@ -53,7 +53,7 @@
(#endwise! "end"))

((ERROR "let" @cursor @indent
[(identifier) (let_binding) (assignment)]? @cursor @indent .
[(identifier) (let_binding) (assignment)]? @cursor
)
(#endwise! "end"))

Expand Down
188 changes: 144 additions & 44 deletions tests/endwise/julia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@
+end
END

test "julia, struct, correct indent 1", <<~END
-struct Foo{
- }█
+struct Foo{
+ }
+
+end
END

test "julia, struct, correct indent 2", <<~END
-struct Foo{} <: Bar{T
- }█
+struct Foo{} <: Bar{T
+ }
+
+end
END

test "julia, struct, correct indent 3", <<~END
-struct Foo{} <:
- Bar{T}█
+struct Foo{} <:
+ Bar{T}
+
+end
END

test "julia, struct, nested 1", <<~END
-struct Foo <: Bar
- mutable struct Baz{T}█
Expand Down Expand Up @@ -293,12 +320,6 @@
+end
END

# test "julia, if, predicate, noop", <<~END
# -if pred(█)
# +if pred(
# + )
# END

# broken due to a bug in ts parser https://github.com/tree-sitter/tree-sitter-julia/issues/117
# test "julia, if, expression 1", <<~END
# -if 1 + 1 == 2█
Expand All @@ -321,6 +342,33 @@
+end
END

test "julia, if, correct indent 1", <<~END
-if !(a && true
- )█
+if !(a && true
+ )
+
+end
END

test "julia, if, correct indent 2", <<~END
-if a ||
- b█
+if a ||
+ b
+
+end
END

test "julia, if, correct indent 3", <<~END
-if a(
- )█
+if a(
+ )
+
+end
END

test "julia, if, nested", <<~END
-if !(a && b)
- if bar█
Expand Down Expand Up @@ -525,25 +573,46 @@
END

test "julia, for loop, function", <<~END
-for i in f()█
+for i in f()
-for i f()█
+for i f()
+
+end
END

# test "julia, for loop, noop", <<~END
# -for i in f(█)
# +for i in f(
# + )
# END

test "julia, for loop, double", <<~END
-for i in 1:10, j = 1:10█
+for i in 1:10, j = 1:10
+
+end
END

test "julia, for loop, correct indent 1", <<~END
-for i in f(
- )█
+for i in f(
+ )
+
+end
END

test "julia, for loop, correct indent 2", <<~END
-for i = 1:10,
- j = 1:10█
+for i = 1:10,
+ j = 1:10
+
+end
END

test "julia, for loop, correct indent 3", <<~END
-for i in 1:10, j in f(
- )█
+for i in 1:10, j in f(
+ )
+
+end
END

test "julia, for loop, nested 1", <<~END
-for i in 1:10, j in list1
- for (k, l) in list2█
Expand Down Expand Up @@ -628,11 +697,32 @@
+end
END

# test "julia, while, predicate, noop", <<~END
# -while pred(█)
# +while pred(
# + )
# END
test "julia, while, correct indent 1", <<~END
-while !(a && true
- )█
+while !(a && true
+ )
+
+end
END

test "julia, while, correct indent 2", <<~END
-while a ||
- b█
+while a ||
+ b
+
+end
END

test "julia, while, correct indent 3", <<~END
-while a(
- )█
+while a(
+ )
+
+end
END

# broken due to a bug in ts parser https://github.com/tree-sitter/tree-sitter-julia/issues/117
# test "julia, while, expression 1", <<~END
Expand Down Expand Up @@ -736,11 +826,32 @@
+end
END

# test "julia, let, function, noop", <<~END
# -let x = f(█)
# +let x = f(
# + )
# END
test "julia, let loop, correct indent 1", <<~END
-let i = f(
- )█
+let i = f(
+ )
+
+end
END

test "julia, let loop, correct indent 2", <<~END
-let i = 1,
- j = 2█
+let i = 1,
+ j = 2
+
+end
END

test "julia, let loop, correct indent 3", <<~END
-let i = 1, j = f(
- )█
+let i = 1, j = f(
+ )
+
+end
END

test "julia, let, nested 1", <<~END
-let z
Expand Down Expand Up @@ -794,14 +905,15 @@
+end
END

test "julia, let, incomplete", <<~END
-let
- a = let x, y = 1, z█
+let
+ a = let x, y = 1, z
+
+ end
END
# broken
# test "julia, let, incomplete", <<~END
# -a = let x
# - let y = 1, z█
# +a = let x
# + let y = 1, z
# +
# + end
# END

##################################################

Expand All @@ -826,12 +938,6 @@
+end
END

# test "julia, function, noop", <<~END
# -function f(█)
# +function f(
# +)
# END

test "julia, function, return type", <<~END
-function foo(x::Any, y::Int)::Int8█
+function foo(x::Any, y::Int)::Int8
Expand Down Expand Up @@ -937,12 +1043,6 @@
+end
END

# test "julia, macro, noop within brackets", <<~END
# -macro f(█)
# +macro f(
# + )
# END

test "julia, macro, constant", <<~END
-macro f()█
+macro f()
Expand Down

0 comments on commit 8b34305

Please sign in to comment.