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

add ranked suggestions to add error #2985

Merged
merged 5 commits into from
Feb 14, 2022

Conversation

IanButterworth
Copy link
Sponsor Member

@IanButterworth IanButterworth commented Feb 13, 2022

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.

Screen Shot 2022-02-13 at 3 51 00 PM

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

julia> @time try Pkg.add("Image"); catch  end
  0.009007 seconds (23.61 k allocations: 2.039 MiB)

julia> @time try Pkg.add("Image"); catch  end
  0.008462 seconds (23.62 k allocations: 2.040 MiB)

this PR

julia> @time try Pkg.add("Image"); catch end
  0.027184 seconds (101.59 k allocations: 13.357 MiB)

julia> @time try Pkg.add("Image"); catch end
  0.044085 seconds (101.59 k allocations: 13.357 MiB, 22.40% gc time)

julia> @time try Pkg.add("Image"); catch end
  0.026322 seconds (101.59 k allocations: 13.356 MiB)

Closes #2911

test/new.jl Outdated Show resolved Hide resolved
@IanButterworth
Copy link
Sponsor Member Author

Let's merge to get people trying this out in the first 1.8 cut

@IanButterworth IanButterworth merged commit fd26a6b into JuliaLang:master Feb 14, 2022
@IanButterworth IanButterworth deleted the ib/add_suggestions branch February 14, 2022 22:54
Comment on lines +940 to +943
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
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest nearby (& popular?) package when name not found
3 participants