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
2 changes: 1 addition & 1 deletion deps/JuliaSyntax.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JULIASYNTAX_BRANCH = main
JULIASYNTAX_SHA1 = 46723f071d5b2efcb21ca6757788028afb91cc13
JULIASYNTAX_SHA1 = 99e975a726a82994de3f8e961e6fa8d39aed0d37
JULIASYNTAX_GIT_URL := https://github.com/JuliaLang/JuliaSyntax.jl.git
JULIASYNTAX_TAR_URL = https://api.github.com/repos/JuliaLang/JuliaSyntax.jl/tarball/$1

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ecef4caa8b237a51f92d5622b811a0c3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
56dc5158ebfaf0d5e3e5002dfeb322a137f0866add071cfa9f7a0d9ef2d40859e4c6131358c5aeaf0e9e39fe77a94ba88022028092230b059099cd87e2b795ac

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7f8298d198ed88b283a1eb15b5614315
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7fe9ced894688f843a8520078302225c125a9d017d4ee96a94db41553b47b044341ac158e9816bab0a5faf8b15f934c72bdb6707ccad3b8a2539131a42a84fb6
2 changes: 1 addition & 1 deletion stdlib/JuliaSyntaxHighlighting.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JULIASYNTAXHIGHLIGHTING_BRANCH = main
JULIASYNTAXHIGHLIGHTING_SHA1 = c64204160b0f82f2ab002db9c39a25896999b8f1
JULIASYNTAXHIGHLIGHTING_SHA1 = e34cc37a7ab62db1e06152d8f2602bd2187fa473
JULIASYNTAXHIGHLIGHTING_GIT_URL := https://github.com/julialang/JuliaSyntaxHighlighting.jl.git
JULIASYNTAXHIGHLIGHTING_TAR_URL = https://api.github.com/repos/julialang/JuliaSyntaxHighlighting.jl/tarball/$1
19 changes: 11 additions & 8 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Base.Filesystem: _readdirx
using Base.JuliaSyntax: @K_str, @KSet_str, parseall, byte_range, children, is_prefix_call, is_trivia, kind

using ..REPL.LineEdit: NamedCompletion
using ..REPL.SyntaxUtil: CursorNode, find_parent, seek_pos, char_range, char_last, children_nt, find_delim
using ..REPL.SyntaxUtil: CursorNode, find_parent, seek_pos, char_range, char_first, char_last, children_nt, find_delim

abstract type Completion end

Expand Down Expand Up @@ -1043,7 +1043,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
# `file ~/exa TAB => `file ~/example.txt
# `file ~/example.txt TAB => `file /home/user/example.txt
if (n = find_parent(cur, K"CmdString")) !== nothing
off = n.position - 1
off = char_first(n) - 1
ret, r, success = shell_completions(string[char_range(n)], pos - off, hint, cmd_escape=true)
success && return ret, r .+ off, success
end
Expand Down Expand Up @@ -1107,14 +1107,14 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
# Symbol completion
# TODO: Should completions replace the identifier at the cursor?
looks_like_ident = Base.isidentifier(@view string[intersect(char_range(cur), 1:pos)])
if cur.parent !== nothing && kind(cur.parent) == K"var"
if cur.parent !== nothing && kind(cur.parent) === K"var"
# Replace the entire var"foo", but search using only "foo".
r = intersect(char_range(cur.parent), 1:pos)
r2 = char_range(children_nt(cur.parent)[1])
s = string[intersect(r2, 1:pos)]
elseif kind(cur) == K"MacroName"
elseif cur.parent !== nothing && kind(cur.parent) === K"macro_name"
# Include the `@`
r = intersect(prevind(string, cur.position):char_last(cur), 1:pos)
r = intersect(prevind(string, char_first(cur)):char_last(cur), 1:pos)
s = string[r]
elseif looks_like_ident || kind(cur) in KSet"Bool Identifier @"
r = intersect(char_range(cur), 1:pos)
Expand All @@ -1141,7 +1141,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
end

# Allow completion for `import Mod.name` (where `name` is not a module)
complete_modules_only = prefix == nothing || kind(n.parent) == K"using"
complete_modules_only = prefix === nothing || kind(n.parent) === K"using"
comp_keywords = false
end

