coc-python icon indicating copy to clipboard operation
coc-python copied to clipboard

Jedi column parameter is always out of range

Open sangaline opened this issue 5 years ago • 6 comments

I started getting this error after upgrading the coc-python plugin today (which also required upgrading to jedi 0.17.0). The column parameter is always one above the length of the line, resulting in this error:

[coc.nvim] Jedi error: Traceback (most recent call last):
  File "completion.py", line 624, in watch
    response = self._process_request(rq)
  File "completion.py", line 599, in _process_request
    script, request['id'])
  File "completion.py", line 287, in _serialize_arguments
    return json.dumps({"id": identifier, "results": self._get_call_signatures_with_args(script)})
  File "completion.py", line 144, in _get_call_signatures_with_args
    call_signatures = script.call_signatures()
  File "/home/sangaline/workspaces/test/.venv/lib/python3.6/site-packages/jedi/api/__init__.py", line 379, in call_signatures
    return self.get_signatures(*self._pos)
  File "/home/sangaline/workspaces/test/.venv/lib/python3.6/site-packages/jedi/api/helpers.py", line 455, in wrapper
    column, line_len, line, line_string))
ValueError: `column` parameter (20) is not in a valid range (0-19) for line 658 ('# this is a comment\n').

I've attempted downgrading to combinations of the last few coc-python and jedi versions, but I still get the same error every time I enter a character. This might indicate that it's somehow related to an interaction with another plugin that upgraded at the same time, but the error itself is coming from the coc-python extension.

sangaline avatar May 07 '20 22:05 sangaline

A temporary workaround for anybody getting bitten by this is to change

        column = line_len if column is None else column

in jedi/api/helpers.validate_line_column() to this:

        column = min(line_len, line_len if column is None else column)

There's a related issue in the jedi repo, and the maintainer seems very against making this change in jedi.

sangaline avatar May 07 '20 22:05 sangaline

Can't reproduce.

chemzqm avatar May 08 '20 04:05 chemzqm

Is there any specific information that I could provide that would be helpful?

The Python version is 3.6.7 and the neovim version information is:

NVIM v0.4.3
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.3/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

Even if this isn't easy to reproduce, would it be possible to cap the column index at the current line length in coc-python? According to the Jedi issue, the LSP specifies that column positions greater than the length of a line must be treated as if the line length was given instead, but Jedi itself does not allow this.

sangaline avatar May 08 '20 16:05 sangaline

I'm experiencing the same. Tricky to reproduce because it's sporadic, happening roughly 20% of the time when adding certain characters at the end of a line, specifically ,<space> (note the space) ... just typing , repeatedly does not trigger.

Throws:

[coc.nvim] Jedi error: Traceback (most recent call last):
  File "completion.py", line 670, in watch
    response = self._process_request(rq)
  File "completion.py", line 640, in _process_request
    return self._serialize_arguments(script, line, column, request["id"])
  File "completion.py", line 309, in _serialize_arguments
    "results": self._get_call_signatures_with_args(script, line, column),
  File "completion.py", line 148, in _get_call_signatures_with_args
    call_signatures = script.get_signatures(line, column)
  File "/Users/britt/opt/anaconda3/lib/python3.7/site-packages/jedi/api/helpers.py", line 464, in wrapper
    column, line_len, line, line_string))
ValueError: `column` parameter (103) is not in a valid range (0-102) for line 65

bs avatar May 23 '20 18:05 bs

It seems that it also happens when file is not saved. Steps to reproduce:

  1. open a new python file
  2. as the first line type "add".capitalize (DO NOT SAVE)
  3. put the cursor at the middle of capitalize word
  4. try to jump to definition See the error:
[coc.nvim] Jedi error: Traceback (most recent call last):                                                                                                                                                              
  File "completion.py", line 670, in watch
    response = self._process_request(rq)
  File "completion.py", line 603, in _process_request
    script = jedi.Script(
  File "/home/naquad/.local/lib/python3.8/site-packages/jedi/api/__init__.py", line 172, in __init__
    with open(path, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/naquad/projects/tests/jediissuecheck.py

Another way:

  1. create an empty python file
  2. open that file and add the same line "asd".capitalize (DO NOT SAVE)
  3. put the cursor in the middle of capitalize word
  4. hit jump to definition See the error:
[coc.nvim] Jedi error: Traceback (most recent call last):                                                                                                                                                               
  File "completion.py", line 670, in watch
    response = self._process_request(rq)
  File "completion.py", line 612, in _process_request
    script.goto(line, column, follow_imports=True), request["id"]
  File "/home/naquad/.local/lib/python3.8/site-packages/jedi/api/helpers.py", line 462, in wrapper
    raise ValueError('`column` parameter (%d) is not in a valid range '
ValueError: `column` parameter (16) is not in a valid range (0-0) for line 1 ('').

As a temporary fix, I've updated my mapping to save the file before jumping to the definition:

nmap <buffer> gd :w<CR><Plug>(coc-definition)

naquad avatar Jun 18 '20 10:06 naquad

@chemzqm Did you have any luck with reproducing given @naquad's instructions?

Even if you can't reproduce it, would it be possible to cap the column at the length of the line? The LSP allows for the column to be above the line length, but this explicitly isn't supported by Jedi and it's resulting in these errors for myself and others.

sangaline avatar Aug 19 '20 14:08 sangaline