Skip to content

Commit

Permalink
improve str macro doc help (JuliaLang#39110)
Browse files Browse the repository at this point in the history
* improve str macro doc help

* add string macro search result
  • Loading branch information
Moelf authored Apr 2, 2022
1 parent 020c2de commit 8823058
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,19 @@ accessible(mod::Module) =
map(names, moduleusings(mod))...;
collect(keys(Base.Docs.keywords))] |> unique |> filtervalid

doc_completions(name) = fuzzysort(name, accessible(Main))
function doc_completions(name)
res = fuzzysort(name, accessible(Main))

# to insert an entry like `raw""` for `"@raw_str"` in `res`
ms = match.(r"^@(.*?)_str$", res)
idxs = findall(!isnothing, ms)

# avoid messing up the order while inserting
for i in reverse(idxs)
insert!(res, i, "$(only(ms[i].captures))\"\"")
end
res
end
doc_completions(name::Symbol) = doc_completions(string(name))


Expand Down
8 changes: 8 additions & 0 deletions stdlib/REPL/test/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ end
@test REPL.insert_hlines(IOBuffer(), nothing) === nothing
end

@testset "Check @var_str also completes to var\"\" in REPL.doc_completions()" begin
checks = ["var", "raw", "r"]
symbols = "@" .* checks .* "_str"
results = checks .* "\"\""
for (i,r) in zip(symbols,results)
@test r REPL.doc_completions(i)
end
end
@testset "fuzzy score" begin
# https://github.com/JunoLab/FuzzyCompletions.jl/issues/7
# shouldn't throw when there is a space in a middle of query
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using REPL
@testset "Check symbols previously not shown by REPL.doc_completions()" begin
symbols = ["?","=","[]","[","]","{}","{","}",";","","'","&&","||","julia","Julia","new","@var_str"]
for i in symbols
@test REPL.doc_completions(i)[1]==i
@test i REPL.doc_completions(i)
end
end
let ex = quote
Expand Down

0 comments on commit 8823058

Please sign in to comment.