Skip to content

Commit 5d8b703

Browse files
committed
strip trailing dots in frontend
1 parent f096f31 commit 5d8b703

6 files changed

Lines changed: 24 additions & 75 deletions

File tree

src/datatip.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@ atom-ide-ui is already deprecated, ugly, not fully functional, and and...
66
handle("datatip") do data
77
@destruct [
88
word,
9-
fullWord,
109
mod || "Main",
1110
path || "",
1211
column || 1,
1312
row || 1,
1413
startRow || 0,
1514
context || ""
1615
] = data
17-
datatip(word, fullWord, mod, path, column, row, startRow, context)
16+
datatip(word, mod, path, column, row, startRow, context)
1817
end
1918

20-
function datatip(word, fullword, mod, path, column = 1, row = 1, startrow = 0, context = "")
19+
function datatip(word, mod, path, column = 1, row = 1, startrow = 0, context = "")
2120
if isdebugging() && (ddt = JunoDebugger.datatip(word, path, row, column)) !== nothing
2221
return Dict(:error => false, :strings => ddt)
2322
end
2423

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

28-
tdt = globaldatatip(mod, word, fullword)
27+
tdt = globaldatatip(mod, word)
2928
tdt !== nothing && return Dict(:error => false, :strings => tdt)
3029

3130
return Dict(:error => true) # nothing hits
@@ -35,8 +34,8 @@ datatip(dt::Vector{Dict{Symbol, Any}}) = Dict(:error => false, :strings => dt)
3534
datatip(dt::Int) = Dict(:error => false, :line => dt)
3635
datatip(dt::Vector{Int}) = datatip(dt[1])
3736

38-
function localdatatip(fullword, column, row, startrow, context)
39-
word = first(split(fullword, '.')) # always ignore dot accessors
37+
function localdatatip(word, column, row, startrow, context)
38+
word = first(split(word, '.')) # always ignore dot accessors
4039
position = row - startrow
4140
ls = locals(context, position, column)
4241
filter!(ls) do l
@@ -56,9 +55,7 @@ function localdatatip(l, word, startrow)
5655
end
5756
end
5857

59-
function globaldatatip(mod, word, fullword)
60-
word = striptrailingdots(word, fullword)
61-
58+
function globaldatatip(mod, word)
6259
docs = @errs getdocs(mod, word)
6360
docs isa EvalError && return nothing
6461

src/goto.jl

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ using CSTParser
33
handle("gotosymbol") do data
44
@destruct [
55
word,
6-
fullWord,
76
path || nothing,
87
# local context
98
column || 1,
@@ -16,30 +15,29 @@ handle("gotosymbol") do data
1615
text || "",
1716
] = data
1817
gotosymbol(
19-
word, fullWord, path,
18+
word, path,
2019
column, row, startRow, context, onlyGlobal,
2120
mod, text
2221
)
2322
end
2423

2524
function gotosymbol(
26-
word, fullword, path = nothing,
25+
word, path = nothing,
2726
column = 1, row = 1, startrow = 0, context = "", onlyglobal = false,
2827
mod = "Main", text = ""
2928
)
3029
try
3130
# local goto
3231
if !onlyglobal
33-
localitems = localgotoitem(fullword, path, column, row, startrow, context)
32+
localitems = localgotoitem(word, path, column, row, startrow, context)
3433
isempty(localitems) || return Dict(
3534
:error => false,
36-
:items => map(Dict, localitems),
37-
:local => true
35+
:items => map(Dict, localitems)
3836
)
3937
end
4038

