diff --git a/deps/JuliaSyntax.version b/deps/JuliaSyntax.version index 9487754d8a617..94f480c65dcf7 100644 --- a/deps/JuliaSyntax.version +++ b/deps/JuliaSyntax.version @@ -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 diff --git a/deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/md5 b/deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/md5 deleted file mode 100644 index ff40f520dfe85..0000000000000 --- a/deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/md5 +++ /dev/null @@ -1 +0,0 @@ -2a0921e59edfab54554aa173f091c5b7 diff --git a/deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/sha512 b/deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/sha512 deleted file mode 100644 index 64e90d0edaba0..0000000000000 --- a/deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/sha512 +++ /dev/null @@ -1 +0,0 @@ -17050e23216335f6599f009f71e9614a11b6686e455554b1efd287cd8526a7ebece06dc473e34cd50f61bf52085ff72bb4279144a9fdb3a234d3d589a10fddaf diff --git a/deps/checksums/JuliaSyntax-99e975a726a82994de3f8e961e6fa8d39aed0d37.tar.gz/md5 b/deps/checksums/JuliaSyntax-99e975a726a82994de3f8e961e6fa8d39aed0d37.tar.gz/md5 new file mode 100644 index 0000000000000..12fce1e97c1db --- /dev/null +++ b/deps/checksums/JuliaSyntax-99e975a726a82994de3f8e961e6fa8d39aed0d37.tar.gz/md5 @@ -0,0 +1 @@ +ecef4caa8b237a51f92d5622b811a0c3 diff --git a/deps/checksums/JuliaSyntax-99e975a726a82994de3f8e961e6fa8d39aed0d37.tar.gz/sha512 b/deps/checksums/JuliaSyntax-99e975a726a82994de3f8e961e6fa8d39aed0d37.tar.gz/sha512 new file mode 100644 index 0000000000000..f042854e27a47 --- /dev/null +++ b/deps/checksums/JuliaSyntax-99e975a726a82994de3f8e961e6fa8d39aed0d37.tar.gz/sha512 @@ -0,0 +1 @@ +56dc5158ebfaf0d5e3e5002dfeb322a137f0866add071cfa9f7a0d9ef2d40859e4c6131358c5aeaf0e9e39fe77a94ba88022028092230b059099cd87e2b795ac diff --git a/deps/checksums/JuliaSyntaxHighlighting-c64204160b0f82f2ab002db9c39a25896999b8f1.tar.gz/md5 b/deps/checksums/JuliaSyntaxHighlighting-c64204160b0f82f2ab002db9c39a25896999b8f1.tar.gz/md5 deleted file mode 100644 index ab25499278eb5..0000000000000 --- a/deps/checksums/JuliaSyntaxHighlighting-c64204160b0f82f2ab002db9c39a25896999b8f1.tar.gz/md5 +++ /dev/null @@ -1 +0,0 @@ -a0a07c2a5d4b6456b97ecd5193cd7381 diff --git a/deps/checksums/JuliaSyntaxHighlighting-c64204160b0f82f2ab002db9c39a25896999b8f1.tar.gz/sha512 b/deps/checksums/JuliaSyntaxHighlighting-c64204160b0f82f2ab002db9c39a25896999b8f1.tar.gz/sha512 deleted file mode 100644 index 4ea3829b8ed03..0000000000000 --- a/deps/checksums/JuliaSyntaxHighlighting-c64204160b0f82f2ab002db9c39a25896999b8f1.tar.gz/sha512 +++ /dev/null @@ -1 +0,0 @@ -219d6f79928b5b89ae177f21877437fcb385c734828b52264db4e955fe0b6f7f309d3b7081c379240a8e8c2ea9e3d2d8218e08d1f6ff9c786d96a0218c8e4de2 diff --git a/deps/checksums/JuliaSyntaxHighlighting-e34cc37a7ab62db1e06152d8f2602bd2187fa473.tar.gz/md5 b/deps/checksums/JuliaSyntaxHighlighting-e34cc37a7ab62db1e06152d8f2602bd2187fa473.tar.gz/md5 new file mode 100644 index 0000000000000..100b232bb6840 --- /dev/null +++ b/deps/checksums/JuliaSyntaxHighlighting-e34cc37a7ab62db1e06152d8f2602bd2187fa473.tar.gz/md5 @@ -0,0 +1 @@ +7f8298d198ed88b283a1eb15b5614315 diff --git a/deps/checksums/JuliaSyntaxHighlighting-e34cc37a7ab62db1e06152d8f2602bd2187fa473.tar.gz/sha512 b/deps/checksums/JuliaSyntaxHighlighting-e34cc37a7ab62db1e06152d8f2602bd2187fa473.tar.gz/sha512 new file mode 100644 index 0000000000000..f9da526150e2c --- /dev/null +++ b/deps/checksums/JuliaSyntaxHighlighting-e34cc37a7ab62db1e06152d8f2602bd2187fa473.tar.gz/sha512 @@ -0,0 +1 @@ +7fe9ced894688f843a8520078302225c125a9d017d4ee96a94db41553b47b044341ac158e9816bab0a5faf8b15f934c72bdb6707ccad3b8a2539131a42a84fb6 diff --git a/stdlib/JuliaSyntaxHighlighting.version b/stdlib/JuliaSyntaxHighlighting.version index fbeb67059f34f..ef804afd4685a 100644 --- a/stdlib/JuliaSyntaxHighlighting.version +++ b/stdlib/JuliaSyntaxHighlighting.version @@ -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 diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index a4c12880866db..4d0c250c61417 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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"." diff --git a/stdlib/REPL/src/SyntaxUtil.jl b/stdlib/REPL/src/SyntaxUtil.jl index 6b455aa16dc9f..86178b45bf163 100644 --- a/stdlib/REPL/src/SyntaxUtil.jl +++ b/stdlib/REPL/src/SyntaxUtil.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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