Skip to content

Commit 3c6b3bd

Browse files
committed
Improve completion descriptions
1 parent 3954f14 commit 3c6b3bd

4 files changed

Lines changed: 44 additions & 6 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
# Python Autocomplete Package
22

3-
CPython variables, methods, functions and modules autocompletions in Atom. Install
3+
Python variables, methods, functions and modules autocompletions in Atom. Install
44
[autocomplete-plus](https://github.com/atom-community/autocomplete-plus) before
55
installing this package.
66

77
This is powered by [Jedi](https://github.com/davidhalter/jedi).
88

99
![Demo](https://cloud.githubusercontent.com/assets/193864/7388957/36019954-ee9c-11e4-8373-7bf551ed613f.gif)
10+
11+
12+
# Features
13+
14+
* Highlights UPPERCASE_VARIABLES as constants according to PEP8.
15+
* Highlights builtin functions and variables with special style.
16+
* Prints first 50 characters of statement value while completing variables.
17+
* Additional caching so the same request will not be handled twice.
18+
19+
20+
Inspired by [autocomplete-plus-python-jedi](https://github.com/tinloaf/autocomplete-plus-python-jedi).

lib/completion.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class JediCompletion(object):
9-
types = {
9+
basic_types = {
1010
'module': 'import',
1111
'class': 'class',
1212
'instance': 'variable',
@@ -20,6 +20,33 @@ def __init__(self):
2020
if path not in sys.path:
2121
sys.path.insert(0, path)
2222

23+
def _get_completion_type(self, completion):
24+
is_built_in = completion.in_builtin_module
25+
if completion.type not in ['import', 'keyword'] and is_built_in():
26+
return 'builtin'
27+
if completion.type in ['statement'] and completion.name.isupper():
28+
return 'constant'
29+
if completion.type in self.basic_types:
30+
return self.basic_types.get(completion.type)
31+
32+
def _description(self, completion):
33+
"""Provide a description of the completion object."""
34+
if completion._definition is None:
35+
return ''
36+
t = completion.type
37+
if t == 'statement':
38+
desc = ''.join(
39+
c.get_code() for c in completion._definition.children
40+
if type(c).__name__ in ['InstanceElement', 'String']).replace('\n', '')
41+
elif t == 'keyword':
42+
desc = ''
43+
elif t == 'import':
44+
desc = completion._definition.get_code()
45+
else:
46+
desc = '.'.join(unicode(p) for p in completion._path())
47+
line = '' if completion.in_builtin_module else '@%s' % completion.line
48+
return ('%s: %s%s' % (t, desc, line))[:50]
49+
2350
@classmethod
2451
def _get_top_level_module(cls, path):
2552
"""Recursively walk through directories looking for top level module.
@@ -57,10 +84,10 @@ def _serialize(self, completions, identifier):
5784
'snippet': self._generate_snippet(completion),
5885
'displayText': completion.name,
5986
# 'replacementPrefix': completion.name[:completion._like_name_length],
60-
'type': self.types.get(completion.type),
87+
'type': self._get_completion_type(completion),
6188
# TODO: try to understand return value
6289
# 'leftLabel': '',
63-
'rightLabel': completion.description,
90+
'rightLabel': self._description(completion),
6491
'description': completion.docstring(),
6592
# 'descriptionMoreURL': completion.module_name
6693
})

lib/main.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports =
2020

2121
getProvider: ->
2222
return @provider if @provider?
23-
PythonProvider = require('./pythonprovider')
23+
PythonProvider = require('./python-provider')
2424
@provider = new PythonProvider()
2525
return @provider
2626

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports =
22
class PythonProvider
33
selector: '.source.python'
4-
disableForSelector: '.source.python .comment, .source.python .string'
4+
disableForSelector: '.source.python.comment, .source.python.string'
55
inclusionPriority: 1
66
excludeLowerPriority: true
77

0 commit comments

Comments
 (0)