nixprime / cpsm

A CtrlP matcher, specialized for paths.
Apache License 2.0
202 stars 19 forks source link

Treat underscore as word/path-segment separator? #41

Open matthewd opened 6 years ago

matthewd commented 6 years ago

Starting from activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, I typed pool.

I wanted to find activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, but the top results were:

> activerecord/test/cases/pooled_connections_test.rb
> activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
> activerecord/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb
> activestorage/test/controllers/previews_controller_test.rb
> activestorage/app/controllers/active_storage/previews_controller.rb
> actionview/test/fixtures/actionpack/test/potential_conflicts.erb
> actionpack/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb
> activesupport/lib/active_support/core_ext/range/overlaps.rb
> actionpack/test/fixtures/public/foo/other-index.html
> actionpack/test/fixtures/公共/foo/other-index.html
> railties/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt
> activesupport/lib/active_support/logger.rb

The first match does contain a contiguous pool at the start of the filename, so it's not unreasonable that it came first. And the second has a split prefix match for po*/o*/l*. But the rest are pretty spread-out arbitrary single-letter substring matches.

Given the path similarity, I expected my target to be at the top of the list, followed by activerecord/lib/active_record/connection_adapters/statement_pool.rb (shorter, but no abstract).

cp and spoo are sufficient to get those two files, respectively, to the top while using their first character.

I know different people/projects use underscores (and similar characters) in different ways, and sometimes treating it as a full word separator equal to / could give equally surprising results in the opposite direction. Perhaps the list of separators could be configurable?


:heart: :green_heart: :blue_heart: :yellow_heart: :purple_heart:

Thanks so much for cpsm! Its match quality has completely changed my mind about the usefulness of fuzzy finders -- and it's only because of that "always knows what I mean" awesomeness that I'm opening this issue to report where it's tripped me up.

nixprime commented 6 years ago

_ is actually recognized as a word separator, which is why cp and spoo work. The problem is that cpsm isn't very good at matching queries that don't at least match at the beginning of the basename, because in the current implementation word matching is a bit of hack to prevent matching from being exponential-time in the length of the query. I have some ideas on how to improve this, but it'll probably involve another matcher redesign.