Skip to content

Commit 9b65943

Browse files
committed
JuliaSyntax version bump and REPL tweaks
1 parent 040f6cd commit 9b65943

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

deps/JuliaSyntax.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
JULIASYNTAX_BRANCH = main
2-
JULIASYNTAX_SHA1 = 46723f071d5b2efcb21ca6757788028afb91cc13
2+
JULIASYNTAX_SHA1 = 99e975a726a82994de3f8e961e6fa8d39aed0d37
33
JULIASYNTAX_GIT_URL := https://github.com/JuliaLang/JuliaSyntax.jl.git
44
JULIASYNTAX_TAR_URL = https://api.github.com/repos/JuliaLang/JuliaSyntax.jl/tarball/$1

deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/JuliaSyntax-46723f071d5b2efcb21ca6757788028afb91cc13.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ecef4caa8b237a51f92d5622b811a0c3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
56dc5158ebfaf0d5e3e5002dfeb322a137f0866add071cfa9f7a0d9ef2d40859e4c6131358c5aeaf0e9e39fe77a94ba88022028092230b059099cd87e2b795ac

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using Base.Filesystem: _readdirx
1515
using Base.JuliaSyntax: @K_str, @KSet_str, parseall, byte_range, children, is_prefix_call, is_trivia, kind
1616

1717
using ..REPL.LineEdit: NamedCompletion
18-
using ..REPL.SyntaxUtil: CursorNode, find_parent, seek_pos, char_range, char_last, children_nt, find_delim
18+
using ..REPL.SyntaxUtil: CursorNode, find_parent, seek_pos, char_range, char_first, char_last, children_nt, find_delim
1919

2020
abstract type Completion end
2121

@@ -1043,7 +1043,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
10431043
# `file ~/exa TAB => `file ~/example.txt
10441044
# `file ~/example.txt TAB => `file /home/user/example.txt
10451045
if (n = find_parent(cur, K"CmdString")) !== nothing
1046-
off = n.position - 1
1046+
off = char_first(n) - 1
10471047
ret, r, success = shell_completions(string[char_range(n)], pos - off, hint, cmd_escape=true)
10481048
success && return ret, r .+ off, success
10491049
end
@@ -1107,14 +1107,14 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
11071107
# Symbol completion
11081108
# TODO: Should completions replace the identifier at the cursor?
11091109
looks_like_ident = Base.isidentifier(@view string[intersect(char_range(cur), 1:pos)])
1110-
if cur.parent !== nothing && kind(cur.parent) == K"var"
1110+
if cur.parent !== nothing && kind(cur.parent) === K"var"
11111111
# Replace the entire var"foo", but search using only "foo".
11121112
r = intersect(char_range(cur.parent), 1:pos)
11131113
r2 = char_range(children_nt(cur.parent)[1])
11141114
s = string[intersect(r2, 1:pos)]
1115-
elseif kind(cur) == K"MacroName"
1115+
elseif cur.parent !== nothing && kind(cur.parent) === K"macro_name"
11161116
# Include the `@`
1117-
r = intersect(prevind(string, cur.position):char_last(cur), 1:pos)
1117+
r = intersect(prevind(string, char_first(cur)):char_last(cur), 1:pos)
11181118
s = string[r]
11191119
elseif looks_like_ident || kind(cur) in KSet"Bool Identifier @"
11201120
r = intersect(char_range(cur), 1:pos)
@@ -1141,7 +1141,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
11411141
end
11421142

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

@@ -1175,8 +1175,10 @@ function find_ref_key(cur::CursorNode, pos::Int)
11751175
n = find_parent(cur, K"ref")
11761176
n !== nothing || return nothing, nothing, nothing
11771177
key, closed = find_delim(n, K"[", K"]")
1178-
first(key) - 1 <= pos <= last(key) || return nothing, nothing, nothing
1179-
n, key, closed
1178+
if key === nothing || !(first(key) - 1 <= pos <= last(key))
1179+
return nothing, nothing, nothing
1180+
end
1181+
return n, key, closed
11801182
end
11811183

11821184
# 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)
12121214
p = node.parent
12131215
# In x.var"y", the parent is the "var" when the cursor is on "y".
12141216
kind(p) == K"var" && (p = p.parent)
1217+
kind(p) == K"macro_name" && (p = p.parent)
12151218

