-
Notifications
You must be signed in to change notification settings - Fork 0
Remove deprecated calls for Jedi >= 0.16.0 #1
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
Changes from all commits
0591ade
1967c4f
cb51b09
7ca854b
b1e08e1
9e8d7fd
16a526b
551990f
afafa62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,16 +51,18 @@ | |
| @hookimpl | ||
| def pyls_completions(config, document, position): | ||
| try: | ||
| definitions = document.jedi_script(position).completions() | ||
| code_position = _utils.position_to_jedi_linecolumn(document, position) | ||
| completions = document.jedi_script().complete(**code_position) | ||
| except AttributeError as e: | ||
| if 'CompiledObject' in str(e): | ||
| # Needed to handle missing CompiledObject attribute | ||
| # 'sub_modules_dict' | ||
| definitions = None | ||
| # TODO: probably not needed for new Complete objects | ||
| completions = None | ||
| else: | ||
| raise e | ||
|
|
||
| if not definitions: | ||
| if not completions: | ||
| return None | ||
|
|
||
| completion_capabilities = config.capabilities.get('textDocument', {}).get('completion', {}) | ||
|
|
@@ -69,7 +71,7 @@ def pyls_completions(config, document, position): | |
| settings = config.plugin_settings('jedi_completion', document_path=document.path) | ||
| should_include_params = settings.get('include_params') | ||
| include_params = snippet_support and should_include_params and use_snippets(document, position) | ||
| return [_format_completion(d, include_params) for d in definitions] or None | ||
| return [_format_completion(c, include_params) for c in completions] or None | ||
|
|
||
|
|
||
| def is_exception_class(name): | ||
|
|
@@ -138,9 +140,9 @@ def _format_completion(d, include_params=True): | |
| path = path.replace('/', '\\/') | ||
| completion['insertText'] = path | ||
|
|
||
| if (include_params and hasattr(d, 'params') and d.params and | ||
| not is_exception_class(d.name)): | ||
| positional_args = [param for param in d.params | ||
| sig = d.get_signatures() | ||
| if (include_params and sig and not is_exception_class(d.name)): | ||
| positional_args = [param for param in sig[0].params | ||
| if '=' not in param.description and | ||
| param.name not in {'/', '*'}] | ||
|
|
||
|
|
@@ -163,8 +165,9 @@ def _format_completion(d, include_params=True): | |
|
|
||
|
|
||
| def _label(definition): | ||
| if definition.type in ('function', 'method') and hasattr(definition, 'params'): | ||
| params = ', '.join([param.name for param in definition.params]) | ||
| sig = definition.get_signatures() | ||
| if definition.type in ('function', 'method') and sig: | ||
| params = ', '.join([param.name for param in sig[0].params]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, why
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
| return '{}({})'.format(definition.name, params) | ||
|
|
||
| return definition.name | ||
|
|
@@ -173,7 +176,7 @@ def _label(definition): | |
| def _detail(definition): | ||
| try: | ||
| return definition.parent().full_name or '' | ||
| except AttributeError: | ||
| except (AttributeError, TypeError): | ||
| return definition.full_name or '' | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,16 +213,9 @@ def word_at_position(self, position): | |
| return m_start[0] + m_end[-1] | ||
|
|
||
| def jedi_names(self, all_scopes=False, definitions=True, references=False): | ||
| environment_path = None | ||
| if self._config: | ||
| jedi_settings = self._config.plugin_settings('jedi', document_path=self.path) | ||
| environment_path = jedi_settings.get('environment') | ||
| environment = self.get_enviroment(environment_path) if environment_path else None | ||
|
|
||
| return jedi.api.names( | ||
| source=self.source, path=self.path, all_scopes=all_scopes, | ||
| definitions=definitions, references=references, environment=environment, | ||
| ) | ||
| script = self.jedi_script() | ||
| return script.get_names(all_scopes=all_scopes, definitions=definitions, | ||
| references=references) | ||
|
Comment on lines
+216
to
+218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you ditch
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
|
|
||
| def jedi_script(self, position=None): | ||
| extra_paths = [] | ||
|
|
@@ -237,15 +230,17 @@ def jedi_script(self, position=None): | |
| environment = self.get_enviroment(environment_path) if environment_path else None | ||
|
|
||
| kwargs = { | ||
| 'source': self.source, | ||
| # 'source' is deprecated but 'code' was only introduced in 0.17.0 | ||
| 'source' if jedi.__version__ < "0.17.0" else 'code': self.source, | ||
| 'path': self.path, | ||
| 'sys_path': sys_path, | ||
| 'environment': environment, | ||
| 'project': jedi.api.Project(os.path.dirname(self.path), | ||
| sys_path=sys_path), | ||
| } | ||
|
|
||
| if position: | ||
| kwargs['line'] = position['line'] + 1 | ||
| kwargs['column'] = _utils.clip_column(position['character'], self.lines, position['line']) | ||
| # deprecated by Jedi to use in Script() constructor | ||
| kwargs += _utils.position_to_jedi_linecolumn(self, position) | ||
|
|
||
| return jedi.Script(**kwargs) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you taking here only the first signature? Also, could you provide an example of an object with multiple signatures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because PyLS expects only one for completion, but the newer Jedi provides a list of signatures.
https://jedi.readthedocs.io/en/latest/docs/api.html#jedi.Script.get_signatures
I am pretty sure there are cases with multiple signatures for a completion.
https://jedi.readthedocs.io/en/latest/docs/api-classes.html#jedi.api.classes.BaseName.get_signatures