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

Rope autoimport doesn't work and cause all completion to not function #503

Open
eyalk11 opened this issue Dec 25, 2023 · 16 comments
Open

Rope autoimport doesn't work and cause all completion to not function #503

eyalk11 opened this issue Dec 25, 2023 · 16 comments

Comments

@eyalk11
Copy link

eyalk11 commented Dec 25, 2023

I couldn't get autoimport to work. And when I try to enabled rope_autoimport, suddenly nothing works. It simply doesn't suggest anything (python).

version: 1.9.0

python-lsp-jsonrpc 1.1.2
python-lsp-server 1.9.0

require('lspconfig').pylsp.setup{
    capabilities = capabilities,
    on_attach = on_attach,
    settings =
    {
        pylsp = {
            plugins =
            {
                pycodestyle = {
                    enabled = false,
                    ignore = {'E225','E231'},
                },
                pydocstyle = {
                    enabled= false
                },
                pylint = { enabled = false },
                --rope = {enabled = true },
                rope_autoimport = {enabled = true, {code_actions = {enabled = true}}},
                jedi_symbols = { enabled = true, all_scopes = true, include_import_symbols = true},

            }
        }
    }
}

  sources = cmp.config.sources(
{
    {
    name = "dictionary",
    keyword_length = 2,
    priority=0.1
    },
    { name = 'buffer', priority = 1 },

    { name = 'ultisnips', priority= 3 }, -- For vsnip users.
    { name = 'nvim_lsp' , priority = 100}
    -- { name = 'luasnip' }, -- For luasnip users.
    -- { name = 'ultisnips' }, -- For ultisnips users.
    -- { name = 'snippy' }, -- For snippy users.
})


When I did enabled it, I see it found some options
But I couldn't see them in the menu.

