Go to definition in the Editor stopped working after the introspection services migration to use the LSP
See original GitHub issueProblem Description
Go to definition (Ctrl-G) in the Editor stopped working after PR #4751 was merged.
A minor comment first: the lsp_client_python.log
file is taking forever to build and if something introspection related is done while the file is being built, everything seems to break (help, go to definition and code style warnings).
I think the reason that go to definition has stopped working is that there is an error in the path of the file that the language server is returning to Spyder in handle_go_to_definition. An extra /
is added at the beginning and the disk name is not capitalized.
For example, let’s say that I Ctrl-G GoToLineDialog on line 1682 of the file codeeditor.py
. This file is located on my computer at C:\Users\User\spyder\spyder\widgets\sourcecode\codeeditor.py
.
The position['params']
that is returned to handle_go_to_definition is:
{'uri': 'file:///c:/Users/User/spyder/spyder/widgets/sourcecode/codeeditor.py',
'range': {'start': {'line': 102, 'character': 6}, 'end': {'line': 102, 'character': 20}},
'file': '/c:/Users/User/spyder/spyder/widgets/sourcecode/codeeditor.py'
}
So as you can see, the value stored for the file is '/c:/Users/User/spyder/spyder/widgets/sourcecode/codeeditor.py'
instead of C:\Users\User\spyder\spyder\widgets\sourcecode\codeeditor.py
, the value that is stored in CodeEditor.filename
.
If I replace handle_go_to_definition by:
@handles(LSPRequestTypes.DOCUMENT_DEFINITION)
def handle_go_to_definition(self, position):
position = position['params']
if position is not None:
def_range = position['range']
start = def_range['start']
position_file = osp.normpath(position['file'][1:])
if osp.normpath(self.filename) == position_file:
self.go_to_line(start['line'] + 1, start['character'],
None, word=None)
else:
self.go_to_definition.emit(position_file, start['line'] + 1,
start['character'])
to remove the extra \
and normalize the paths before comparing them, then the go to definition feature is working again as expected.
Versions
- Spyder version: Spyder 4.0.0.dev0
- Python version: Python 3.6.5 64bits
- Qt version: Qt 5.9.3
- PyQt version: PyQt5 5.9.2
- Operating System name/version: Windows
Dependencies
pyflakes >=0.6.0 : 1.6.0 (OK)
pycodestyle >=2.3 : 2.3.1 (OK)
pygments >=2.0 : 2.2.0 (OK)
sphinx >=0.6.6 : 1.7.1 (OK)
rope >=0.9.4 : 0.10.7 (OK)
jedi >=0.11.0 : 0.12.1 (OK)
nbconvert >=4.0 : 5.3.1 (OK)
pandas >=0.13.1 : 0.22.0 (OK)
numpy >=1.7 : 1.13.0 (OK)
sympy >=0.7.3 : 1.1.1 (OK)
cython >=0.21 : 0.27.3 (OK)
qtconsole >=4.2.0 : 4.4.0.dev (OK)
IPython >=4.0 : 6.2.1 (OK)
matplotlib >=2.0.0: 2.2.0 (OK)
pylint >=0.25 : 1.8.3 (OK)
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
@jnsebgosselin I think this is a Windows-only issue, thanks for pointing out!
Ok good. In that case, this is a deal.