uptech / alt Goto Github PK
View Code? Open in Web Editor NEWCommand line tool to find alternate files
License: MIT License
Command line tool to find alternate files
License: MIT License
I think it'd be beneficial to craft a nice vim script (which I suppose would be a plugin) for this.
I'm sure there are other things people would like, but the one that's bothering me at the moment is:
:edit
to open it (this would preserve location in the file)This is more like a question than an issue regarding the path of this project. I think it would also be useful to get alternatives to .html / .ts / .scss files for Angular development, or similar couplings for other projects.
Current the way of handling alternatives does not allow this, do you think it would be helpful to have 'switching patterns' and get those different patterns in some order so editors can swap them?
For example calling alt with alt --angular
would swpa foo.html , foo.ts and foo.scss, or alt --react
would suggest foo.jsx or foo.css . Or even alt --c
would swap foo.c and includes/foo.h ... even more alt --no-file-check feature so editor can create this file if it does not exists.
alt
currently uses fuzzy-based searching based on the filename with scoring. Some languages, like Elixir [1], have conventions for test file locations. What if there was introduced other heuristics? E.g. if an exact match—based on a language's conventions—exists, then return that.
Implementation wise it could be as simple as checking if the file exists, which I can't imagine lowering performance. If anything, this fast return could increase performance as it could skip the fuzzy-based searching since an exact known match was found.
If so, would you be open to a PR that implements this?
The motivation for this was that I wanted to (optionally) create a test file if it didn't already exist when I try and use alt
. If the "known file by convention" heuristic was there, then I could do that.
[1] /lib/animal/giraffes/giraffe.ex
→ /test/animal/giraffes/giraffe_test.exs
It'd be nice to be able to know why it does (or doesn't) work in various "in the field" scenarios.
At this time the following are the known use cases that we want to support.
features/project_management.feature <=> features/step_definitions/project_management_steps.rb
spec/foo/bar/jacked_spec.js <=> foo/bar/jacked.js
test/lib/my_awesome_app/supervisor_test.exs <=> lib/my_awesome_app/supervisor.ex
spec/web/controllers/users/create_spec.rb <=> apps/web/controllers/users/create.rb
spec/web/views/users/create_spec.rb <=> apps/web/views/users/create.rb
spec/foo/bar/car/my_lib_spec.rb <=> lib/foo/bar/car/my_lib.rb
spec/offer_service/fulfiller_spec.rb <=> apps/offer_service/fulfiller.rb
spec/controllers/users/create_spec.rb <=> app/controllers/users/create.rb
spec/views/users/create_spec.rb <=> app/views/users/create.rb
spec/foo/bar/car/my_lib_spec.rb <=> lib/foo/bar/car/my_lib.rb
spec/fulfiller_spec.rb <=> app/fulfiller.rb
spec/controllers/tasks_controller_spec.rb <=> app/controllers/tasks_controller.rb
spec/models/task_spec.rb <=> app/models/task.rb
spec/helpers/hoopty_spec.rb <=> app/helpers/hoopty.rb
spec/mailers/hoopty_mailer_spec.rb <=> app/mailers/hoopty_mailer.rb
spec/foo_spec.rb <=> lib/foo.rb
spec/bar/foo_rake_spec.rb <=> bar/foo.rake
spec/foo_spec.rb <=> lib/foo.rb
After some relatively light research it seems that there are three primary string pattern matching algorithms for the scenario of variable pattern & variable text. They are listed below with their various ~ complexities based on my research.
Based on my initial research, ignoring the fact that we are dealing with paths not just normal strings, it seems that KMP is probably the best option for efficiently finding an exact pattern match in some text.
I started building an Atom package a while back, but have since switched to VS Code as my primary editor (for non-JVM projects).
I'm volunteering myself to write a VS Code extension ✋
Would you consider providing binary releases on github or maybe a bottled version of the tap?
Firstly, thank you for making this.
With alt 3.1.0, installed through Homebrew on macOS, no alternative files are being found for Go tests. E.g. if I have main.go
and main_test.go
(same directory), I expect the _test.go
file to be found.
When using in a monorepo (example Lerna), if you run alt from root of the repo, alt is not working.
You need to go the first to one of the package folder
// repo tree example
├── package.json (private module)
├── packages/
│ ├── module1/
│ │ ├── package.json (module)
│ │ ├── src/
│ │ ├── tests/
│ ├── module2/
│ │ ├── package.json (module)
│ │ ├── src/
│ │ ├── tests/
Let's say I'm in Vim, editing app/lib/hashing.py
.
app/lib/hashing_test.py
does not exist, but I'd like to work on the tests.
Yet this command returns nothing:
$ alt app/lib/hashing.py
I'd be expecting (provided there are some other tests in the repo):
$ alt app/lib/hashing.py
app/lib/hashing_test.py
Any plan to support alternate of C/C++ source code - header files?
E.g.:
$ alt ./foo/bar/faz.c
./foo/bar/faz.h
$ alt ./fizz/bang.hpp
./fizz/bang.cpp
It would be really cool to have a Neovim plugin for Alt that handled installation and updating of the binary or even just provided a basic configuration API in Lua and displayed a warning message if it's not installed!
I've been using other.nvim because it provides nice built in commands that I can set keybindings to, but it's not as good at finding alternate files and it's a bit slower. I'd love to switch back to Alt, but having a separate config for it outside of my lazy.nvim config bugs me.
New scenario here where Alt cannot find the alternate:
File exists at lib/tasks/something.rake
Test file exists at spec/lib/tasks/something_rake_spec.rb
From something.rake
, alt finds the spec file, but from the spec file it cannot find an alternate.
Here's the debug output:
Rake file:
$ alt --debug lib/tasks/intercom.rake
0.08695652173913043: lib/tasks/intercom.rake - spec/controllers/intercom_proxy_controller_spec.rb
0.08804347826086957: lib/tasks/intercom.rake - spec/lib/intercom/batch_enqueuer_spec.rb
0.09518213866039954: lib/tasks/intercom.rake - spec/lib/intercom/bulk_pusher_spec.rb
0.11360448807854139: lib/tasks/intercom.rake - spec/lib/intercom/leads_spec.rb
0.07012622720897616: lib/tasks/intercom.rake - spec/lib/notification_preferences/intercom_preferences_spec.rb
0.391304347826087: lib/tasks/intercom.rake - spec/lib/tasks/intercom_rake_spec.rb
0.11148272017837234: lib/tasks/intercom.rake - spec/queues/intercom/push_batch_spec.rb
path to find alternate for: lib/tasks/intercom.rake
# possible alternate paths: 3100
# filtered possible alternate paths: 7
highest_score: 0.391304347826087
highest_scored_poss_alt_path: spec/lib/tasks/intercom_rake_spec.rb
spec/lib/tasks/intercom_rake_spec.rb
Test file:
alt --debug spec/lib/tasks/intercom_rake_spec.rb
path to find alternate for: spec/lib/tasks/intercom_rake_spec.rb
# possible alternate paths: 3100
# filtered possible alternate paths: 0
highest_score: 0
highest_scored_poss_alt_path:
The reasoning is fairly obvious, it's just because the spec/implementation file names aren't similar enough, or are just kind of structured differently... In any case, it could be a simple matter of adding an exception, but I'm wondering if there's a smarter way to solve it.
I was kind of surprised it couldn't find a possible alternate path to search though... does that make sense to anyone else?
The readme should be more clear what "alternate path" means. Is it the location of a duplicate file? Is it a suggested place to put the file instead of its current location? Or is it maybe something else?
AutomotiveTests/Vehicles/VehicleAttributesVehicleSpec.swift <=> Automotive/Vehicles/VehicleAttributesVehicle.swift
AutomotiveTests/Vehicles/VehicleAttributesVehicleTests.swift <=> Automotive/Vehicles/VehicleAttributesVehicle.swift
AutomotiveUITests/Vehicles/VehicleAttributesVehicleUITests.swift <=> Automotive/Vehicles/VehicleAttributesVehicle.swift
AutomotiveUITests/Vehicles/VehicleAttributesVehicleUISpec.swift <=> Automotive/Vehicles/VehicleAttributesVehicle.swift
I'm surprised to see that this doesn't work:
alt ./crypto-helpers.test.js
I would expect discovery of:
./crypto-helpers.js
... and vise-versa.
As a fast in memory index consider using Finite State Transducer to find alternative paths
and index the project once when loading the project.
More info
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.