alt icon indicating copy to clipboard operation
alt copied to clipboard

Multiple alternatives based on framework/language

Open bariscicek opened this issue 6 years ago • 7 comments

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.

bariscicek avatar Jan 27 '19 13:01 bariscicek

That seems interesting. I would like some feature like that too, which could be configured with a config file so that the codebase remains language/framework agnostic.

If there's interest from the authors, I would be more than happy to draft a feature proposal of how it could work, and implementing it.

gugahoa avatar Mar 31 '19 11:03 gugahoa

So, the original incarnation before alt existed was https://github.com/uptech/vim-open-alternate which had an implementation more along these lines.

Though, it continued to have maintenance issues because it turns out it is difficult to account for all the possible cases in your regex, lol. Also, I started running into issues where certain frameworks/languages were conflicting with others in terms of patterns and detection.

So, I built alt which is an attempt to generalize the problem and solve it by using an scoring algorithm based on similarity between paths. I eventually added some classification functionality again to optimize things but have been trying to avoid adding the switches to identify mode.

Maybe having the switches/modes would be fine though if we had a default (general mode), and then the switches.

drewdeponte avatar Apr 15 '19 07:04 drewdeponte

So, I was thinking about this more this morning and it now has me re-thinking the filter by classification strategy. I think a better strategy would be some sort of additial weighting system. Lets look at the following example:

File you are currently in:

foo/bar/car/house.js

Possible alternates:

foo/bar/car/house.test.js
foo/bar/car/house.css
foo/bar/car/house.html

Ignoring test classification and test word stripping. In the above case foo/bar/car/house.css and foo/bar/car/house.html would have the same score because it strips the extension before doing the similarity scoring. So one of these two would be the winner as house.test.js has an additional .test which makes its similiraty score worse.

However what we would want in this scenario probably for house.test.js to be the winner since logically it is an alternate for the house.js implementation file.

We could accomplish this by introducing a weighting system that improves the similarity score based on some heuristics. This could be based off the extension or based off other words found in the possible alternate path and filename.

drewdeponte avatar Apr 15 '19 15:04 drewdeponte

I'm playing around with an implementation of the same alt functionality here: https://github.com/gugahoa/fzf_alt

My bet was that fzf would sort the possible files list better than I would, and then I could just go through it with a regex to test for the test file.

I left the strip + test regex up to the user to configure, as that can have particularities that's up to the user.

I'm still playing around with how to implement how to alternate between things like house.js, house.css and house.html

gugahoa avatar Apr 15 '19 20:04 gugahoa

@gugahoa this project is actually based on the core of https://github.com/BurntSushi/ripgrep. Originally it wasn't but then I worked with ripgreps core dev to get the foundation of ripgrep integrated for the same reasons.

drewdeponte avatar Apr 15 '19 21:04 drewdeponte

Thinking about this more. I think having framework specific support probably isn't the correct approach. Instead I think it should instead maybe be the algo for identifying the alternate file.

Maybe there are different approaches

  • similarity
  • similarity w/ test filtering
  • etc.

drewdeponte avatar Jan 11 '22 05:01 drewdeponte

I just released v4.0.0 which has a more generalized algorithm that I think should aid with this.

drewdeponte avatar May 08 '23 04:05 drewdeponte