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

Multiple alternatives based on framework/language #25

Open
bariscicek opened this issue Jan 27, 2019 · 7 comments
Open

Multiple alternatives based on framework/language #25

bariscicek opened this issue Jan 27, 2019 · 7 comments

Comments

@bariscicek
Copy link

bariscicek commented Jan 27, 2019

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.

@gugahoa
Copy link

gugahoa commented Mar 31, 2019

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.

@drewdeponte
Copy link
Owner

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
Copy link
Owner

drewdeponte commented Apr 15, 2019

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.

@gugahoa
Copy link

gugahoa commented Apr 15, 2019

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

@drewdeponte
Copy link
Owner

@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
Copy link
Owner

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
Copy link
Owner

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

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

No branches or pull requests

3 participants