2023-12-25 12:17:31,819 Jerusalem Standard Time - DEBUG - pylsp_jsonrpc.endpoint - Got result from synchronous request handler: {'isIncomplete': False, 'items': [{'label': 'nt', 'kind': 9, 'sortText': '[z00044', 'data': {'doc_uri': 'file:///C:/gitproj/Auto-GPT/autogpt/command_decorator.py'}, 'detail': '# Auto-Import\nimport nt', 'additionalTextEdits': [{'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 0, 'character': 0}}, 'newText': 'import nt\n'}]}, {'label': 'NEW_URL', 'kind': 6, 'sortText': '[z00070', 'data': {'doc_uri':  .... 


2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - pylsp.plugins.rope_autoimport - autoimport: searching for word: os
2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - parso.python.diff - diff parser start
2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - parso.python.diff - line_lengths old: 67; new: 67
2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - parso.python.diff - -> code[equal] old[1:31] new[1:31]
2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - parso.python.diff - copy old[1:4] new[1:4]
2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - parso.python.diff - parse_part from 5 to 7 (to 7 in part parser)
2023-12-25 12:10:09,508 Jerusalem Standard Time - DEBUG - parso.python.diff - parse_part from 8 to 8 (to 9 in part parser)
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - parso.python.diff - copy old[10:66] new[9:31]
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - parso.python.diff - -> code[replace] old[32:32] new[32:32]
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - parso.python.diff - parse_part from 32 to 32 (to 34 in part parser)
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - parso.python.diff - -> code[equal] old[33:67] new[33:67]
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - parso.python.diff - copy old[35:66] new[33:66]
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - parso.python.diff - diff parser end
2023-12-25 12:10:09,510 Jerusalem Standard Time - DEBUG - pylsp.plugins.rope_autoimport - [<Name full_name='__future__.annotations', description='instance annotations'>, <Name full_name='functools', description='module functools'>, <Name full_name='typing.TYPE_CHECKING', description='instance TYPE_CHECKING'>, <Name full_name='typing.Any', description='class Any'>, <Name full_name='typing.Callable', description='class Callable'>, <Name full_name='typing.Optional', description='class Optional'>, <Name full_name='typing.TypedDict', description='class TypedDict'>, <Name full_name='autogpt.core.planning.strategies.name_and_goals.NameAndGoals', description='class NameAndGoals'>, <Name full_name='autogpt.config.Config', description='class Config'>, <Name full_name='autogpt.models.command.Command', description='class Command'>, <Name full_name='autogpt.models.command.CommandParameter', description='class CommandParameter'>, <Name full_name='command_decorator.AUTO_GPT_COMMAND_IDENTIFIER', description='AUTO_GPT_COMMAND_IDENTIFIER = "auto_gpt_command"'>, <Name full_name='command_decorator.CommandParameterSpec', description='class CommandParameterSpec'>, <Name full_name='command_decorator.command', description='def command'>]
2023-12-25 12:10:10,019 Jerusalem Standard Time - DEBUG - pylsp.config.config -       pylsp_lint [hook]
          config: <pylsp.config.config.Config object at 0x00000227AA7006A0>
          workspace: <pylsp.workspace.Workspace object at 0x00000227AB2DB820>
          document: file:///C:/gitproj/Auto-GPT/autogpt/command_decorator.py
          is_saved: False

2023-12-25 12:10:10,023 Jerusalem Standard Time - DEBUG - pylsp_jsonrpc.endpoint - Sending request with id 1a3cf8b3-7575-4bc7-9942-db01eca38315: window/workDoneProgress/create {'token': 'd3b05aa0-eacd-484e-9e2d-f91e406c484b'}
2023-12-25 12:10:10,027 Jerusalem Standard Time - DEBUG - pylsp.config.config -       finish pylsp_completions --> [[{'label': 'os', 'kind': 9, 'sortText': '[z00063', 'data': {'doc_uri': 'file:///C:/gitproj/Auto-GPT/autogpt/command_decorator.py'}, 'detail': '# Auto-Import\nimport os', 'additionalTextEdits': [{'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 0, 'character': 0}}, 'newText': 'import os\n'}]}, {'label': 'OSPEED', 'kind': 6, 'sortText': '[z00092', 'data': {'doc_uri': 'file:///C:/gitproj/Auto-GPT/autogpt/command_decorator.py'}, 'detail': '# Auto-Import\nfrom tty import OSPEED', 'additionalTextEdits': [{'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 0, 'character': 0}}, 'newText': 'from tty import OSPEED\n'}]}, {'label': 'os', 'kind': 9, 'sortText': '[z00097', 'data': {'doc_uri': '......
2023-12-25 12:10:10,031 Jerusalem Standard Time - DEBUG - pylsp_jsonrpc.endpoint - Handling response from client {'jsonrpc': '2.0', 'result': None, 'id': '60d958d5-57a3-41cd-bd11-702dd12fd0e0'}
2023-12-25 12:10:10,031 Jerusalem Standard Time - DEBUG - pylsp_jsonrpc.endpoint - Received result for message 60d958d5-57a3-41cd-bd11-702dd12fd0e0: None

When I disable rope_autocomplete , it suddenly work (basic completion) .

Do you have an idea why? or direction?
Thanks

@eyalk11 eyalk11 changed the title Rope autoimport doesn't work and sometimes all completion is non-functioning Rope autoimport doesn't work and cause all completion to not function Dec 25, 2023
@eyalk11
Copy link
Author

eyalk11 commented Dec 25, 2023

lsprel.log
Since 12:40 until ~13:00 It didn't work at all. When I disabled the plugin (rope-autoimport), it suddenly worked (normal completion).

@eyalk11
Copy link
Author

eyalk11 commented Dec 25, 2023

It also seem that it doesn't send the full text I type often.

2023-12-25 12:44:12,290 Jerusalem Standard Time - DEBUG - pylsp.plugins.rope_autoimport - autoimport: searching for word: c

Though hard to be sure.

@tkrabel
Copy link
Contributor

tkrabel commented Dec 26, 2023

It's hard for me to understand what the issue here is. Can you Answer the following questions for clarity?

  1. What where you trying to do? Can you give an example?
  2. What did you expect?
  3. What did you see instead?

@eyalk11
Copy link
Author

eyalk11 commented Dec 31, 2023

  1. I am trying to get auto-import work. It doesn't work on any python file. When I enable auto-import plugin, I get no suggestions at all for anything. That is if I include this line:
                rope_autoimport = {enabled = true, {code_actions = {enabled = true}}}

2 and 3:
For example,
I type DataFrame, and get no suggestions. (Expect to see from pandas improt DataFrame).
I type os and get no suggestions.

In fact, I get no suggestions at all even for same file variables. Unless I disable auto-import. I tried 3 different installations of pylsp with different python versions.

What do you suggest to do?

The log seems to suggest some valid suggestions even as I don't see them.

PS

does it matter that python version that runs pylsp and python3_host are different?

@tkrabel
Copy link
Contributor

tkrabel commented Jan 2, 2024

Can you check again with the following setting:

                rope_autoimport = {enabled = true, {completions = {enabled = true}}}

Does that work?

@eyalk11
Copy link
Author

eyalk11 commented Jan 4, 2024

No, the entire plugin doesn't work in this case ( except diagnostics).

Maybe it is related?

I allowed both completion and code actions and for a sec it displayed the options.

2024-01-05 08:05:01,829 Jerusalem Standard Time - DEBUG - pylsp.plugins.rope_autoimport - autoimport: searching for word: DataFrame

I typed it at least 10 times, so I wonder why it only appeared once.
Then I was able to see code actions for a short while.

Out of desperation I improved the implantation of nvim-pymode to use sqllite db , and probably will include your great scoring method. But your implementation is better. I don't understand how it doesn't work no matter what I do.

@tkrabel
Copy link
Contributor

tkrabel commented Jan 5, 2024

Sorry to hear it still doesn’t work. Can you record your screen of the behavior? Everything just works fine on my end …

@eyalk11
Copy link
Author

eyalk11 commented Jan 5, 2024

https://drive.google.com/file/d/1XUNISIc83vcxI0R4CsR-NonNrJzvSP0A/view?usp=sharing

image

(Trying to add project root doesn't solve it)

@tkrabel-db
Copy link
Contributor

@eyalk11 from the video, it seems the LS is broken. E.g. in 0:23, on line 18, it says undefined name 'f', which doesn't make sense to me given the content of the line.

Do you get any LSP errors when doing that again?

@eyalk11
Copy link
Author

eyalk11 commented Jan 8, 2024

I think it is related to the autosave , so it recalled a former expression. As you could see, in the second half, it worked really fine.
I added the log . No errors.
try.log

@awalvie
Copy link

awalvie commented Mar 18, 2024

I have the same issue. When I enable rope_autoimport completions stop working.

@smartinellimarco
Copy link

smartinellimarco commented Mar 18, 2024

In my case, completions work but I dont see any coming for autoimports.
Nor the code actions.
I inspected the lsp settings in Mason and saw this:

        → pylsp.plugins.rope_autoimport.code_actions.enabled        default: true
        → pylsp.plugins.rope_autoimport.completions.enabled         default: true
        → pylsp.plugins.rope_autoimport.enabled                     default: false

with the following config:

    pylsp = {
      -- FIXME: does not work
      plugins = {
        rope_autoimport = { enabled = true, { completions = { enabled = true } } },
      },
    },

also, from LSP logs:
[ERROR][2024-03-18 14:22:31] .../vim/lsp/rpc.lua:734 "rpc" "/Users/marco/.local/share/nvim/mason/bin/pylsp" "stderr" "2024-03-18 14:22:31,650 -03 - WARNING - pylsp_jsonrpc.endpoint - Received cancel notification for unknown message id 84\n"

@HungryJoe
Copy link

I'm having the exact same issue described above. I don't see a bug-report template for this project, so I'll try and give all the context I think is relevant.

Context

  • OS: Darwin x86-64 (macOS 14.6.1)
  • Package manager: Nix home manager. python-lsp-server and deps, plus pylsp-rope and python-lsp-ruff, are installed via a dedicated 3.12.5 Python interpreter
  • python-lsp-server version 1.12.0
  • pylsp-rope version 0.1.16
  • python-lsp-ruff version 2.2.2
  • rope version 1.13.0
  • jedi version 0.19.1
  • Editor: Helix version 24.7 (079f5442)

Relevant Config: config-with-rope.txt
(See this repo for my full Helix config)

Here's a sample log file so that you can see that all plugins load successfully.

Steps to reproduce

  1. Open an existing Python file
  2. Type any symbol
  3. Type a symbol from an installed library that hasn't been imported

Expectation

Step (2) would cause an auto-complete window to show up.
Step (3) would cause an auto-complete window to show up that would auto-import the symbol on confirming it.

What happens instead

No auto-complete window shows up.

Misc Notes

When rope_autoimport and rope_completion are disabled, auto-completion works great, except that there's no auto-import and symbols from installed libraries that haven't been imported into the current file don't show up in the completion list. See config.txt for a sample configuration.

Also, disabling pylsp_rope doesn't help.

@eyalk11
Copy link
Author

eyalk11 commented Oct 10, 2024

So long and no solution.
Do you have different python versions installed? How did you install pylsp? (I ussd meson)

@HungryJoe
Copy link

HungryJoe commented Oct 14, 2024

Yeah, I have python-lsp-server installed via 3.12, but I use 3.10 for all of my projects. However, even when I install and use python-lsp-server under the same 3.10 interpreter I use for my projects (or use the 3.12 interpreter that has the original LS install as my default interpreter), I get the results described above.

In the 3.12 case, I installed pylsp using Nix home-manager. In the 3.10 case, I installed it using pip.

HungryJoe pushed a commit to HungryJoe/helix_config that referenced this issue Nov 7, 2024
Until the following issue is fixed, it's useless for completion,
so basedpyright is taking over that plus all the other stuff
it did already.
python-lsp/python-lsp-server#503
@HungryJoe
Copy link

I've discovered something: If I just enable rope_autoimport's completion, it'll work, it just takes around 15s after typing a single character before a completion list shows up. When other completion provider(s) are enabled, I'm seeing in the logs that python-lsp-server tries to provide completions but doesn't get all the way to sending a JSON RPC message for some reason. Here's a sample log where I just type a single character and wait a while, with rope_autoimport and rope_completion completion providers enabled: pylsp.log

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

6 participants