Skip to content

Commit

Permalink
Filter builtin modules (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Mar 9, 2019
1 parent 5e785fe commit 18f3c3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pyls/plugins/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def pyls_references(document, position, exclude_declaration=False):
# Filter out if the usage is the actual declaration of the thing
usages = [d for d in usages if not d.is_definition()]

# Filter out builtin modules
usages = [d for d in usages if not d.in_builtin_module()]

return [{
'uri': uris.uri_with(document.uri, path=d.module_path) if d.module_path else document.uri,
'range': {
Expand Down
22 changes: 19 additions & 3 deletions test/plugins/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

DOC2 = """from test1 import Test1
Test1()
try:
Test1()
except UnicodeError:
pass
"""


Expand Down Expand Up @@ -59,5 +62,18 @@ def test_references(tmp_workspace): # pylint: disable=redefined-outer-name
assert doc2_import_ref['range']['end'] == {'line': 0, 'character': 23}

doc2_usage_ref = [u for u in refs if u['uri'] != DOC1_URI][1]
assert doc2_usage_ref['range']['start'] == {'line': 2, 'character': 0}
assert doc2_usage_ref['range']['end'] == {'line': 2, 'character': 5}
assert doc2_usage_ref['range']['start'] == {'line': 3, 'character': 4}
assert doc2_usage_ref['range']['end'] == {'line': 3, 'character': 9}


def test_references_builtin(tmp_workspace): # pylint: disable=redefined-outer-name
# Over 'UnicodeError':
position = {'line': 4, 'character': 7}
doc2_uri = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC2_NAME))
doc2 = Document(doc2_uri)

refs = pyls_references(doc2, position)
assert len(refs) == 1

assert refs[0]['range']['start'] == {'line': 4, 'character': 7}
assert refs[0]['range']['end'] == {'line': 4, 'character': 19}

0 comments on commit 18f3c3f

Please sign in to comment.