fannheyward / coc-pyright

Pyright extension for coc.nvim
MIT License
1.27k stars 46 forks source link

Bad order of suggestions #704

Closed Rizhiy closed 2 years ago

Rizhiy commented 2 years ago

What's the output of :CocCommand pyright.version

[coc.nvim] coc-pyright 1.1.215 with Pyright 1.1.218

What's the output of :CocCommand workspace.showOutput Pyright

   22 Workspace: /home/rizhiy/projects/sp-earnings
   21 Using python from /home/rizhiy/miniconda3/envs/sp-earnings/bin/python
   20
   19 [Warn  - 3:34:49 AM] disableCompletion in the client options is deprecated. use disabledFeatures instead.
   18
   17     at new Zh (/home/rizhiy/.vim/plugged/coc.nvim/build/index.js:225:28036)
   16     at Object.activate (/home/rizhiy/.config/coc/extensions/node_modules/coc-pyright/lib/index.js:23470:18)
   15 [Warn  - 3:34:49 AM] disableDiagnostics in the client options is deprecated. use disabledFeatures instead.
   14
   13     at new Zh (/home/rizhiy/.vim/plugged/coc.nvim/build/index.js:225:28036)
   12     at Object.activate (/home/rizhiy/.config/coc/extensions/node_modules/coc-pyright/lib/index.js:23470:18)
   11 [Info  - 3:34:50 AM] Pyright language server 1.1.218 starting
   10 [Info  - 3:34:50 AM] Server root directory: /home/rizhiy/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
    9 [Info  - 3:34:50 AM] No configuration file found.
    8 [Info  - 3:34:50 AM] pyproject.toml file found at /home/rizhiy/projects/sp-earnings.
    7 [Info  - 3:34:50 AM] Setting pythonPath for service "sp-earnings": "/home/rizhiy/miniconda3/envs/sp-earnings/bin/python"
    6 [Info  - 3:34:50 AM] Loading pyproject.toml file at /home/rizhiy/projects/sp-earnings/pyproject.toml
    5 [Error  - 3:34:50 AM] Pyproject file "/home/rizhiy/projects/sp-earnings/pyproject.toml" is missing "[tool.pyright]" section.
    4 [Warn  - 3:34:50 AM] stubPath /home/rizhiy/projects/sp-earnings/typings is not a valid directory.
    3 [Info  - 3:34:50 AM] Assuming Python version 3.9
    2 [Info  - 3:34:50 AM] Assuming Python platform Linux
    1 [Info  - 3:34:50 AM] Searching for source files
  23  [Info  - 3:34:50 AM] Found 663 source files

Suggestions produced by coc-pyright seem to be in a strange order, for example: image

As you can see get_raw which is a public method is after __init__ and __setitem__ which are dunder methods.

I would like to have my attributes to be in the following order:

  1. Public
  2. Private
  3. Others

How can I accomplish this?

Extra info: I tried using AstroVim and I believe it also uses pyright on the backend. Suggestions given in its autocompletion are in correct order.

fannheyward commented 2 years ago

https://github.com/fannheyward/coc-pyright/pull/695 has improved this, please try v1.1.219.

Rizhiy commented 2 years ago

Hi, yes it is much better now. Although sorting once part of the name is given is still partially broken, e.g.:

image Here _wrapped should really be first one in the list.

image Here _set_register_base_class should probably be ahead of dunder methods.

I think the logic should be roughly as follows:

  1. Exact start matches sorted first by private level, then alphabetically
  2. Exact matches in the middle of name, sorted as before
  3. Fuzzy matches, sorted first by closeness, then as before.

Does JavaScript perhaps have a fuzzy matching package which has required functionality?

I will try make it work over the weekend, if no-one implements it by then.

tejasvi commented 2 years ago

_wrapped case is due to #649. _set_register_base_class is interesting since #695 sorts by the number of leading underscores. For pyright's default ordering just remove below lines. https://github.com/fannheyward/coc-pyright/blob/929c5f69eb234b6037bdcc5d844fd42275ba3ea5/src/index.ts#L131-L133

fannheyward commented 2 years ago

Try coc-pyright v1.1.220, the Pyright's sorting has improved a lot.

Rizhiy commented 2 years ago

v1.1.220 seems to work as desired, thank you.