12161219
# expr.node => expr
12171220
if kind(p) == K"."

stdlib/REPL/src/SyntaxUtil.jl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export CursorNode, char_range, char_last, children_nt, find_delim, seek_pos
1414
struct CursorData <: AbstractSyntaxData
1515
source::SourceFile
1616
raw::GreenNode{SyntaxHead}
17-
position::Int
17+
byte_end::Int
1818
index::Int
1919
index_nt::Int # nth non-trivia in parent
2020
val::Any
@@ -34,10 +34,10 @@ end
3434
function _to_CursorNode(source::SourceFile, txtbuf::Vector{UInt8}, offset::Int,
3535
raw::GreenNode{SyntaxHead},
3636
position::Int, index::Int=-1, index_nt::Int=-1)
37+
byte_end = position + span(raw) - 1
3738
if is_leaf(raw)
38-
valrange = position:position + span(raw) - 1
39-
val = parse_julia_literal(txtbuf, head(raw), valrange .+ offset)
40-
return CursorNode(nothing, nothing, CursorData(source, raw, position, index, index_nt, val))
39+
val = parse_julia_literal(txtbuf, head(raw), position:byte_end .+ offset)
40+
return CursorNode(nothing, nothing, CursorData(source, raw, byte_end, index, index_nt, val))
4141
else
4242
cs = CursorNode[]
4343
pos = position
@@ -47,7 +47,7 @@ function _to_CursorNode(source::SourceFile, txtbuf::Vector{UInt8}, offset::Int,
4747
pos += Int(rawchild.span)
4848
i_nt += !is_trivia(rawchild)
4949
end
50-
node = CursorNode(nothing, cs, CursorData(source, raw, position, index, index_nt, nothing))
50+
node = CursorNode(nothing, cs, CursorData(source, raw, byte_end, index, index_nt, nothing))
5151
for c in cs
5252
c.parent = node
5353
end
@@ -65,16 +65,14 @@ end
6565
Base.show(io::IO, node::CursorNode) = show(io, MIME("text/plain"), node.raw)
6666
Base.show(io::IO, mime::MIME{Symbol("text/plain")}, node::CursorNode) = show(io, mime, node.raw)
6767

68-
function Base.Expr(node::CursorNode)
69-
(; filename, first_line) = node.source
70-
src = SourceFile(node.source[byte_range(node)]; filename, first_line)
71-
Expr(SyntaxNode(src, node.raw))
72-
end
68+
Base.JuliaSyntax._expr_leaf_val(node::CursorNode, _...) = node.val
69+
Base.Expr(node::CursorNode) = Base.JuliaSyntax.to_expr(node)
7370

74-
char_range(node) = node.position:char_last(node)
75-
char_last(node) = thisind(node.source, node.position + span(node) - 1)
71+
char_range(node::CursorNode) = char_first(node):char_last(node)
72+
char_first(node::CursorNode) = Int(node.byte_end) - Int(node.raw.span) + 1
73+
char_last(node::CursorNode) = thisind(node.source, node.byte_end)
7674

77-
children_nt(node) = [n for n in children(node) if !is_trivia(n)]
75+
children_nt(node::CursorNode) = [n for n in children(node) if !is_trivia(n)]
7876

7977
function seek_pos(node, pos)
8078
pos in byte_range(node) || return nothing
@@ -97,13 +95,13 @@ end
9795
# Return the character range between left_kind and right_kind in node. The left
9896
# delimiter must be present, while the range will extend to the rest of the node
9997
# if the right delimiter is missing.
100-
function find_delim(node, left_kind, right_kind)
98+
function find_delim(node::CursorNode, left_kind::Kind, right_kind::Kind)
10199
cs = children(node)
102100
left = findfirst(c -> kind(c) == left_kind, cs)
103101
left !== nothing || return nothing, nothing
104102
right = findlast(c -> kind(c) == right_kind, cs)
105103
closed = right !== nothing && right != left
106-
right = closed ? thisind(node.source, cs[right].position - 1) : char_last(node)
104+
right = closed ? thisind(node.source, char_first(cs[right]) - 1) : char_last(node)
107105
left = nextind(node.source, char_last(cs[left]))
108106
return left:right, closed
109107
end

0 commit comments

Comments
 (0)