-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
add ranked suggestions to add
error
#2985
add ranked suggestions to add
error
#2985
Conversation
41533b5
to
0444922
Compare
0444922
to
81ad18b
Compare
Let's merge to get people trying this out in the first 1.8 cut |
function fuzzysort(search::String, candidates::Vector{String}) | ||
scores = map(cand -> (REPL.fuzzyscore(search, cand), -Float64(REPL.levenshtein(search, cand))), candidates) | ||
candidates[sortperm(scores)] |> reverse, any(s -> s[1] > 0, scores) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from Slack- it would be better to use REPL's levsort
instead (https://github.com/JuliaLang/julia/blob/f3e3554910a79fa38d5662d14abe04e137075e18/stdlib/REPL/src/docview.jl#L652-L660), which is what the REPL uses for corrections: https://github.com/JuliaLang/julia/blob/f3e3554910a79fa38d5662d14abe04e137075e18/stdlib/REPL/src/docview.jl#L700-L707.
This does a lot better on DifferentielEquations
:
julia> levsort("DifferentielEquations", all)
3-element Vector{String}:
"DifferentialEquations"
"DifferenceEquations"
"DifferentialEvolutionMCMC"
vs
julia> fuzzysort("DifferentielEquations", all)
(["DifferentialEvolutionMCMC", "DifferentialDynamicsModels", "DifferentiableStateSpaceModels", "DifferentialEquations", "SimpleDifferentialOperators", "DiscreteDifferentialGeometry", "DifferentialForms", "DifferentialDynamicProgramming", "DifferenceEquations", "AbstractDifferentiation" … "BenchmarkingEconomicEfficiency", "BayesianNonparametricStatistics", "ApproxFunOrthogonalPolynomials", "GAP_pkg_normalizinterface_jll", "ReinforcementLearningEnvironmentAtari", "MultivariateOrthogonalPolynomials", "BlackBoxOptimizationBenchmarking", "SemiclassicalOrthogonalPolynomials", "OpenTelemetryExporterOtlpProtoGrpc", "ReinforcementLearningEnvironmentClassicControl"], false)
When a package isn't found by name this adds a number of ranked matches (depending on the result scores and terminal width), via the same fuzzyscore search that
REPL
does for help mode.If there are no match scores above zero, no suggestions are shown.
It seems like the search could be improved in REPL because it's unfortunate that the diffeq spelling mistake isn't found.
Also the
fuzzysort
method tweak could be upstreamed.It adds a bit of slowness, but I think that's ok for this kind of user feedback (this is with 3 registries including General)
master
this PR
Closes #2911