Skip to content

Commit e436ff0

Browse files
lgeigerccordoba12
authored andcommitted
Remove unnecessary loops in definition, hover and references (#525)
1 parent 981aafb commit e436ff0

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

pyls/plugins/definition.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ def pyls_definitions(config, document, position):
1212
follow_imports=settings.get('follow_imports', True),
1313
follow_builtin_imports=settings.get('follow_builtin_imports', True))
1414

15-
definitions = [
16-
d for d in definitions
15+
return [
16+
{
17+
'uri': uris.uri_with(document.uri, path=d.module_path),
18+
'range': {
19+
'start': {'line': d.line - 1, 'character': d.column},
20+
'end': {'line': d.line - 1, 'character': d.column + len(d.name)},
21+
}
22+
}
23+
for d in definitions
1724
if d.is_definition() and d.line is not None and d.column is not None and d.module_path is not None
1825
]
19-
20-
return [{
21-
'uri': uris.uri_with(document.uri, path=d.module_path),
22-
'range': {
23-
'start': {'line': d.line - 1, 'character': d.column},
24-
'end': {'line': d.line - 1, 'character': d.column + len(d.name)}
25-
}
26-
} for d in definitions]

pyls/plugins/hover.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ def pyls_hover(document, position):
1111
word = document.word_at_position(position)
1212

1313
# Find an exact match for a completion
14-
definitions = [d for d in definitions if d.name == word]
14+
for d in definitions:
15+
if d.name == word:
16+
return {'contents': _utils.format_docstring(d.docstring()) or ''}
1517

16-
if not definitions:
17-
# :(
18-
return {'contents': ''}
19-
20-
return {'contents': _utils.format_docstring(definitions[0].docstring()) or ""}
18+
return {'contents': ''}

pyls/plugins/references.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ def pyls_references(document, position, exclude_declaration=False):
1515
usages = [d for d in usages if not d.is_definition()]
1616

1717
# Filter out builtin modules
18-
usages = [d for d in usages if not d.in_builtin_module()]
19-
2018
return [{
2119
'uri': uris.uri_with(document.uri, path=d.module_path) if d.module_path else document.uri,
2220
'range': {
2321
'start': {'line': d.line - 1, 'character': d.column},
2422
'end': {'line': d.line - 1, 'character': d.column + len(d.name)}
2523
}
26-
} for d in usages]
24+
} for d in usages if not d.in_builtin_module()]

0 commit comments

Comments
 (0)