From 7d3a76c3af0aea7e832eedf18cbaf50e69a8894b Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 30 Jan 2021 15:30:56 +0000 Subject: [PATCH 01/10] Implement completionItem/resolve --- pylsp/hookspecs.py | 5 ++++ pylsp/plugins/jedi_completion.py | 34 +++++++++++++++++++--- pylsp/plugins/rope_completion.py | 48 +++++++++++++++++++++++++------- pylsp/python_lsp.py | 10 +++++-- test/plugins/test_completion.py | 29 ++++++++++++++++++- 5 files changed, 109 insertions(+), 17 deletions(-) diff --git a/pylsp/hookspecs.py b/pylsp/hookspecs.py index ff2925ac..7a5ec5ec 100644 --- a/pylsp/hookspecs.py +++ b/pylsp/hookspecs.py @@ -29,6 +29,11 @@ def pylsp_completions(config, workspace, document, position): pass +@hookspec +def pylsp_completion_item_resolve(config, workspace, completion_item): + pass + + @hookspec def pylsp_definitions(config, workspace, document, position): pass diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py index a04d2101..239f6d77 100644 --- a/pylsp/plugins/jedi_completion.py +++ b/pylsp/plugins/jedi_completion.py @@ -33,11 +33,17 @@ # Types of parso node for errors _ERRORS = ('error_node', ) +# most recently retrieved completion items, used for resolution +_LAST_COMPLETIONS = {} + @hookimpl def pylsp_completions(config, document, position): """Get formatted completions for current code position""" + global _LAST_COMPLETIONS + settings = config.plugin_settings('jedi_completion', document_path=document.path) + resolve_eagerly = settings.get('eager', False) code_position = _utils.position_to_jedi_linecolumn(document, position) code_position["fuzzy"] = settings.get("fuzzy", False) @@ -63,14 +69,27 @@ def pylsp_completions(config, document, position): if include_class_objects: for c in completions: if c.type == 'class': - completion_dict = _format_completion(c, False) + completion_dict = _format_completion(c, False, resolve=resolve_eagerly) completion_dict['kind'] = lsp.CompletionItemKind.TypeParameter completion_dict['label'] += ' object' ready_completions.append(completion_dict) + _LAST_COMPLETIONS = { + # label is the only required property; here it is assumed to be unique + completion['label']: (completion, data) + for completion, data in zip(ready_completions, completions) + } + return ready_completions or None +@hookimpl +def pylsp_completion_item_resolve(config, completion_item): + """Resolve formatted completion for given non-resolved completion""" + completion, data = _LAST_COMPLETIONS.get(completion_item['label']) + return _resolve_completion(completion, data) + + def is_exception_class(name): """ Determine if a class name is an instance of an Exception. @@ -121,16 +140,23 @@ def use_snippets(document, position): not (expr_type in _ERRORS and 'import' in code)) -def _format_completion(d, include_params=True): +def _resolve_completion(completion, d): + completion['detail'] = _detail(d) + completion['documentation'] = _utils.format_docstring(d.docstring()) + return completion + + +def _format_completion(d, include_params=True, resolve=False): completion = { 'label': _label(d), 'kind': _TYPE_MAP.get(d.type), - 'detail': _detail(d), - 'documentation': _utils.format_docstring(d.docstring()), 'sortText': _sort_text(d), 'insertText': d.name } + if resolve: + completion = _resolve_completion(completion, d) + if d.type == 'path': path = osp.normpath(d.name) path = path.replace('\\', '\\\\') diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index c1e162a2..171da628 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -9,15 +9,32 @@ log = logging.getLogger(__name__) +# most recently retrieved completion items, used for resolution +_LAST_COMPLETIONS = {} @hookimpl def pylsp_settings(): # Default rope_completion to disabled - return {'plugins': {'rope_completion': {'enabled': False}}} + return {'plugins': {'rope_completion': {'enabled': False, 'eager': False}}} + + +def _resolve_completion(completion, data): + try: + doc = data.get_doc() + except AttributeError: + doc = "" + completion['detail'] = '{0} {1}'.format(data.scope or "", data.name) + completion['documentation'] = doc + return completion @hookimpl def pylsp_completions(config, workspace, document, position): + global _LAST_COMPLETIONS + + settings = config.plugin_settings('rope_completion', document_path=document.path) + resolve_eagerly = settings.get('eager', False) + # Rope is a bit rubbish at completing module imports, so we'll return None word = document.word_at_position({ # The -1 should really be trying to look at the previous word, but that might be quite expensive @@ -41,22 +58,33 @@ def pylsp_completions(config, workspace, document, position): definitions = sorted_proposals(definitions) new_definitions = [] for d in definitions: - try: - doc = d.get_doc() - except AttributeError: - doc = None - new_definitions.append({ + item = { 'label': d.name, 'kind': _kind(d), - 'detail': '{0} {1}'.format(d.scope or "", d.name), - 'documentation': doc or "", 'sortText': _sort_text(d) - }) + } + if resolve_eagerly: + item = _resolve_completion(item, d) + new_definitions.append(item) + + _LAST_COMPLETIONS = { + # label is the only required property; here it is assumed to be unique + completion['label']: (completion, data) + for completion, data in zip(new_definitions, definitions) + } + definitions = new_definitions return definitions or None +@hookimpl +def pyls_completion_item_resolve(config, completion_item): + """Resolve formatted completion for given non-resolved completion""" + completion, data = _LAST_COMPLETIONS.get(completion_item['label']) + return _resolve_completion(completion, data) + + def _sort_text(definition): """ Ensure builtins appear at the bottom. Description is of format : . @@ -72,7 +100,7 @@ def _sort_text(definition): def _kind(d): - """ Return the VSCode type """ + """ Return the LSP type """ MAP = { 'none': lsp.CompletionItemKind.Value, 'type': lsp.CompletionItemKind.Class, diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index 81efc353..0e96a87f 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -162,8 +162,8 @@ def capabilities(self): 'resolveProvider': False, # We may need to make this configurable }, 'completionProvider': { - 'resolveProvider': False, # We know everything ahead of time - 'triggerCharacters': ['.'] + 'resolveProvider': True, # We could know everything ahead of time, but this takes time to transfer + 'triggerCharacters': ['.'], }, 'documentFormattingProvider': True, 'documentHighlightProvider': True, @@ -250,6 +250,9 @@ def completions(self, doc_uri, position): 'items': flatten(completions) } + def completion_item_resolve(self, completion_item): + return self._hook('pyls_completion_item_resolve', completion_item=completion_item) + def definitions(self, doc_uri, position): return flatten(self._hook('pylsp_definitions', doc_uri, position=position)) @@ -296,6 +299,9 @@ def signature_help(self, doc_uri, position): def folding(self, doc_uri): return flatten(self._hook('pylsp_folding_range', doc_uri)) + def m_completion_item__resolve(self, **completionItem): + return self.completion_item_resolve(completionItem) + def m_text_document__did_close(self, textDocument=None, **_kwargs): workspace = self._match_uri_to_workspace(textDocument['uri']) workspace.rm_document(textDocument['uri']) diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index df197248..5cc7e8ca 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -12,6 +12,7 @@ from pylsp import uris, lsp from pylsp.workspace import Document from pylsp.plugins.jedi_completion import pylsp_completions as pylsp_jedi_completions +from pylsp.plugins.jedi_completion import pylsp_completion_item_resolve as pylsp_jedi_completion_item_resolve from pylsp.plugins.rope_completion import pylsp_completions as pylsp_rope_completions from pylsp._utils import JEDI_VERSION @@ -44,6 +45,10 @@ def everyone(self, a, b, c=None, d=2): print Hello().world print Hello().every + +def documented_hello(): + \"\"\"Sends a polite greeting\"\"\" + pass """ @@ -139,6 +144,26 @@ def test_jedi_completion(config, workspace): pylsp_jedi_completions(config, doc, {'line': 1, 'character': 1000}) +def test_jedi_completion_item_resolve(config, workspace): + # Over the blank line + com_position = {'line': 8, 'character': 0} + doc = Document(DOC_URI, workspace, DOC) + completions = pylsp_jedi_completions(config, doc, com_position) + + items = {c['label']: c for c in completions} + + documented_hello_item = items['documented_hello()'] + + assert 'documentation' not in documented_hello_item + assert 'detail' not in documented_hello_item + + resolved_documented_hello = pylsp_jedi_completion_item_resolve( + config, + completion_item=documented_hello_item + ) + assert 'Sends a polite greeting' in resolved_documented_hello['documentation'] + + def test_jedi_completion_with_fuzzy_enabled(config, workspace): # Over 'i' in os.path.isabs(...) config.update({'plugins': {'jedi_completion': {'fuzzy': True}}}) @@ -410,7 +435,9 @@ def test_jedi_completion_environment(workspace): # After 'import logh' with new environment completions = pylsp_jedi_completions(doc._config, doc, com_position) assert completions[0]['label'] == 'loghub' - assert 'changelog generator' in completions[0]['documentation'].lower() + + resolved = pylsp_jedi_completion_item_resolve(completions[0]['documentation']) + assert 'changelog generator' in resolved['documentation'].lower() def test_document_path_completions(tmpdir, workspace_other_root_path): From be8c2e3bc1543af82b53fec3a6c90364dd11a4d3 Mon Sep 17 00:00:00 2001 From: krassowski Date: Wed, 28 Apr 2021 21:54:39 +0100 Subject: [PATCH 02/10] Fix CI-only test for resolve --- test/plugins/test_completion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index 5cc7e8ca..e44ecef1 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -436,7 +436,7 @@ def test_jedi_completion_environment(workspace): completions = pylsp_jedi_completions(doc._config, doc, com_position) assert completions[0]['label'] == 'loghub' - resolved = pylsp_jedi_completion_item_resolve(completions[0]['documentation']) + resolved = pylsp_jedi_completion_item_resolve(doc._config, completions[0]) assert 'changelog generator' in resolved['documentation'].lower() From 807b3715cc87aab649120e6dd9d488f330300509 Mon Sep 17 00:00:00 2001 From: krassowski Date: Wed, 28 Apr 2021 21:58:21 +0100 Subject: [PATCH 03/10] Address pylint notes, fix names --- pylsp/plugins/jedi_completion.py | 4 +++- pylsp/plugins/rope_completion.py | 5 ++++- test/plugins/test_completion.py | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py index 239f6d77..61fd4a10 100644 --- a/pylsp/plugins/jedi_completion.py +++ b/pylsp/plugins/jedi_completion.py @@ -40,6 +40,8 @@ @hookimpl def pylsp_completions(config, document, position): """Get formatted completions for current code position""" + # pylint: disable=too-many-locals + # pylint: disable=global-statement global _LAST_COMPLETIONS settings = config.plugin_settings('jedi_completion', document_path=document.path) @@ -84,7 +86,7 @@ def pylsp_completions(config, document, position): @hookimpl -def pylsp_completion_item_resolve(config, completion_item): +def pylsp_completion_item_resolve(completion_item): """Resolve formatted completion for given non-resolved completion""" completion, data = _LAST_COMPLETIONS.get(completion_item['label']) return _resolve_completion(completion, data) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index 171da628..76766028 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -12,6 +12,7 @@ # most recently retrieved completion items, used for resolution _LAST_COMPLETIONS = {} + @hookimpl def pylsp_settings(): # Default rope_completion to disabled @@ -30,6 +31,8 @@ def _resolve_completion(completion, data): @hookimpl def pylsp_completions(config, workspace, document, position): + # pylint: disable=too-many-locals + # pylint: disable=global-statement global _LAST_COMPLETIONS settings = config.plugin_settings('rope_completion', document_path=document.path) @@ -79,7 +82,7 @@ def pylsp_completions(config, workspace, document, position): @hookimpl -def pyls_completion_item_resolve(config, completion_item): +def pylsp_completion_item_resolve(completion_item): """Resolve formatted completion for given non-resolved completion""" completion, data = _LAST_COMPLETIONS.get(completion_item['label']) return _resolve_completion(completion, data) diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index e44ecef1..215e0544 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -158,7 +158,6 @@ def test_jedi_completion_item_resolve(config, workspace): assert 'detail' not in documented_hello_item resolved_documented_hello = pylsp_jedi_completion_item_resolve( - config, completion_item=documented_hello_item ) assert 'Sends a polite greeting' in resolved_documented_hello['documentation'] @@ -436,7 +435,7 @@ def test_jedi_completion_environment(workspace): completions = pylsp_jedi_completions(doc._config, doc, com_position) assert completions[0]['label'] == 'loghub' - resolved = pylsp_jedi_completion_item_resolve(doc._config, completions[0]) + resolved = pylsp_jedi_completion_item_resolve(completions[0]) assert 'changelog generator' in resolved['documentation'].lower() From f11c943f04b5f31b5b8ec09dc378b3d979367b79 Mon Sep 17 00:00:00 2001 From: krassowski Date: Wed, 28 Apr 2021 22:00:57 +0100 Subject: [PATCH 04/10] Only sent the first result for completionItem/resolve --- pylsp/hookspecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylsp/hookspecs.py b/pylsp/hookspecs.py index 7a5ec5ec..8cc2fa3a 100644 --- a/pylsp/hookspecs.py +++ b/pylsp/hookspecs.py @@ -29,7 +29,7 @@ def pylsp_completions(config, workspace, document, position): pass -@hookspec +@hookspec(firstresult=True) def pylsp_completion_item_resolve(config, workspace, completion_item): pass From 24911a801904267936a21cd80e0d922330d89da5 Mon Sep 17 00:00:00 2001 From: krassowski Date: Wed, 28 Apr 2021 22:20:05 +0100 Subject: [PATCH 05/10] Fix indentation --- pylsp/hookspecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylsp/hookspecs.py b/pylsp/hookspecs.py index 8cc2fa3a..06311299 100644 --- a/pylsp/hookspecs.py +++ b/pylsp/hookspecs.py @@ -31,7 +31,7 @@ def pylsp_completions(config, workspace, document, position): @hookspec(firstresult=True) def pylsp_completion_item_resolve(config, workspace, completion_item): - pass + pass @hookspec From c51f5b651e8d0f3b85f9b0e266ef2d07cdd48b9f Mon Sep 17 00:00:00 2001 From: krassowski Date: Fri, 9 Jul 2021 22:55:00 +0100 Subject: [PATCH 06/10] Finalise pyls -> pylsp transition --- pylsp/python_lsp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index 0e96a87f..972e4a65 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -251,7 +251,7 @@ def completions(self, doc_uri, position): } def completion_item_resolve(self, completion_item): - return self._hook('pyls_completion_item_resolve', completion_item=completion_item) + return self._hook('pylsp_completion_item_resolve', completion_item=completion_item) def definitions(self, doc_uri, position): return flatten(self._hook('pylsp_definitions', doc_uri, position=position)) From b4a9565d152658ed7280de1915cb77843ac5b12f Mon Sep 17 00:00:00 2001 From: krassowski Date: Fri, 9 Jul 2021 22:57:55 +0100 Subject: [PATCH 07/10] Document the `eager` option --- CONFIGURATION.md | 1 + pylsp/config/schema.json | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 75439f51..46c1e2e6 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -11,6 +11,7 @@ This server can be configured using `workspace/didChangeConfiguration` method. E | `pylsp.plugins.jedi_completion.include_params` | `boolean` | Auto-completes methods and classes with tabstops for each parameter. | `true` | | `pylsp.plugins.jedi_completion.include_class_objects` | `boolean` | Adds class objects as a separate completion item. | `true` | | `pylsp.plugins.jedi_completion.fuzzy` | `boolean` | Enable fuzzy when requesting autocomplete. | `false` | +| `pylsp.plugins.jedi_completion.eager` | `boolean` | Resolve documentation and detail eagerly. | `false` | | `pylsp.plugins.jedi_definition.enabled` | `boolean` | Enable or disable the plugin. | `true` | | `pylsp.plugins.jedi_definition.follow_imports` | `boolean` | The goto call will follow imports. | `true` | | `pylsp.plugins.jedi_definition.follow_builtin_imports` | `boolean` | If follow_imports is True will decide if it follow builtin imports. | `true` | diff --git a/pylsp/config/schema.json b/pylsp/config/schema.json index 6da8e167..05777434 100644 --- a/pylsp/config/schema.json +++ b/pylsp/config/schema.json @@ -49,6 +49,11 @@ "default": false, "description": "Enable fuzzy when requesting autocomplete." }, + "pylsp.plugins.jedi_completion.eager": { + "type": "boolean", + "default": false, + "description": "Resolve documentation and detail eagerly." + }, "pylsp.plugins.jedi_definition.enabled": { "type": "boolean", "default": true, From 7c1ebf14b68b244292511e31980ded7bf30620f2 Mon Sep 17 00:00:00 2001 From: krassowski Date: Fri, 9 Jul 2021 23:14:40 +0100 Subject: [PATCH 08/10] Add a TODO note --- pylsp/plugins/jedi_completion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py index 61fd4a10..97b9defb 100644 --- a/pylsp/plugins/jedi_completion.py +++ b/pylsp/plugins/jedi_completion.py @@ -68,6 +68,7 @@ def pylsp_completions(config, document, position): for c in completions ] + # TODO split up once other improvements are merged if include_class_objects: for c in completions: if c.type == 'class': From 79fc79fe004f98419ec09f0f07b7d61e391065a7 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 10 Jul 2021 16:32:54 +0100 Subject: [PATCH 09/10] Use document-specific cache proposed in the review The document identifier is stored in the completion item data. --- pylsp/hookspecs.py | 2 +- pylsp/plugins/jedi_completion.py | 19 ++++++++++--------- pylsp/plugins/rope_completion.py | 12 ++++-------- pylsp/python_lsp.py | 3 ++- pylsp/workspace.py | 1 + test/plugins/test_completion.py | 5 +++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pylsp/hookspecs.py b/pylsp/hookspecs.py index 06311299..736cf931 100644 --- a/pylsp/hookspecs.py +++ b/pylsp/hookspecs.py @@ -30,7 +30,7 @@ def pylsp_completions(config, workspace, document, position): @hookspec(firstresult=True) -def pylsp_completion_item_resolve(config, workspace, completion_item): +def pylsp_completion_item_resolve(config, workspace, document, completion_item): pass diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py index 97b9defb..921c663a 100644 --- a/pylsp/plugins/jedi_completion.py +++ b/pylsp/plugins/jedi_completion.py @@ -33,22 +33,17 @@ # Types of parso node for errors _ERRORS = ('error_node', ) -# most recently retrieved completion items, used for resolution -_LAST_COMPLETIONS = {} - @hookimpl def pylsp_completions(config, document, position): """Get formatted completions for current code position""" # pylint: disable=too-many-locals - # pylint: disable=global-statement - global _LAST_COMPLETIONS settings = config.plugin_settings('jedi_completion', document_path=document.path) resolve_eagerly = settings.get('eager', False) code_position = _utils.position_to_jedi_linecolumn(document, position) - code_position["fuzzy"] = settings.get("fuzzy", False) + code_position['fuzzy'] = settings.get('fuzzy', False) completions = document.jedi_script(use_document_path=True).complete(**code_position) if not completions: @@ -77,7 +72,13 @@ def pylsp_completions(config, document, position): completion_dict['label'] += ' object' ready_completions.append(completion_dict) - _LAST_COMPLETIONS = { + for completion_dict in ready_completions: + completion_dict['data'] = { + 'doc_uri': document.uri + } + + # most recently retrieved completion items, used for resolution + document.shared_data['LAST_JEDI_COMPLETIONS'] = { # label is the only required property; here it is assumed to be unique completion['label']: (completion, data) for completion, data in zip(ready_completions, completions) @@ -87,9 +88,9 @@ def pylsp_completions(config, document, position): @hookimpl -def pylsp_completion_item_resolve(completion_item): +def pylsp_completion_item_resolve(completion_item, document): """Resolve formatted completion for given non-resolved completion""" - completion, data = _LAST_COMPLETIONS.get(completion_item['label']) + completion, data = document.shared_data['LAST_JEDI_COMPLETIONS'].get(completion_item['label']) return _resolve_completion(completion, data) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index 76766028..49719be9 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -9,9 +9,6 @@ log = logging.getLogger(__name__) -# most recently retrieved completion items, used for resolution -_LAST_COMPLETIONS = {} - @hookimpl def pylsp_settings(): @@ -32,8 +29,6 @@ def _resolve_completion(completion, data): @hookimpl def pylsp_completions(config, workspace, document, position): # pylint: disable=too-many-locals - # pylint: disable=global-statement - global _LAST_COMPLETIONS settings = config.plugin_settings('rope_completion', document_path=document.path) resolve_eagerly = settings.get('eager', False) @@ -70,7 +65,8 @@ def pylsp_completions(config, workspace, document, position): item = _resolve_completion(item, d) new_definitions.append(item) - _LAST_COMPLETIONS = { + # most recently retrieved completion items, used for resolution + document.shared_data['LAST_ROPE_COMPLETIONS'] = { # label is the only required property; here it is assumed to be unique completion['label']: (completion, data) for completion, data in zip(new_definitions, definitions) @@ -82,9 +78,9 @@ def pylsp_completions(config, workspace, document, position): @hookimpl -def pylsp_completion_item_resolve(completion_item): +def pylsp_completion_item_resolve(completion_item, document): """Resolve formatted completion for given non-resolved completion""" - completion, data = _LAST_COMPLETIONS.get(completion_item['label']) + completion, data = document.shared_data['LAST_ROPE_COMPLETIONS'].get(completion_item['label']) return _resolve_completion(completion, data) diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index 972e4a65..50c6693b 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -251,7 +251,8 @@ def completions(self, doc_uri, position): } def completion_item_resolve(self, completion_item): - return self._hook('pylsp_completion_item_resolve', completion_item=completion_item) + doc_uri = completion_item.get('data', {}).get('doc_uri', None) + return self._hook('pylsp_completion_item_resolve', doc_uri, completion_item=completion_item) def definitions(self, doc_uri, position): return flatten(self._hook('pylsp_definitions', doc_uri, position=position)) diff --git a/pylsp/workspace.py b/pylsp/workspace.py index 20720c9b..a063cabe 100644 --- a/pylsp/workspace.py +++ b/pylsp/workspace.py @@ -138,6 +138,7 @@ def __init__(self, uri, workspace, source=None, version=None, local=True, extra_ self.path = uris.to_fs_path(uri) self.dot_path = _utils.path_to_dot_name(self.path) self.filename = os.path.basename(self.path) + self.shared_data = {} self._config = workspace._config self._workspace = workspace diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index 215e0544..be138e81 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -158,7 +158,8 @@ def test_jedi_completion_item_resolve(config, workspace): assert 'detail' not in documented_hello_item resolved_documented_hello = pylsp_jedi_completion_item_resolve( - completion_item=documented_hello_item + completion_item=documented_hello_item, + document=doc ) assert 'Sends a polite greeting' in resolved_documented_hello['documentation'] @@ -435,7 +436,7 @@ def test_jedi_completion_environment(workspace): completions = pylsp_jedi_completions(doc._config, doc, com_position) assert completions[0]['label'] == 'loghub' - resolved = pylsp_jedi_completion_item_resolve(completions[0]) + resolved = pylsp_jedi_completion_item_resolve(completions[0], doc) assert 'changelog generator' in resolved['documentation'].lower() From ed4cd412375bd79a9db9a388854e9775f4a47639 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 10 Jul 2021 16:46:36 +0100 Subject: [PATCH 10/10] Add data.doc_uri for rope too --- pylsp/plugins/rope_completion.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index 49719be9..b73d8412 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -59,7 +59,10 @@ def pylsp_completions(config, workspace, document, position): item = { 'label': d.name, 'kind': _kind(d), - 'sortText': _sort_text(d) + 'sortText': _sort_text(d), + 'data': { + 'doc_uri': document.uri + } } if resolve_eagerly: item = _resolve_completion(item, d)