Skip to content

Commit 7a94011

Browse files
committed
strip trailing dots
1 parent 5538ffe commit 7a94011

3 files changed

Lines changed: 43 additions & 15 deletions

File tree

src/datatip.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@ Once we can come to handle links within datatips, we may want to append method t
77
handle("datatip") do data
88
@destruct [
99
word,
10+
fullWord,
1011
mod || "Main",
1112
path || "",
1213
column || 1,
1314
row || 1,
1415
startRow || 0,
1516
context || ""
1617
] = data
17-
datatip(word, mod, path, column, row, startRow, context)
18+
datatip(word, fullWord, mod, path, column, row, startRow, context)
1819
end
1920

20-
function datatip(word, mod, path, column = 1, row = 1, startrow = 0, context = "")
21+
function datatip(word, fullword, mod, path, column = 1, row = 1, startrow = 0, context = "")
2122
if isdebugging() && (ddt = JunoDebugger.datatip(word, path, row, column)) !== nothing
2223
return Dict(:error => false, :strings => ddt)
2324
end
2425

25-
ldt = localdatatip(word, column, row, startrow, context)
26-
isempty(ldt) || return datatip(ldt)
26+
ldt = localdatatip(fullword, column, row, startrow, context)
27+
isempty(ldt) || return push!(datatip(ldt), :local => true)
2728

28-
tdt = topleveldatatip(mod, word)
29+
tdt = globaldatatip(mod, word, fullword)
2930
tdt !== nothing && return Dict(:error => false, :strings => tdt)
3031

3132
return Dict(:error => true) # nothing hits
@@ -35,8 +36,8 @@ datatip(dt::Vector{Dict{Symbol, Any}}) = Dict(:error => false, :strings => dt)
3536
datatip(dt::Int) = Dict(:error => false, :line => dt)
3637
datatip(dt::Vector{Int}) = datatip(dt[1])
3738

38-
function localdatatip(word, column, row, startrow, context)
39-
word = first(split(word, '.')) # ignore dot accessors
39+
function localdatatip(fullword, column, row, startrow, context)
40+
word = first(split(fullword, '.')) # always ignore dot accessors
4041
position = row - startrow
4142
ls = locals(context, position, column)
4243
filter!(ls) do l
@@ -56,7 +57,9 @@ function localdatatip(l, word, startrow)
5657
end
5758
end
5859

59-
function topleveldatatip(mod, word)
60+
function globaldatatip(mod, word, fullword)
61+
word = striptrailingdots(word, fullword)
62+
6063
docs = @errs getdocs(mod, word)
6164
docs isa EvalError && return nothing
6265

src/goto.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using CSTParser
33
handle("gotosymbol") do data
44
@destruct [
55
word,
6+
fullWord,
67
path || nothing,
78
# local context
89
column || 1,
@@ -15,29 +16,30 @@ handle("gotosymbol") do data
1516
text || "",
1617
] = data
1718
gotosymbol(
18-
word, path,
19+
word, fullWord, path,
1920
column, row, startRow, context, onlyGlobal,
2021
mod, text
2122
)
2223
end
2324

2425
function gotosymbol(
25-
word, path = nothing,
26+
word, fullword, path = nothing,
2627
column = 1, row = 1, startrow = 0, context = "", onlyglobal = false,
2728
mod = "Main", text = ""
2829
)
2930
try
3031
# local goto
3132
if !onlyglobal
32-
localitems = localgotoitem(word, path, column, row, startrow, context)
33+
localitems = localgotoitem(fullword, path, column, row, startrow, context)
3334
isempty(localitems) || return Dict(
3435
:error => false,
3536
:items => map(Dict, localitems),
37+
:local => true
3638
)
3739
end
3840

3941
# global goto
40-
globalitems = globalgotoitems(word, mod, text, path)
42+
globalitems = globalgotoitems(word, fullword, mod, text, path)
4143
isempty(globalitems) || return Dict(
4244
:error => false,
4345
:items => map(Dict, globalitems),
@@ -65,8 +67,8 @@ Dict(gotoitem::GotoItem) = Dict(
6567

6668
### local goto
6769

68-
function localgotoitem(word, path, column, row, startrow, context)
69-
word = first(split(word, '.')) # ignore dot accessors
70+
function localgotoitem(fullword, path, column, row, startrow, context)
71+
word = first(split(fullword, '.')) # always ignore dot accessors
7072
position = row - startrow
7173
ls = locals(context, position, column)
7274
filter!(ls) do l
@@ -83,12 +85,14 @@ localgotoitem(word, ::Nothing, column, row, startrow, context) = [] # when `path
8385

8486
### global goto - bundles toplevel gotos & method gotos
8587

86-
function globalgotoitems(word, mod, text, path)
88+
function globalgotoitems(word, fullword, mod, text, path)
8789
mod = getmodule(mod)
8890

8991
moduleitems = modulegotoitems(word, mod)
9092
isempty(moduleitems) || return moduleitems
9193

94+
word = striptrailingdots(word, fullword)
95+
9296
toplevelitems = toplevelgotoitems(word, mod, text, path)
9397

9498
# only append methods that are not caught by `toplevelgotoitems`

src/utils.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ function md_hlines(md)
9999
return MD(v)
100100
end
101101

102+
"""
103+
strlimit(str::AbstractString, limit::Int = 30, ellipsis::AbstractString = "…")
104+
105+
Chops off `str` so that its _length_ doesn't exceed `limit`. The excessive part
106+
will be replaced by `ellipsis`.
107+
108+
!!! note
109+
The length of returned string will _never_ exceed `limit`.
110+
"""
102111
function strlimit(str::AbstractString, limit::Int = 30, ellipsis::AbstractString = "")
103112
will_append = length(str) > limit
104113

@@ -118,6 +127,18 @@ end
118127

119128
shortstr(val) = strlimit(string(val), 20)
120129

130+
"""
131+
striptrailingdots(word::AbstractString, fullword::AbstractString)
132+
133+
Strips all the dot-accessors after `word` in `fullword`.
134+
"""
135+
function striptrailingdots(word::AbstractString, fullword::AbstractString)
136+
words = split(fullword, '.')
137+
ind = findfirst(w -> w == word, words)
138+
ind === nothing && return word # invalid case
139+
return join(words[1:ind], '.')
140+
end
141+
121142
# singleton type for undefined values
122143
struct Undefined end
123144

0 commit comments

Comments
 (0)