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

:MerlinOccurrencesProjectWide fails with KeyError #1832

Open
talex5 opened this issue Sep 21, 2024 · 2 comments
Open

:MerlinOccurrencesProjectWide fails with KeyError #1832

talex5 opened this issue Sep 21, 2024 · 2 comments
Labels

Comments

@talex5
Copy link

talex5 commented Sep 21, 2024

I tried using this new feature on Eio (e.g. on statx_works at https://github.com/ocaml-multicore/eio/blob/d2a3e21bc47dd7a6c482f4c61f9e00c1a39922a9/lib_eio_linux/sched.ml#L12; many other places fail too). I got:

Error detected while processing function merlin#OccurrencesProjectWide:
line    3:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/.opam/5.2.0-fp/share/merlin/vim/autoload/merlin.py", line 548, in vim_occurrences
    for pos in with_text_previews(lst):
  File "/home/user/.opam/5.2.0-fp/share/merlin/vim/autoload/merlin.py", line 536, in with_text_previews
    text = preview_lines_by_file[oc['file']][lnum]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
KeyError: 12 

preview_lines_by_file[oc['file']] has entries for 526 and 527 (the other two uses in the file), but not for 12 (the definition).

occurs = [
  {'file': '/home/user/work/eio/lib_eio_linux/sched.ml',
   'start': {'line': 12, 'col': 4},
   'end': {'line': 12, 'col': 15}},
  {'file': '/home/user/work/eio/lib_eio_linux/eio_linux.ml',
   'start': {'line': 421, 'col': 14},
   'end': {'line': 421, 'col': 25}},
  {'file': '/home/user/work/eio/lib_eio_linux/sched.ml',
   'start': {'line': 526, 'col': 14},
   'end': {'line': 526, 'col': 25}},
  {'file': '/home/user/work/eio/lib_eio_linux/sched.ml',
   'start': {'line': 527, 'col': 8},
   'end': {'line': 527, 'col': 19}}
]

The Python docs say:

Generally, the iterable needs to already be sorted on the same key function.

I tried adding this to the start of the function, and that seemed to fix it:

occurs.sort(key = lambda oc: oc.get('file'))
@voodoos
Copy link
Collaborator

voodoos commented Sep 23, 2024

Thanks for the report and investigation @talex5, I am not familiar with the vim implementation, so forwarding to @Julow

@Julow
Copy link
Contributor

Julow commented Sep 23, 2024

Indeed, that was a misunderstanding of how itertools.groupby works and sorting fixes it :) Could you open a PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants