From ac79ceff66b692bc30ad93a60621b1dcf07db51c Mon Sep 17 00:00:00 2001 From: Jack Wickham Date: Fri, 1 Nov 2019 11:26:16 +0000 Subject: [PATCH] Don't go to definition of builtin modules (#687) --- pyls/plugins/definition.py | 12 ++++++++++-- test/plugins/test_definitions.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyls/plugins/definition.py b/pyls/plugins/definition.py index 69109afd..8ec3b1ad 100644 --- a/pyls/plugins/definition.py +++ b/pyls/plugins/definition.py @@ -20,6 +20,14 @@ def pyls_definitions(config, document, position): 'end': {'line': d.line - 1, 'character': d.column + len(d.name)}, } } - for d in definitions - if d.is_definition() and d.line is not None and d.column is not None and d.module_path is not None + for d in definitions if d.is_definition() and _not_internal_definition(d) ] + + +def _not_internal_definition(definition): + return ( + definition.line is not None and + definition.column is not None and + definition.module_path is not None and + not definition.in_builtin_module() + ) diff --git a/test/plugins/test_definitions.py b/test/plugins/test_definitions.py index 3faa7cfb..e2db9c6f 100644 --- a/test/plugins/test_definitions.py +++ b/test/plugins/test_definitions.py @@ -40,7 +40,7 @@ def test_builtin_definition(config): # No go-to def for builtins doc = Document(DOC_URI, DOC) - assert len(pyls_definitions(config, doc, cursor_pos)) == 1 + assert not pyls_definitions(config, doc, cursor_pos) def test_assignment(config):