Expand Down Expand Up @@ -1175,8 +1175,10 @@ function find_ref_key(cur::CursorNode, pos::Int)
n = find_parent(cur, K"ref")
n !== nothing || return nothing, nothing, nothing
key, closed = find_delim(n, K"[", K"]")
first(key) - 1 <= pos <= last(key) || return nothing, nothing, nothing
n, key, closed
if key === nothing || !(first(key) - 1 <= pos <= last(key))
return nothing, nothing, nothing
end
return n, key, closed
end

# If the cursor is in a literal string, return the contents and char range
Expand Down Expand Up @@ -1212,6 +1214,7 @@ function node_prefix(node::CursorNode, context_module::Module)
p = node.parent
# In x.var"y", the parent is the "var" when the cursor is on "y".
kind(p) == K"var" && (p = p.parent)
kind(p) == K"macro_name" && (p = p.parent)

# expr.node => expr
if kind(p) == K"."
Expand Down
28 changes: 13 additions & 15 deletions stdlib/REPL/src/SyntaxUtil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export CursorNode, char_range, char_last, children_nt, find_delim, seek_pos
struct CursorData <: AbstractSyntaxData
source::SourceFile
raw::GreenNode{SyntaxHead}
position::Int
byte_end::Int
index::Int
index_nt::Int # nth non-trivia in parent
val::Any
Expand All @@ -34,10 +34,10 @@ end
function _to_CursorNode(source::SourceFile, txtbuf::Vector{UInt8}, offset::Int,
raw::GreenNode{SyntaxHead},
position::Int, index::Int=-1, index_nt::Int=-1)
byte_end = position + span(raw) - 1
if is_leaf(raw)
valrange = position:position + span(raw) - 1
val = parse_julia_literal(txtbuf, head(raw), valrange .+ offset)
return CursorNode(nothing, nothing, CursorData(source, raw, position, index, index_nt, val))
val = parse_julia_literal(txtbuf, head(raw), position:byte_end .+ offset)
return CursorNode(nothing, nothing, CursorData(source, raw, byte_end, index, index_nt, val))
else
cs = CursorNode[]
pos = position
Expand All @@ -47,7 +47,7 @@ function _to_CursorNode(source::SourceFile, txtbuf::Vector{UInt8}, offset::Int,
pos += Int(rawchild.span)
i_nt += !is_trivia(rawchild)
end
node = CursorNode(nothing, cs, CursorData(source, raw, position, index, index_nt, nothing))
node = CursorNode(nothing, cs, CursorData(source, raw, byte_end, index, index_nt, nothing))
for c in cs
c.parent = node
end
Expand All @@ -65,16 +65,14 @@ end
Base.show(io::IO, node::CursorNode) = show(io, MIME("text/plain"), node.raw)
Base.show(io::IO, mime::MIME{Symbol("text/plain")}, node::CursorNode) = show(io, mime, node.raw)

function Base.Expr(node::CursorNode)
(; filename, first_line) = node.source
src = SourceFile(node.source[byte_range(node)]; filename, first_line)
Expr(SyntaxNode(src, node.raw))
end
Base.JuliaSyntax._expr_leaf_val(node::CursorNode, _...) = node.val
Base.Expr(node::CursorNode) = Base.JuliaSyntax.to_expr(node)

char_range(node) = node.position:char_last(node)
char_last(node) = thisind(node.source, node.position + span(node) - 1)
char_range(node::CursorNode) = char_first(node):char_last(node)
char_first(node::CursorNode) = Int(node.byte_end) - Int(node.raw.span) + 1
char_last(node::CursorNode) = thisind(node.source, node.byte_end)

children_nt(node) = [n for n in children(node) if !is_trivia(n)]
children_nt(node::CursorNode) = [n for n in children(node) if !is_trivia(n)]

function seek_pos(node, pos)
pos in byte_range(node) || return nothing
Expand All @@ -97,13 +95,13 @@ end
# Return the character range between left_kind and right_kind in node. The left
# delimiter must be present, while the range will extend to the rest of the node
# if the right delimiter is missing.
function find_delim(node, left_kind, right_kind)
function find_delim(node::CursorNode, left_kind::Kind, right_kind::Kind)
cs = children(node)
left = findfirst(c -> kind(c) == left_kind, cs)
left !== nothing || return nothing, nothing
right = findlast(c -> kind(c) == right_kind, cs)
closed = right !== nothing && right != left
right = closed ? thisind(node.source, cs[right].position - 1) : char_last(node)
right = closed ? thisind(node.source, char_first(cs[right]) - 1) : char_last(node)
left = nextind(node.source, char_last(cs[left]))
return left:right, closed
end
Expand Down