Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve str macro doc help #39110

Merged
merged 4 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, this line had a trailing whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

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