ocaml-community / utop

Universal toplevel for OCaml
Other
844 stars 112 forks source link

Fix completion of symbols in modules #468

Open steffenhaug opened 10 months ago

steffenhaug commented 10 months ago

Fixes #455

The reason you don't get a completion when typing a symbol in a module, is because the range from utop-prompt-max to (point) does not match the actual prefix of the completion returned from utop. The fix is to set the start and end positions of the completion corresponding to the position of the prefix utop is actually completing.

Before, there was a fix that attempted to fix the same thing with some special logic in the processing of the lines returned from utop, but using the cadr of the split string will not work with more than one level of modules, and even then the range of the completion was not set correctly, leading to the issue. With this fix, we can complete things like List.<TAB>, and even Base.Float.O.<TAB>.

There might be a better way to determine the completion prefix; I'm not experienced enough with OCaml to know if splitting by . covers finding the prefix for everything that utop can autocomplete, but at least it is a start.

I'm also not the most experienced elisp hacker, so if the code is in bad style or there is something I have overlooked, feel free to make suggestions as to how I can improve the fix.