Open withsmilo opened 3 years ago
I'm afraid that I cannot help with this one as the logic for target detection is implemented in jedi
/python-language-server
. The relevant lines in pyls are:
and
it seems that jedi_script()
has an argument that might help in your case: use_document_path
; if it was turned to True
it would include the test_lsp/
directory in Python PATH
thus the test_func.py
file would be checked for definitions. However, currently it is not set when jedi_script()
is being called to get go-to-definition definitions so the default False
is kept. You may be able to convince pyls maintainers to make it tuneable via a setting if you are willing to make a PR (this should be quite straightforward - see the follow_imports
setting for an example).
@krassowski I solved my problem thanks to your kind answer. This is my workaround. I would like to hear your opinion if there is a better way.
def pyls_definitions(config, document, position):
...
definitions = document.jedi_script(use_document_path=True).goto(
follow_imports=settings.get('follow_imports', True),
follow_builtin_imports=settings.get('follow_builtin_imports', True),
**code_position)
...
def jedi_script(self, position=None, use_document_path=False):
...
# Extend sys_path with document's path if requested
if use_document_path:
sys_path += [os.path.normpath(os.path.dirname(self.path.replace(".virtual_documents", "")))]
...
Thank you, great to hear it helped! This seems like an interesting solution. If there is a need to strip away to the .virtual_documents
prefix our extension should handle this somewhere. I will look into it next week (time permitting).
@krassowski Really thanks!
@krassowski May I close this issue?
Let's keep it open for reference.
Description
The 'Jump to definition' doesn't work properly inside the folder.
Reproduce
test_lsp
and go into it.test_func.py
.Untitled.ipynb
.bark
definition, it failed with aNo jump targets found
error message.Expected behavior
It should be jumped to
test_func.py
.Context
Required: installed server extensions
Required: installed lab extensions
Troubleshoot Output
Command Line Output
Browser Output (recommended for all interface issues)