merlin icon indicating copy to clipboard operation
merlin copied to clipboard

Support "Find occurrences" at whole project scale, not just inside the current file

Open UnixJunkie opened this issue 10 years ago • 12 comments

merlin-locate is project-wise merlin-occurrences is just current-buffer Can't we have a merlin-occurrences that is project-wise?

UnixJunkie avatar Mar 20 '15 17:03 UnixJunkie

I started work on this a few weeks ago, but I don't have time for it right now… I hope to release it in a few more weeks.

let-def avatar Mar 20 '15 17:03 let-def

Thanks! :+1:

UnixJunkie avatar Mar 20 '15 17:03 UnixJunkie

Hi,

I feel always a bit bad when reviving a 4 year old issue 😅 but I found this issue while looking for a way to find project-wise occurrences (currently limited to the current file).

The issue https://github.com/ocaml/merlin/issues/156 is kind of misleading, one has to read carefully through the thread to understand it only works in the current file.

I propose this issue is renamed to better reflect the feature request: Support "Find occurrences" in the project, not just in the current file. What do you think?


6 years later, does someone have any idea if this feature is:

  • feasible?
  • easy or difficult to implement?

I have the secret (though probably unrealistic 😁 ) hope that current knowledge would make this implementation easier than it was back then 🤞

As a recent OCaml developer, this would be an amazing feature to work on medium to large projects (where grepping gives too many false-positives) 🙏

Project-wise renaming would be the cherry on top, but finding occurrences alone would be an amazing step forward already.

sir4ur0n avatar Feb 24 '21 23:02 sir4ur0n

@Sir4ur0n there is ocp-grep, if you are really dying for something.

UnixJunkie avatar Feb 25 '21 01:02 UnixJunkie

So I gave a serious shot to ocp-grep, thanks for mentioning that @UnixJunkie , I wasn't aware of it!

Unfortunately there are several shortcomings to this tool:

  • It seems to miss some occurrences (returns less than all valid occurrences)
  • I could not make it work to find occurrences of operators (but maybe it's possible)
  • The Emacs command tries to find the identifier at point to pass it to ocp-grep, unfortunately it fails on 90% of my tries, and I have to manually find and type the identifier myself.
  • I hoped I could compose it with some Merlin command to get the identifier at point, unfortunately the Merlin API provides no such thing.
  • Merely no documentation (or I miserably failed to find it)

I don't mean to be unfair to ocp-grep (nor its maintainers) though: when it works, it works rather well, this is a net improvement over the current status quo of grepping an OCaml codebase as it removes many false positives in the result list.

As Merlin seems to be the standard OCaml development tool, I think it would make sense to add this "Find occurrences" feature.

What do the maintainers think about this?

  • "Makes sense, we will work on it (assuming we have time, etc.) / are already working on it"
  • "Makes sense, but we don't have time/energy/motivation/other to do it ourselves. Contributions are welcome though" (in that case, could we get pointers please?)
  • "No, this is a bad idea/doesn't make sense (in Merlin) because ..."
  • Other

I just want to thank again the maintainers because what Merlin currently does, it does really well (I am often baffled by how well it keeps working below lines that don't compile) 🙇

sir4ur0n avatar Mar 04 '21 21:03 sir4ur0n

Re: find occurrences in merlin

I was recently onboarded to work on editor experience for OCaml projects. I find "occurrences" as important as you do especially when working with new projects. There are some other tasks that I will need to complete before however, including work on other aspects of occurrences.

So, if you want the feature asap and anyone wants to point you in the right direction (I can't since I'm new to merlin codebase myself), then it may be indeed a good idea to give it a try yourself.

ulugbekna avatar Mar 05 '21 04:03 ulugbekna

Hi,

The answer is definitely "Makes sense, we will work on it (assuming we have time, etc.) / are already working on it" :)

Historically Merlin has been supporting a wide range of versions and this has made this kind of feature difficult to support. Now that a given version of merlin only support the latest compiler, it can leverage more precise compiler information.

For example, finding where a value comes from can be a tricky question to define. It used to be tracked by source location, but this is not always a 1:1 mapping (for example with generated code). With things like https://github.com/ocaml/ocaml/pull/8934 merged in the compiler it means that merlin can have a more precise view of how definitions, declarations and usage are linked.

All of these features (more precise jumps, cross-module uses, better renaming) are on merlin's roadmap so you should be able to see some improvements later this year.

emillon avatar Mar 29 '21 09:03 emillon

Any progress?

HyunggyuJang avatar Apr 15 '22 11:04 HyunggyuJang

Yes, we've progressed by at least one more (significant) step with some recent changes that were made to the compiler ( https://github.com/ocaml/ocaml/blob/trunk/Changes#L658 ).

At this point everything we would need from the compiler for a project-wide "find occurences" functionality is present in 4.14. What we need is to build the actual tooling around it; which implies merlin but also some cooperation from dune and other build systems. @voodoos has started working on this recently.

We have no ETA for the finished feature yet, but the work is progressing steadily.

trefis avatar Apr 15 '22 15:04 trefis

The ability to search for occurrences of a symbol across a project is very useful.

I was wondering if any more progress had been made on this @voodoos @trefis

I am willing to work on this feature to make it happen. However, I don't know Merlin internals but I'm willing to learn. Let me know if it would be efficient to be guided to build this feature and I can volunteer.

sidkshatriya avatar Nov 04 '22 21:11 sidkshatriya

I was wondering if any more progress had been made on this @voodoos @trefis

Yes, it is actually in the works :-) Your testing will be very much welcome when we will have our first prototype !

voodoos avatar Nov 06 '22 11:11 voodoos

Very exciting!

If there is a public branch available to check this out do let us know :-) !

sidkshatriya avatar Nov 06 '22 13:11 sidkshatriya