4139
# global goto
42-
globalitems = globalgotoitems(word, fullword, mod, text, path)
40+
globalitems = globalgotoitems(word, mod, text, path)
4341
isempty(globalitems) || return Dict(
4442
:error => false,
4543
:items => map(Dict, globalitems),
@@ -67,8 +65,8 @@ Dict(gotoitem::GotoItem) = Dict(
6765

6866
### local goto
6967

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

8684
### global goto - bundles toplevel gotos & method gotos
8785

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

9189
moduleitems = modulegotoitems(word, mod)
9290
isempty(moduleitems) || return moduleitems
9391

94-
word = striptrailingdots(word, fullword)
95-
9692
toplevelitems = toplevelgotoitems(word, mod, text, path)
9793

9894
# only append methods that are not caught by `toplevelgotoitems`
@@ -126,12 +122,11 @@ const SYMBOLSCACHE = Dict{String, PathItemsMaps}()
126122
function toplevelgotoitems(word, mod, text, path)
127123
# strip a dot-accessed module if exists
128124
identifiers = split(word, '.')
129-
head = identifiers[1]
130-
if head word && (val = getfield′(mod, string(head))) isa Module
125+
head = string(identifiers[1])
126+
if head word && getfield′(mod, head) isa Module
131127
# if `head` is a module, update `word` and `mod`
132128
nextword = join(identifiers[2:end], '.')
133-
nextmod = val
134-
return toplevelgotoitems(nextword, nextmod, text, path)
129+
return globalgotoitems(nextword, head, text, path)
135130
end
136131

137132
key = string(mod)

src/utils.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,10 @@ end
140140
shortstr(val) = strlimit(string(val), 20)
141141

142142
"""
143-
striptrailingdots(word::AbstractString, fullword::AbstractString)
143+
Undefined
144144
145-
Strips all the dot-accessors after `word` in `fullword`.
145+
singleton type representing undefined values
146146
"""
147-
function striptrailingdots(word::AbstractString, fullword::AbstractString)
148-
words = split(fullword, '.')
149-
ind = findfirst(w -> w == word, words)
150-
ind === nothing && return word # invalid case
151-
return join(words[1:ind], '.')
152-
end
153-
154-
# singleton type for undefined values
155147
struct Undefined end
156148

157149
# get utilities

test/datatip.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
datatipmethodtest() = nothing
8282
end
8383

84-
let datatip = globaldatatip("Main", "datatipmethodtest", "datatipmethodtest")
84+
let datatip = globaldatatip("Main", "datatipmethodtest")
8585
@test datatip isa Vector
8686
firsttip = datatip[1]
8787
secondtip = datatip[2]
@@ -94,16 +94,11 @@
9494
## variable datatip
9595
@eval Main datatipvariabletest = "this string should be shown in datatip"
9696

97-
let datatip = globaldatatip("Main", "datatipvariabletest", "datatipvariabletest")
97+
let datatip = globaldatatip("Main", "datatipvariabletest")
9898
@test datatip isa Vector
9999
firsttip = datatip[1]
100100
@test firsttip[:type] == :snippet
101101
@test occursin(r"this string should be shown in datatip", firsttip[:value])
102102
end
103-
104-
## strips training dots
105-
let item = globaldatatip("Atom", "SYMBOLSCACHE", "SYMBOLSCACHE")
106-
@test item == globaldatatip("Atom", "SYMBOLSCACHE", "SYMBOLSCACHE.keys")
107-
end
108103
end
109104
end

test/goto.jl

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@
195195
end
196196

197197
@testset "regenerating symbols" begin
198-
# @info "––– caching symbols in loaded modules (only errors shown) ------"
199-
# with_logger(ConsoleLogger(stderr, Base.CoreLogging.Warn)) do
200198
regeneratesymbols()
201-
# end
202-
# @info "––– finished caching -------------------------------------------"
203199

204200
@test haskey(SYMBOLSCACHE, "Base")
205201
@test length(keys(SYMBOLSCACHE["Base"])) > 100
@@ -244,21 +240,10 @@
244240
@testset "goto global symbols" begin
245241
# both the original methods and the toplevel bindings that are overloaded
246242
# in a context module should be shown
247-
let items = globalgotoitems("isconst", "isconst", "Main.Junk", "", nothing)
243+
let items = globalgotoitems("isconst", "Main.Junk", "", nothing)
248244
@test length(items) === 2
249245
@test "isconst(m::Module, s::Symbol)" map(item -> item.text, items) # from Base
250246
@test "Base.isconst(::JunkType)" map(item -> item.text, items) # from Junk
251247
end
252-
253-
# strips trailing dots
254-
let item = globalgotoitems("isconst", "isconst", "Main.Junk", "", nothing)
255-
@test item == globalgotoitems("isconst", "Junk.isconst", "Main.Junk", "", nothing)
256-
@test item == globalgotoitems("isconst", "Main.Junk.isconst", "Main.Junk", "", nothing)
257-
end
258-
let item = globalgotoitems("Junk", "Junk", "Main.Junk", "", nothing)
259-
@test item == globalgotoitems("Junk", "Main.Junk", "Main.Junk", "", nothing)
260-
@test item == globalgotoitems("Junk", "Junk.isconst", "Main.Junk", "", nothing)
261-
@test item == globalgotoitems("Junk", "Main.Junk.isconst", "Main.Junk", "", nothing)
262-
end
263248
end
264249
end

test/utils.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,3 @@ end
114114
@test strlimit("Jμλια in the Nutshell", 20, " ...") == "Jμλια in the Nut ..."
115115
end
116116
end
117-
118-
@testset "strip trailing dots" begin
119-
using Atom: striptrailingdots
120-
121-
# only including ASCII
122-
@test striptrailingdots("field", "Head.field") == "Head.field"
123-
@test striptrailingdots("Head", "Head.field") == "Head"
124-
125-
# including Unicode
126-
@test striptrailingdots("fιηλδ", "Hηαδ.fιηλδ") == "Hηαδ.fιηλδ"
127-
@test striptrailingdots("Hηαδ", "Hηαδ.fιηλδ") == "Hηαδ"
128-
129-
# invalid case
130-
@test_nowarn striptrailingdots("foo", "head.field")
131-
end

0 commit comments

Comments
 (0)