Skip to content
Merged
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
28 changes: 21 additions & 7 deletions languages/julia/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
(identifier) @function.call
(#any-of? @_pipe "|>" ".|>"))

(macro_definition
(signature
(call_expression
.
(identifier) @function.macro)))

; Built-in functions
; print.("\"", filter(name -> getglobal(Core, name) isa Core.Builtin, names(Core)), "\" ")
((identifier) @function.builtin
Expand Down Expand Up @@ -94,7 +88,7 @@
(assignment
.
(identifier) @constant))

; Zed - moved after builtins to ensure macro highlights take precedence
(macro_identifier
"@" @function.macro
Expand Down Expand Up @@ -319,25 +313,45 @@
.
[
(identifier) @function.definition
; match `foo()` or `foo()::T` or `foo() where...` or `foo()::T where...`
(call_expression (identifier) @function.definition)
(typed_expression . (call_expression (identifier) @function.definition))
(where_expression . (call_expression (identifier) @function.definition))
(where_expression . (typed_expression . (call_expression (identifier) @function.definition)))
; match `Base.foo()` or `Base.foo()::T` or `Base.foo() where...` or `Base.foo()::T where...`
(call_expression (field_expression (identifier) @function.definition .))
(typed_expression . (call_expression (field_expression (identifier) @function.definition .)))
(where_expression . (call_expression (field_expression (identifier) @function.definition .)))
(where_expression . (typed_expression . (call_expression (field_expression (identifier) @function.definition .))))
]))

; Zed - added: Short function definitions like `foo(x) = 2x`
(assignment
.
[
; match `foo()` or `foo()::T` or `foo() where...` or `foo()::T where...`
(call_expression (identifier) @function.definition)
(typed_expression . (call_expression (identifier) @function.definition))
(where_expression . (call_expression (identifier) @function.definition))
(where_expression . (typed_expression . (call_expression (identifier) @function.definition)))
; match `Base.foo()` or `Base.foo()::T` or `Base.foo() where...` or `Base.foo()::T where...`
(call_expression (field_expression (identifier) @function.definition .))
(typed_expression . (call_expression (field_expression (identifier) @function.definition .)))
(where_expression . (call_expression (field_expression (identifier) @function.definition .)))
(where_expression . (typed_expression . (call_expression (field_expression (identifier) @function.definition .))))
]
(operator) @keyword.function)

; Zed - added: Macro definition name highlighting
(macro_definition
(signature
[
(call_expression . (identifier) @function.macro)
(typed_expression . (call_expression . (identifier) @function.macro))
(where_expression . (call_expression . (identifier) @function.macro))
(where_expression . (typed_expression . (call_expression . (identifier) @function.macro)))
]))

; Keyword operators
((operator) @keyword.operator
(#any-of? @keyword.operator "in" "isa"))
Expand Down
40 changes: 26 additions & 14 deletions languages/julia/outline.scm
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,23 @@
"struct" @context
(type_head) @name) @item

; Match long function definitions like `function foo(x) ... end`.
; Handle all four combinations: plain, with return type, with where clause, or both.
(function_definition
"function" @context
(signature
(call_expression
[
(identifier) @name ; match foo()
(field_expression _+ @context (identifier) @name .) ; match Base.foo()
]
(argument_list)? @context)
(_)* @context ; match the rest of the signature e.g., return_type and/or where_clause
[
; match `foo()` or `foo()::T` or `foo() where...` or `foo()::T where...`
(call_expression (identifier) @name (argument_list)? @context)
(typed_expression (call_expression (identifier) @name (argument_list)? @context) _+ @context)
(where_expression (call_expression (identifier) @name (argument_list)? @context) _+ @context)
(where_expression (typed_expression (call_expression (identifier) @name (argument_list)? @context) _+ @context) _+ @context)
; match `Base.foo()` or `Base.foo()::T` or `Base.foo() where...` or `Base.foo()::T where...`
(call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context)
(typed_expression (call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context) _+ @context)
(where_expression (call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context) _+ @context)
(where_expression (typed_expression (call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context) _+ @context) _+ @context)
]
)) @item

; Match short function definitions like foo(x) = 2x.
Expand All @@ -72,13 +79,18 @@
(macro_definition
"macro" @context
(signature
(call_expression
[
(identifier) @name ; match foo()
(field_expression _+ @context (identifier) @name .) ; match Base.foo()
]
(argument_list)? @context)
(_)* @context ; match the rest of the signature e.g., return_type
[
; match `foo()` or `foo()::T` or `foo() where...` or `foo()::T where...`
(call_expression (identifier) @name (argument_list)? @context)
(typed_expression (call_expression (identifier) @name (argument_list)? @context) _+ @context)
(where_expression (call_expression (identifier) @name (argument_list)? @context) _+ @context)
(where_expression (typed_expression (call_expression (identifier) @name (argument_list)? @context) _+ @context) _+ @context)
; match `Base.foo()` or `Base.foo()::T` or `Base.foo() where...` or `Base.foo()::T where...`
(call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context)
(typed_expression (call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context) _+ @context)
(where_expression (call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context) _+ @context)
(where_expression (typed_expression (call_expression (field_expression _+ @context (identifier) @name .) (argument_list)? @context) _+ @context) _+ @context)
]
)) @item

(const_statement
Expand Down
40 changes: 39 additions & 1 deletion syntax-test-cases/edge-cases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ begin
# this is a block, not an index
end

# ------------
# ------------
# Zed specials
# ------------

Expand All @@ -34,6 +34,44 @@ function foo end
function foo(x) 2x end
function Base.foo(x) 2x end

# Long function definitions with return types and where clauses
# (highlight the function name as @function.definition)
# (these should all show in the outline panel)
function foo_plain(x)
return x + 1
end

function bar_typed(x)::String
return string(x)
end

function baz_typed(x::Int)::Int
return x * 2
end

function qux_typed(x::Int, y::Int)::Float64
return x / y
end

function quux_where(x::T) where T
return x + 1
end

function corge_both(x::T)::Int where T
return x * 2
end

# Macro definitions with return types and where clauses
# (highlight the macro name as @function.macro)
# (all should appear in outline)
macro mymacro(ex)
return esc(ex)
end

macro typed_macro(ex)::Expr
return esc(ex)
end

# Short function definitions
# (highlight the function name as @function.definition
# and the equal sign as @keyword.function)
Expand Down