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

Completion requests with column positions greater than the line length don't work (LSP implementation issue) #193

Closed
w0rp opened this issue Nov 21, 2017 · 5 comments

Comments

@w0rp
Copy link

w0rp commented Nov 21, 2017

The LSP protocol document says that character values for the position, used for methods like textDocument/completion should accept values greater than the length of a line. https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#position

* If the character value is greater than the line length it defaults back to the
* line length.

However, validation in jedi causes an exception to be thrown.

558.368137 on 1: Dropping message '2017-11-21 17:22:37,470 UTC - ERROR - jsonrpc.manager - API Exception: {'type': 'ValueError', 'args': ('`column` parameter is not in a valid range.',), 'message': '`column` parameter is not in a valid range.'}
Traceback (most recent call last):
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/jsonrpc/manager.py", line 112, in _get_responses
    result = method(*request.args, **request.kwargs)
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/language_server.py", line 66, in wrapped
    return func(*args, **kwargs)
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/python_ls.py", line 138, in m_text_document__completion
    return self.completions(textDocument['uri'], position)
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/python_ls.py", line 68, in completions
    position=position
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/_utils.py", line 52, in race_hooks
    for impl, result in pool.imap_unordered(_apply, impls, chunksize=1):
  File "/usr/lib/python3.6/multiprocessing/pool.py", line 735, in next
    raise value
  File "/usr/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/_utils.py", line 47, in _apply
    return impl, impl.function(**kwargs)
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/plugins/jedi_completion.py", line 12, in pyls_completions
    definitions = document.jedi_script(position).completions()
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/pyls/workspace.py", line 265, in jedi_script
    return jedi.Script(**kwargs)
  File "/home/w0rp/Downloads/python-ls-project/ve/lib/python3.6/site-packages/jedi/api/__init__.py", line 102, in __init__
    raise ValueError('`column` parameter is not in a valid range.')
ValueError: `column` parameter is not in a valid range.

The ideal way to fix this would be to remove the validation in jedi, and make it use column = min(column, line_len) instead.

@w0rp
Copy link
Author

w0rp commented Nov 22, 2017

The jedi maintainer refuses to fix this, so this issue will have to be handled here.

@gatesn
Copy link
Contributor

gatesn commented Nov 23, 2017 via email

@w0rp
Copy link
Author

w0rp commented Nov 23, 2017

Okay.

@bbenne10
Copy link

bbenne10 commented Dec 6, 2017

I have forked to solve this issue with a PR, but I'm unsure how I might be able to get the current line's length from within PythonLanguageServer.completions. It looks easy enough to add a bare try/except in here, but given @w0rp's original comment regarding the intended behavior, this doesn't feel right. Is there a way to do this? Or is this just more difficult that I initially believed?

@gatesn
Copy link
Contributor

gatesn commented Dec 6, 2017

I think you want to find the line under the position using the Document class

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

3 participants